From 9d7184ed7bc66f4a3a2a5a3e32076446f155edab Mon Sep 17 00:00:00 2001 From: ivanm Date: Thu, 9 May 2024 12:35:26 +0200 Subject: [PATCH 1/3] refs #6965 Add Fk vehicleFk firstEditorFk --- db/versions/11040-grayMonstera/00-firstScript.sql | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 db/versions/11040-grayMonstera/00-firstScript.sql diff --git a/db/versions/11040-grayMonstera/00-firstScript.sql b/db/versions/11040-grayMonstera/00-firstScript.sql new file mode 100644 index 000000000..0f20e771b --- /dev/null +++ b/db/versions/11040-grayMonstera/00-firstScript.sql @@ -0,0 +1,13 @@ +UPDATE vn.route + SET vehicleFk = NULL + WHERE vehicleFk NOT IN (SELECT id FROM vn.vehicle); + +ALTER TABLE vn.route +ADD CONSTRAINT route_vehicleFk FOREIGN KEY (vehicleFk) REFERENCES vn.vehicle(id); + +UPDATE vn.route + SET firstEditorFk = NULL + WHERE firstEditorFk NOT IN (SELECT id FROM vn.worker); + +ALTER TABLE vn.route +ADD CONSTRAINT route_firstEditorFk FOREIGN KEY (firstEditorFk) REFERENCES vn.worker(id); From 9ed90412ded9c7cf8b0368fcf710209265d08e03 Mon Sep 17 00:00:00 2001 From: ivanm Date: Wed, 15 May 2024 13:15:27 +0200 Subject: [PATCH 2/3] refs #6965 Points to user instead of worker --- db/versions/11040-grayMonstera/00-firstScript.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/versions/11040-grayMonstera/00-firstScript.sql b/db/versions/11040-grayMonstera/00-firstScript.sql index 0f20e771b..8fb0e85c3 100644 --- a/db/versions/11040-grayMonstera/00-firstScript.sql +++ b/db/versions/11040-grayMonstera/00-firstScript.sql @@ -7,7 +7,7 @@ ADD CONSTRAINT route_vehicleFk FOREIGN KEY (vehicleFk) REFERENCES vn.vehicle(id) UPDATE vn.route SET firstEditorFk = NULL - WHERE firstEditorFk NOT IN (SELECT id FROM vn.worker); + WHERE firstEditorFk NOT IN (SELECT id FROM account.user); ALTER TABLE vn.route -ADD CONSTRAINT route_firstEditorFk FOREIGN KEY (firstEditorFk) REFERENCES vn.worker(id); +ADD CONSTRAINT route_firstEditorFk FOREIGN KEY (firstEditorFk) REFERENCES account.user(id); From 993dd0d8bd07a53c8689a664c395f8813e66df23 Mon Sep 17 00:00:00 2001 From: ivanm Date: Thu, 16 May 2024 13:15:55 +0200 Subject: [PATCH 3/3] refs #6965 Modify firstEditorFk NULL --- db/versions/11040-grayMonstera/00-firstScript.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/db/versions/11040-grayMonstera/00-firstScript.sql b/db/versions/11040-grayMonstera/00-firstScript.sql index 8fb0e85c3..1fabe4ff5 100644 --- a/db/versions/11040-grayMonstera/00-firstScript.sql +++ b/db/versions/11040-grayMonstera/00-firstScript.sql @@ -5,6 +5,9 @@ UPDATE vn.route ALTER TABLE vn.route ADD CONSTRAINT route_vehicleFk FOREIGN KEY (vehicleFk) REFERENCES vn.vehicle(id); +ALTER TABLE vn.route +MODIFY COLUMN firstEditorFk int(10) unsigned NULL; + UPDATE vn.route SET firstEditorFk = NULL WHERE firstEditorFk NOT IN (SELECT id FROM account.user);