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';