diff --git a/db/changes/232601/00-client_create.sql b/db/changes/232801/00-client_create.sql similarity index 87% rename from db/changes/232601/00-client_create.sql rename to db/changes/232801/00-client_create.sql index f31a8e348..0728ba05e 100644 --- a/db/changes/232601/00-client_create.sql +++ b/db/changes/232801/00-client_create.sql @@ -76,12 +76,14 @@ BEGIN hasCoreVnl = vHasCoreVnl, isActive = TRUE; - IF (SELECT COUNT(*) - FROM mandate - WHERE clientFk = vUserFk - AND companyFk = vCompanyFk - AND mandateTypeFk = vMandateTypeFk) = 0 THEN - INSERT INTO mandate (clientFk, companyFk, mandateTypeFk) - VALUES (vUserFk, vCompanyFk, vMandateTypeFk); + INSERT INTO mandate (clientFk, companyFk, mandateTypeFk) + SELECT vUserFk, vCompanyFk, vMandateTypeFk + WHERE NOT EXISTS ( + SELECT id + FROM mandate + WHERE clientFk = vUserFk + AND companyFk = vCompanyFk + AND mandateTypeFk = vMandateTypeFk + ); END$$ DELIMITER ; diff --git a/db/changes/232601/00-client_create2.sql b/db/changes/232801/00-client_create2.sql similarity index 89% rename from db/changes/232601/00-client_create2.sql rename to db/changes/232801/00-client_create2.sql index 99e25fdc8..d3b7407ed 100644 --- a/db/changes/232601/00-client_create2.sql +++ b/db/changes/232801/00-client_create2.sql @@ -1,5 +1,3 @@ -DROP PROCEDURE IF EXISTS vn.clientCreate; - ALTER TABLE vn.clientConfig ADD defaultPayMethodFk tinyint(3) unsigned NULL; ALTER TABLE vn.clientConfig ADD defaultDueDay int unsigned NULL; ALTER TABLE vn.clientConfig ADD defaultCredit decimal(10, 2) NULL; @@ -9,10 +7,11 @@ ALTER TABLE vn.clientConfig ADD defaultMandateTypeFk smallint(5) NULL; ALTER TABLE vn.clientConfig ADD CONSTRAINT clientNewConfigPayMethod_FK FOREIGN KEY (dafaultPayMethodFk) REFERENCES vn.payMethod(id); ALTER TABLE vn.clientConfig ADD CONSTRAINT clientNewConfigMandateType_FK FOREIGN KEY (defaultMandateTypeFk) REFERENCES vn.mandateType(id); -UPDATE vn.clientConfig +INSERT IGNORE INTO vn.clientConfig SET defaultPayMethodFk = 4, defaultDueDay = 5, defaultCredit = 300.0, defaultIsTaxDataChecked = 1, defaultHasCoreVnl = 1, - defaultMandateTypeFk = 2; \ No newline at end of file + defaultMandateTypeFk = 2 + WHERE id = 1; \ No newline at end of file