Last active
September 9, 2024 20:42
-
-
Save rogeriolino/7c211fb83ea2325f4fcd45346da91401 to your computer and use it in GitHub Desktop.
Fix Novo SGA MySQL AUTO_INCREMENT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP PROCEDURE IF EXISTS update_atendimentos_auto_increment; | |
DROP PROCEDURE IF EXISTS fix_atendimentos_id; | |
DELIMITER $$ | |
CREATE PROCEDURE update_atendimentos_auto_increment() | |
BEGIN | |
SET @next_historico_id = (SELECT COALESCE(MAX(id), 0) + 1 FROM historico_atendimentos); | |
SET @next_atendimentos_id = (SELECT COALESCE(MAX(id), 0) + 1 FROM atendimentos); | |
SET @sql = CONCAT('ALTER TABLE atendimentos AUTO_INCREMENT = ', GREATEST(@next_historico_id, @next_atendimentos_id)); | |
PREPARE stmt FROM @sql; | |
EXECUTE stmt; | |
END$$ | |
CREATE PROCEDURE fix_atendimentos_id() | |
BEGIN | |
SET @last_id = (SELECT COALESCE(MAX(id), 0) FROM historico_atendimentos); | |
SET FOREIGN_KEY_CHECKS=0; | |
UPDATE atendimentos SET id = id + @last_id WHERE id < @last_id; | |
UPDATE atendimentos_codificados SET atendimento_id = atendimento_id + @last_id WHERE atendimento_id < @last_id; | |
SET FOREIGN_KEY_CHECKS=1; | |
END$$ | |
DELIMITER ; |
Dockerfile
FROM novosga/novosga:2.1
COPY start.sh /usr/local/bin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
start.sh