diff --git a/admin/sql/CreateConstraints.sql b/admin/sql/CreateConstraints.sql index 5df42837219..2224b4a2eb5 100644 --- a/admin/sql/CreateConstraints.sql +++ b/admin/sql/CreateConstraints.sql @@ -170,6 +170,19 @@ ADD CONSTRAINT group_type_implies_null_gender CHECK ( OR type IS NULL ); +ALTER TABLE artist +ADD CONSTRAINT character_type_implies_no_end CHECK ( + ( + type = 4 AND + end_date_day IS NULL AND + end_date_month IS NULL AND + end_date_year IS NULL AND + end_area IS NULL AND + ended = FALSE + ) + OR type != 4 +); + ALTER TABLE release_label ADD CHECK (catalog_number IS NOT NULL OR label IS NOT NULL); diff --git a/admin/sql/updates/20241104-mbs-9885.sql b/admin/sql/updates/20241104-mbs-9885.sql new file mode 100644 index 00000000000..00b522baeb5 --- /dev/null +++ b/admin/sql/updates/20241104-mbs-9885.sql @@ -0,0 +1,29 @@ +\set ON_ERROR_STOP 1 + +BEGIN; + +UPDATE artist +SET end_date_day = NULL, + end_date_month = NULL, + end_date_year = NULL, + end_area = NULL, + ended = FALSE +WHERE type = 4; + +ALTER TABLE artist +DROP CONSTRAINT IF EXISTS character_type_implies_no_end; + +ALTER TABLE artist +ADD CONSTRAINT character_type_implies_no_end CHECK ( + ( + type = 4 AND + end_date_day IS NULL AND + end_date_month IS NULL AND + end_date_year IS NULL AND + end_area IS NULL AND + ended = FALSE + ) + OR type != 4 +); + +COMMIT; diff --git a/admin/sql/updates/schema-change/30.master_and_standalone.sql b/admin/sql/updates/schema-change/30.master_and_standalone.sql new file mode 100644 index 00000000000..dc80e8eeb5e --- /dev/null +++ b/admin/sql/updates/schema-change/30.master_and_standalone.sql @@ -0,0 +1,35 @@ +-- Generated by CompileSchemaScripts.pl from: +-- 20241104-mbs-9885.sql +\set ON_ERROR_STOP 1 +BEGIN; +SET search_path = musicbrainz, public; +SET LOCAL statement_timeout = 0; +-------------------------------------------------------------------------------- +SELECT '20241104-mbs-9885.sql'; + + +UPDATE artist +SET end_date_day = NULL, + end_date_month = NULL, + end_date_year = NULL, + end_area = NULL, + ended = FALSE +WHERE type = 4; + +ALTER TABLE artist +DROP CONSTRAINT IF EXISTS character_type_implies_no_end; + +ALTER TABLE artist +ADD CONSTRAINT character_type_implies_no_end CHECK ( + ( + type = 4 AND + end_date_day IS NULL AND + end_date_month IS NULL AND + end_date_year IS NULL AND + end_area IS NULL AND + ended = FALSE + ) + OR type != 4 +); + +COMMIT; diff --git a/upgrade.json b/upgrade.json index 80853eb68d6..085414f3b7a 100644 --- a/upgrade.json +++ b/upgrade.json @@ -230,5 +230,10 @@ "20240223-mbs-13421-fks.sql", "20240319-mbs-13514.sql" ] + }, + "30": { + "master_and_standalone": [ + "20241104-mbs-9885.sql" + ] } }