From 1322023e233a44e88841676872dc945674a4b9f7 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 18 Nov 2024 18:24:15 +0100 Subject: [PATCH] `database`: Allow `meta_subjects.subject` to be null --- .../2024-11-18-160501_meta_subject-null/down.sql | 10 ++++++++++ .../2024-11-18-160501_meta_subject-null/up.sql | 5 +++++ 2 files changed, 15 insertions(+) create mode 100644 acrate_database/migrations/2024-11-18-160501_meta_subject-null/down.sql create mode 100644 acrate_database/migrations/2024-11-18-160501_meta_subject-null/up.sql diff --git a/acrate_database/migrations/2024-11-18-160501_meta_subject-null/down.sql b/acrate_database/migrations/2024-11-18-160501_meta_subject-null/down.sql new file mode 100644 index 0000000..58ab58c --- /dev/null +++ b/acrate_database/migrations/2024-11-18-160501_meta_subject-null/down.sql @@ -0,0 +1,10 @@ +UPDATE meta_subjects SET subject = 'invalid:subject.null' WHERE subject IS NULL; + +ALTER TABLE meta_subjects ALTER subject SET NOT NULL; + +ALTER TABLE meta_subjects ADD CONSTRAINT either_subject_or_redirect_not_null + CHECK ( + (subject IS NOT NULL AND redirect IS NULL) + OR + (subject IS NULL AND redirect IS NOT NULL) + ); diff --git a/acrate_database/migrations/2024-11-18-160501_meta_subject-null/up.sql b/acrate_database/migrations/2024-11-18-160501_meta_subject-null/up.sql new file mode 100644 index 0000000..cba9028 --- /dev/null +++ b/acrate_database/migrations/2024-11-18-160501_meta_subject-null/up.sql @@ -0,0 +1,5 @@ +ALTER TABLE meta_subjects DROP CONSTRAINT either_subject_or_redirect_not_null; + +ALTER TABLE meta_subjects ALTER subject DROP NOT NULL; + +UPDATE meta_subjects SET subject = NULL WHERE subject = 'invalid:subject.null';