-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add proper foreign keys to all document related tables
Foreign keys that contain ON DELETE CASCADE that is.
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
resources/migrations/20241008082211-add-foreign-keys-to-document-child-tables.down.sql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-- this change cannot be undone, sorry |
63 changes: 63 additions & 0 deletions
63
resources/migrations/20241008082211-add-foreign-keys-to-document-child-tables.up.sql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
-- Drop the old foreign key indexes | ||
-- because they are not ON DELETE CASCADE | ||
-- or because they do not conform to the naming scheme | ||
|
||
ALTER TABLE dictionary_localword | ||
DROP FOREIGN KEY IF EXISTS dictionary_localword_ibfk_1; | ||
|
||
--;; | ||
|
||
ALTER TABLE documents_version | ||
DROP FOREIGN KEY IF EXISTS documents_version_documents_document; | ||
|
||
--;; | ||
|
||
ALTER TABLE documents_version | ||
DROP FOREIGN KEY IF EXISTS document_id_refs_id_6e9aeb8bd76a8925; | ||
|
||
--;; | ||
|
||
ALTER TABLE documents_image | ||
DROP FOREIGN KEY IF EXISTS document_id_refs_id_7dcae6cd2eb4b4cc; | ||
|
||
--;; | ||
|
||
ALTER TABLE documents_product | ||
DROP FOREIGN KEY IF EXISTS document_id_refs_id_7ff5341caa42ce0c; | ||
|
||
--;; | ||
|
||
-- then add the new foreign keys | ||
|
||
ALTER TABLE dictionary_unknownword | ||
ADD CONSTRAINT fk_dictionary_unknownword__documents_document | ||
FOREIGN KEY (document_id) REFERENCES documents_document (id) | ||
ON DELETE CASCADE; | ||
|
||
--;; | ||
|
||
ALTER TABLE dictionary_localword | ||
ADD CONSTRAINT fk_dictionary_localword__documents_document | ||
FOREIGN KEY (document_id) REFERENCES documents_document (id) | ||
ON DELETE CASCADE; | ||
|
||
--;; | ||
|
||
ALTER TABLE documents_version | ||
ADD CONSTRAINT fk_documents_version__documents_document | ||
FOREIGN KEY (document_id) REFERENCES documents_document (id) | ||
ON DELETE CASCADE; | ||
|
||
--;; | ||
|
||
ALTER TABLE documents_image | ||
ADD CONSTRAINT fk_documents_image__documents_document | ||
FOREIGN KEY (document_id) REFERENCES documents_document (id) | ||
ON DELETE CASCADE; | ||
|
||
--;; | ||
|
||
ALTER TABLE documents_product | ||
ADD CONSTRAINT fk_documents_product__documents_document | ||
FOREIGN KEY (document_id) REFERENCES documents_document (id) | ||
ON DELETE CASCADE; |