From 723eaed19b60466fa01c0e12a388b592ac1d78f4 Mon Sep 17 00:00:00 2001 From: ivanm Date: Thu, 20 Feb 2025 18:33:14 +0100 Subject: [PATCH 1/5] refactor: refs #8613 add fk to claimEnd.claimDestinationFk --- db/routines/vn/triggers/claimEnd_beforeInsert.sql | 1 + db/versions/11444-orangeMastic/00-firstScript.sql | 8 ++++++++ db/versions/11444-orangeMastic/01-firstScript.sql | 7 +++++++ 3 files changed, 16 insertions(+) create mode 100644 db/versions/11444-orangeMastic/00-firstScript.sql create mode 100644 db/versions/11444-orangeMastic/01-firstScript.sql diff --git a/db/routines/vn/triggers/claimEnd_beforeInsert.sql b/db/routines/vn/triggers/claimEnd_beforeInsert.sql index 113fb8179f..2e458eb3bb 100644 --- a/db/routines/vn/triggers/claimEnd_beforeInsert.sql +++ b/db/routines/vn/triggers/claimEnd_beforeInsert.sql @@ -4,5 +4,6 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`claimEnd_beforeInsert` FOR EACH ROW BEGIN SET NEW.editorFk = account.myUser_getId(); + SET NEW.claimDestinationFk = 1; END$$ DELIMITER ; diff --git a/db/versions/11444-orangeMastic/00-firstScript.sql b/db/versions/11444-orangeMastic/00-firstScript.sql new file mode 100644 index 0000000000..2476ea6f2c --- /dev/null +++ b/db/versions/11444-orangeMastic/00-firstScript.sql @@ -0,0 +1,8 @@ +UPDATE vn.claimEnd ce + JOIN( + SELECT id + FROM vn.claimEnd + WHERE claimDestinationFk NOT IN + (SELECT id FROM vn.claimDestination WHERE id IS NOT NULL) + ) s ON ce.id = s.id + SET ce.claimDestinationFk = 1; \ No newline at end of file diff --git a/db/versions/11444-orangeMastic/01-firstScript.sql b/db/versions/11444-orangeMastic/01-firstScript.sql new file mode 100644 index 0000000000..74882d710b --- /dev/null +++ b/db/versions/11444-orangeMastic/01-firstScript.sql @@ -0,0 +1,7 @@ +ALTER TABLE vn.claimEnd + MODIFY COLUMN claimDestinationFk tinyint(3) unsigned NOT NULL, + ADD CONSTRAINT fk_claimEnd_claimDestination + FOREIGN KEY (claimDestinationFk) + REFERENCES claimDestination(id) + ON UPDATE CASCADE + ON DELETE CASCADE; \ No newline at end of file From 726825164d9f209a4763c4d01a512db332004a02 Mon Sep 17 00:00:00 2001 From: ivanm Date: Fri, 21 Feb 2025 12:21:13 +0100 Subject: [PATCH 2/5] refactor: refs #8613 alter table default 1 --- db/routines/vn/triggers/claimEnd_beforeInsert.sql | 1 - db/versions/11444-orangeMastic/01-firstScript.sql | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/db/routines/vn/triggers/claimEnd_beforeInsert.sql b/db/routines/vn/triggers/claimEnd_beforeInsert.sql index 2e458eb3bb..113fb8179f 100644 --- a/db/routines/vn/triggers/claimEnd_beforeInsert.sql +++ b/db/routines/vn/triggers/claimEnd_beforeInsert.sql @@ -4,6 +4,5 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`claimEnd_beforeInsert` FOR EACH ROW BEGIN SET NEW.editorFk = account.myUser_getId(); - SET NEW.claimDestinationFk = 1; END$$ DELIMITER ; diff --git a/db/versions/11444-orangeMastic/01-firstScript.sql b/db/versions/11444-orangeMastic/01-firstScript.sql index 74882d710b..31d7bb4bbc 100644 --- a/db/versions/11444-orangeMastic/01-firstScript.sql +++ b/db/versions/11444-orangeMastic/01-firstScript.sql @@ -1,5 +1,5 @@ ALTER TABLE vn.claimEnd - MODIFY COLUMN claimDestinationFk tinyint(3) unsigned NOT NULL, + MODIFY COLUMN claimDestinationFk tinyint(3) unsigned NOT NULL DEFAULT 1, ADD CONSTRAINT fk_claimEnd_claimDestination FOREIGN KEY (claimDestinationFk) REFERENCES claimDestination(id) From 8e6eeca5e8e5d182798b2f1181ddd51fa8a0aade Mon Sep 17 00:00:00 2001 From: ivanm Date: Mon, 24 Feb 2025 12:17:59 +0100 Subject: [PATCH 3/5] refactor: refs #8613 change on delete to restrict --- db/versions/11444-orangeMastic/01-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/11444-orangeMastic/01-firstScript.sql b/db/versions/11444-orangeMastic/01-firstScript.sql index 31d7bb4bbc..4b7bfb2863 100644 --- a/db/versions/11444-orangeMastic/01-firstScript.sql +++ b/db/versions/11444-orangeMastic/01-firstScript.sql @@ -4,4 +4,4 @@ ALTER TABLE vn.claimEnd FOREIGN KEY (claimDestinationFk) REFERENCES claimDestination(id) ON UPDATE CASCADE - ON DELETE CASCADE; \ No newline at end of file + ON DELETE RESTRICT; \ No newline at end of file From b2159383276d342817ed075b862f684d9cdd047b Mon Sep 17 00:00:00 2001 From: jtubau Date: Mon, 24 Feb 2025 14:38:52 +0100 Subject: [PATCH 4/5] fix: update foreign key model reference in agency-workCenter.json --- back/models/agency-workCenter.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/models/agency-workCenter.json b/back/models/agency-workCenter.json index adf1e5bcb0..71de17cb25 100644 --- a/back/models/agency-workCenter.json +++ b/back/models/agency-workCenter.json @@ -24,7 +24,7 @@ "relations": { "agency": { "type": "belongsTo", - "model": "WorkCenter", + "model": "Agency", "foreignKey": "agencyFk" }, "workCenter": { From 04b6be23a1969213e73d333e0d0f9a4f7a846d57 Mon Sep 17 00:00:00 2001 From: ivanm Date: Mon, 24 Feb 2025 18:13:56 +0100 Subject: [PATCH 5/5] fix: refs #8613 fk claimEnd --- db/versions/11444-orangeMastic/01-firstScript.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/versions/11444-orangeMastic/01-firstScript.sql b/db/versions/11444-orangeMastic/01-firstScript.sql index 4b7bfb2863..38cd7c0914 100644 --- a/db/versions/11444-orangeMastic/01-firstScript.sql +++ b/db/versions/11444-orangeMastic/01-firstScript.sql @@ -1,5 +1,7 @@ ALTER TABLE vn.claimEnd - MODIFY COLUMN claimDestinationFk tinyint(3) unsigned NOT NULL DEFAULT 1, + MODIFY COLUMN claimDestinationFk tinyint(3) unsigned NOT NULL DEFAULT 1; + +ALTER TABLE vn.claimEnd ADD CONSTRAINT fk_claimEnd_claimDestination FOREIGN KEY (claimDestinationFk) REFERENCES claimDestination(id)