From 37d507a54251f96cb7aa71a3ab59c41f357db61e Mon Sep 17 00:00:00 2001 From: Kartik Ohri Date: Fri, 26 Jul 2024 19:56:34 +0530 Subject: [PATCH] Update to MB DB Schema 29 - 2024 Q2 --- CHANGELOG.rst | 5 + mbdata/__init__.py | 2 +- mbdata/models.py | 103 +- mbdata/sql/CreateConstraints.sql | 5 +- mbdata/sql/CreateFKConstraints.sql | 60 +- mbdata/sql/CreateFunctions.sql | 43 +- mbdata/sql/CreateIndexes.sql | 6 +- mbdata/sql/CreatePrimaryKeys.sql | 7 +- mbdata/sql/CreateTables.sql | 56 +- mbdata/sql/CreateTriggers.sql | 3 - mbdata/sql/CreateTypes.sql | 2 + mbdata/sql/DropFKConstraints.sql | 11 +- mbdata/sql/DropFunctions.sql | 1 - mbdata/sql/DropIndexes.sql | 2 + mbdata/sql/DropPrimaryKeys.sql | 7 +- mbdata/sql/DropTables.sql | 7 +- mbdata/sql/DropTriggers.sql | 1 - mbdata/sql/DropTypes.sql | 1 + mbdata/sql/InsertTestData.sql | 37 +- mbdata/sql/SetSequences.sql | 1 + mbdata/sql/TruncateTables.sql | 7 +- mbdata/sql/caa/CreateMQTriggers.sql | 148 -- mbdata/sql/caa/DropMQTriggers.sql | 19 - mbdata/sql/dbmirror2/MasterSetup.sql | 13 - mbdata/sql/dbmirror2/README | 2 +- mbdata/sql/eaa/CreateMQTriggers.sql | 161 -- mbdata/sql/eaa/DropMQTriggers.sql | 21 - .../20130309-migrate-transclusion-table.pl | 5 +- .../sql/updates/20130313-bcrypt-passwords.pl | 3 +- .../20130322-init-bundled-replication.pl | 16 - .../20130724-refresh-release_meta-asin.sql | 2 +- .../20130906-materialise-recording-lengths.pl | 3 +- .../sql/updates/20220207-mbs-12224-mirror.sql | 162 -- .../updates/20220207-mbs-12224-standalone.sql | 162 ++ .../sql/updates/schema-change/20.mirror.sql | 1844 ------------- .../updates/schema-change/20.standalone.sql | 644 ----- .../sql/updates/schema-change/21.mirror.sql | 1160 --------- .../updates/schema-change/21.standalone.sql | 228 -- .../sql/updates/schema-change/22.mirror.sql | 574 ---- .../updates/schema-change/22.standalone.sql | 435 ---- .../updates/schema-change/23.extensions.sql | 10 - .../sql/updates/schema-change/23.mirror.sql | 549 ---- .../updates/schema-change/23.standalone.sql | 155 -- .../sql/updates/schema-change/24.mirror.sql | 816 ------ .../updates/schema-change/24.standalone.sql | 432 ---- .../sql/updates/schema-change/25.mirror.sql | 718 ----- .../updates/schema-change/25.standalone.sql | 155 -- .../sql/updates/schema-change/26.mirror.sql | 1165 --------- .../updates/schema-change/26.standalone.sql | 177 -- .../sql/updates/schema-change/27.mirror.sql | 2040 --------------- .../updates/schema-change/27.standalone.sql | 2301 ----------------- poetry.lock | 32 +- 52 files changed, 348 insertions(+), 14171 deletions(-) delete mode 100644 mbdata/sql/caa/CreateMQTriggers.sql delete mode 100644 mbdata/sql/caa/DropMQTriggers.sql delete mode 100644 mbdata/sql/eaa/CreateMQTriggers.sql delete mode 100644 mbdata/sql/eaa/DropMQTriggers.sql delete mode 100755 mbdata/sql/updates/20130322-init-bundled-replication.pl delete mode 100644 mbdata/sql/updates/schema-change/20.mirror.sql delete mode 100644 mbdata/sql/updates/schema-change/20.standalone.sql delete mode 100644 mbdata/sql/updates/schema-change/21.mirror.sql delete mode 100644 mbdata/sql/updates/schema-change/21.standalone.sql delete mode 100644 mbdata/sql/updates/schema-change/22.mirror.sql delete mode 100644 mbdata/sql/updates/schema-change/22.standalone.sql delete mode 100644 mbdata/sql/updates/schema-change/23.extensions.sql delete mode 100644 mbdata/sql/updates/schema-change/23.mirror.sql delete mode 100644 mbdata/sql/updates/schema-change/23.standalone.sql delete mode 100644 mbdata/sql/updates/schema-change/24.mirror.sql delete mode 100644 mbdata/sql/updates/schema-change/24.standalone.sql delete mode 100644 mbdata/sql/updates/schema-change/25.mirror.sql delete mode 100644 mbdata/sql/updates/schema-change/25.standalone.sql delete mode 100644 mbdata/sql/updates/schema-change/26.mirror.sql delete mode 100644 mbdata/sql/updates/schema-change/26.standalone.sql delete mode 100644 mbdata/sql/updates/schema-change/27.mirror.sql delete mode 100644 mbdata/sql/updates/schema-change/27.standalone.sql diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 12469e8..f52e785 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,8 @@ +Version 29.0.0 +============== + +- Schema change 29. + Version 27.1.0 ============== diff --git a/mbdata/__init__.py b/mbdata/__init__.py index 44ee59c..69ffafe 100644 --- a/mbdata/__init__.py +++ b/mbdata/__init__.py @@ -1,4 +1,4 @@ # Copyright (C) 2013 Lukas Lalinsky # Distributed under the MIT license, see the LICENSE file for details. -__version__ = "27.1.0" +__version__ = "29.0.0" diff --git a/mbdata/models.py b/mbdata/models.py index 43c2a08..4c35ef3 100644 --- a/mbdata/models.py +++ b/mbdata/models.py @@ -838,7 +838,6 @@ class CDTOC(Base): track_count = Column(Integer, nullable=False) leadout_offset = Column(Integer, nullable=False) track_offset = Column(Integer, nullable=False) - degraded = Column(Boolean, nullable=False, default=False, server_default=sql.false()) created = Column(DateTime(timezone=True), server_default=sql.func.now()) @@ -937,6 +936,26 @@ class EditNote(Base): edit = relationship('Edit', foreign_keys=[edit_id], innerjoin=True) +class EditNoteChange(Base): + __tablename__ = 'edit_note_change' + __table_args__ = ( + Index('edit_note_change_idx_edit_note', 'edit_note'), + {'schema': mbdata.config.schemas.get('musicbrainz', 'musicbrainz')} + ) + + id = Column(Integer, primary_key=True) + status = Column(Enum('deleted', 'edited', name='EDIT_NOTE_STATUS', schema=mbdata.config.schemas.get('musicbrainz', 'musicbrainz'))) + edit_note_id = Column('edit_note', Integer, ForeignKey(apply_schema('edit_note.id', 'musicbrainz'), name='edit_note_change_fk_edit_note'), nullable=False) + change_editor_id = Column('change_editor', Integer, ForeignKey(apply_schema('editor.id', 'musicbrainz'), name='edit_note_change_fk_change_editor'), nullable=False) + change_time = Column(DateTime(timezone=True), server_default=sql.func.now()) + old_note = Column(String, nullable=False) + new_note = Column(String, nullable=False) + reason = Column(String, nullable=False, default='', server_default=sql.text("''")) + + edit_note = relationship('EditNote', foreign_keys=[edit_note_id], innerjoin=True) + change_editor = relationship('Editor', foreign_keys=[change_editor_id], innerjoin=True) + + class EditNoteRecipient(Base): __tablename__ = 'edit_note_recipient' __table_args__ = ( @@ -6526,7 +6545,6 @@ class LinkType(Base): link_phrase = Column(String(255), nullable=False) reverse_link_phrase = Column(String(255), nullable=False) long_link_phrase = Column(String(255), nullable=False) - priority = Column(Integer, nullable=False, default=0, server_default=sql.text('0')) last_updated = Column(DateTime(timezone=True), server_default=sql.func.now()) is_deprecated = Column(Boolean, nullable=False, default=False, server_default=sql.false()) has_dates = Column(Boolean, nullable=False, default=True, server_default=sql.true()) @@ -6673,6 +6691,22 @@ class EditorCollectionEvent(Base): event = relationship('Event', foreign_keys=[event_id], innerjoin=True) +class EditorCollectionGenre(Base): + __tablename__ = 'editor_collection_genre' + __table_args__ = ( + {'schema': mbdata.config.schemas.get('musicbrainz', 'musicbrainz')} + ) + + collection_id = Column('collection', Integer, ForeignKey(apply_schema('editor_collection.id', 'musicbrainz'), name='editor_collection_genre_fk_collection'), nullable=False, primary_key=True) + genre_id = Column('genre', Integer, ForeignKey(apply_schema('genre.id', 'musicbrainz'), name='editor_collection_genre_fk_genre'), nullable=False, primary_key=True) + added = Column(DateTime(timezone=True), server_default=sql.func.now()) + position = Column(Integer, nullable=False, default=0, server_default=sql.text('0')) + comment = Column(String, nullable=False, default='', server_default=sql.text("''")) + + collection = relationship('EditorCollection', foreign_keys=[collection_id], innerjoin=True) + genre = relationship('Genre', foreign_keys=[genre_id], innerjoin=True) + + class EditorCollectionInstrument(Base): __tablename__ = 'editor_collection_instrument' __table_args__ = ( @@ -6841,59 +6875,6 @@ class EditorOauthToken(Base): application = relationship('Application', foreign_keys=[application_id], innerjoin=True) -class EditorWatchPreferences(Base): - __tablename__ = 'editor_watch_preferences' - __table_args__ = ( - {'schema': mbdata.config.schemas.get('musicbrainz', 'musicbrainz')} - ) - - editor_id = Column('editor', Integer, ForeignKey(apply_schema('editor.id', 'musicbrainz'), name='editor_watch_preferences_fk_editor', ondelete='CASCADE'), nullable=False, primary_key=True) - notify_via_email = Column(Boolean, nullable=False, default=True, server_default=sql.true()) - notification_timeframe = Column(Interval, nullable=False, default='1 week', server_default=sql.text("'1 week'")) - last_checked = Column(DateTime(timezone=True), nullable=False, server_default=sql.func.now()) - - editor = relationship('Editor', foreign_keys=[editor_id], innerjoin=True) - - -class EditorWatchArtist(Base): - __tablename__ = 'editor_watch_artist' - __table_args__ = ( - {'schema': mbdata.config.schemas.get('musicbrainz', 'musicbrainz')} - ) - - artist_id = Column('artist', Integer, ForeignKey(apply_schema('artist.id', 'musicbrainz'), name='editor_watch_artist_fk_artist', ondelete='CASCADE'), nullable=False, primary_key=True) - editor_id = Column('editor', Integer, ForeignKey(apply_schema('editor.id', 'musicbrainz'), name='editor_watch_artist_fk_editor', ondelete='CASCADE'), nullable=False, primary_key=True) - - artist = relationship('Artist', foreign_keys=[artist_id], innerjoin=True) - editor = relationship('Editor', foreign_keys=[editor_id], innerjoin=True) - - -class EditorWatchReleaseGroupType(Base): - __tablename__ = 'editor_watch_release_group_type' - __table_args__ = ( - {'schema': mbdata.config.schemas.get('musicbrainz', 'musicbrainz')} - ) - - editor_id = Column('editor', Integer, ForeignKey(apply_schema('editor.id', 'musicbrainz'), name='editor_watch_release_group_type_fk_editor', ondelete='CASCADE'), nullable=False, primary_key=True) - release_group_type_id = Column('release_group_type', Integer, ForeignKey(apply_schema('release_group_primary_type.id', 'musicbrainz'), name='editor_watch_release_group_type_fk_release_group_type'), nullable=False, primary_key=True) - - editor = relationship('Editor', foreign_keys=[editor_id], innerjoin=True) - release_group_type = relationship('ReleaseGroupPrimaryType', foreign_keys=[release_group_type_id], innerjoin=True) - - -class EditorWatchReleaseStatus(Base): - __tablename__ = 'editor_watch_release_status' - __table_args__ = ( - {'schema': mbdata.config.schemas.get('musicbrainz', 'musicbrainz')} - ) - - editor_id = Column('editor', Integer, ForeignKey(apply_schema('editor.id', 'musicbrainz'), name='editor_watch_release_status_fk_editor', ondelete='CASCADE'), nullable=False, primary_key=True) - release_status_id = Column('release_status', Integer, ForeignKey(apply_schema('release_status.id', 'musicbrainz'), name='editor_watch_release_status_fk_release_status'), nullable=False, primary_key=True) - - editor = relationship('Editor', foreign_keys=[editor_id], innerjoin=True) - release_status = relationship('ReleaseStatus', foreign_keys=[release_status_id], innerjoin=True) - - class Medium(Base): __tablename__ = 'medium' __table_args__ = ( @@ -8573,6 +8554,18 @@ class MediumIndex(Base): medium = relationship('Medium', foreign_keys=[medium_id]) +class UnreferencedRowLog(Base): + __tablename__ = 'unreferenced_row_log' + __table_args__ = ( + Index('unreferenced_row_log_idx_inserted', 'inserted'), + {'schema': mbdata.config.schemas.get('musicbrainz', 'musicbrainz')} + ) + + table_name = Column(String, nullable=False, primary_key=True) + row_id = Column(Integer, nullable=False, primary_key=True) + inserted = Column(DateTime(timezone=True), server_default=sql.func.now()) + + class URL(Base): __tablename__ = 'url' __table_args__ = ( diff --git a/mbdata/sql/CreateConstraints.sql b/mbdata/sql/CreateConstraints.sql index 52e3294..5df4283 100644 --- a/mbdata/sql/CreateConstraints.sql +++ b/mbdata/sql/CreateConstraints.sql @@ -41,7 +41,7 @@ ALTER TABLE artist_alias ALTER TABLE editor_collection_type ADD CONSTRAINT allowed_collection_entity_type CHECK ( entity_type IN ( - 'area', 'artist', 'event', 'instrument', 'label', + 'area', 'artist', 'event', 'genre', 'instrument', 'label', 'place', 'recording', 'release', 'release_group', 'series', 'work' ) @@ -76,7 +76,8 @@ ALTER TABLE instrument_alias ALTER TABLE label ADD CONSTRAINT control_for_whitespace CHECK (controlled_for_whitespace(name)), - ADD CONSTRAINT only_non_empty CHECK (name != ''); + ADD CONSTRAINT only_non_empty CHECK (name != ''), + ADD CONSTRAINT label_code_length CHECK (label_code > 0 AND label_code < 1000000); ALTER TABLE label_alias ADD CONSTRAINT control_for_whitespace CHECK (controlled_for_whitespace(name)), diff --git a/mbdata/sql/CreateFKConstraints.sql b/mbdata/sql/CreateFKConstraints.sql index 33f3be0..eef896f 100644 --- a/mbdata/sql/CreateFKConstraints.sql +++ b/mbdata/sql/CreateFKConstraints.sql @@ -500,6 +500,16 @@ ALTER TABLE edit_note FOREIGN KEY (edit) REFERENCES edit(id); +ALTER TABLE edit_note_change + ADD CONSTRAINT edit_note_change_fk_edit_note + FOREIGN KEY (edit_note) + REFERENCES edit_note(id); + +ALTER TABLE edit_note_change + ADD CONSTRAINT edit_note_change_fk_change_editor + FOREIGN KEY (change_editor) + REFERENCES editor(id); + ALTER TABLE edit_note_recipient ADD CONSTRAINT edit_note_recipient_fk_recipient FOREIGN KEY (recipient) @@ -657,6 +667,16 @@ ALTER TABLE editor_collection_event FOREIGN KEY (event) REFERENCES event(id); +ALTER TABLE editor_collection_genre + ADD CONSTRAINT editor_collection_genre_fk_collection + FOREIGN KEY (collection) + REFERENCES editor_collection(id); + +ALTER TABLE editor_collection_genre + ADD CONSTRAINT editor_collection_genre_fk_genre + FOREIGN KEY (genre) + REFERENCES genre(id); + ALTER TABLE editor_collection_gid_redirect ADD CONSTRAINT editor_collection_gid_redirect_fk_new_id FOREIGN KEY (new_id) @@ -877,46 +897,6 @@ ALTER TABLE editor_subscribe_series_deleted FOREIGN KEY (deleted_by) REFERENCES edit(id); -ALTER TABLE editor_watch_artist - ADD CONSTRAINT editor_watch_artist_fk_artist - FOREIGN KEY (artist) - REFERENCES artist(id) - ON DELETE CASCADE; - -ALTER TABLE editor_watch_artist - ADD CONSTRAINT editor_watch_artist_fk_editor - FOREIGN KEY (editor) - REFERENCES editor(id) - ON DELETE CASCADE; - -ALTER TABLE editor_watch_preferences - ADD CONSTRAINT editor_watch_preferences_fk_editor - FOREIGN KEY (editor) - REFERENCES editor(id) - ON DELETE CASCADE; - -ALTER TABLE editor_watch_release_group_type - ADD CONSTRAINT editor_watch_release_group_type_fk_editor - FOREIGN KEY (editor) - REFERENCES editor(id) - ON DELETE CASCADE; - -ALTER TABLE editor_watch_release_group_type - ADD CONSTRAINT editor_watch_release_group_type_fk_release_group_type - FOREIGN KEY (release_group_type) - REFERENCES release_group_primary_type(id); - -ALTER TABLE editor_watch_release_status - ADD CONSTRAINT editor_watch_release_status_fk_editor - FOREIGN KEY (editor) - REFERENCES editor(id) - ON DELETE CASCADE; - -ALTER TABLE editor_watch_release_status - ADD CONSTRAINT editor_watch_release_status_fk_release_status - FOREIGN KEY (release_status) - REFERENCES release_status(id); - ALTER TABLE event ADD CONSTRAINT event_fk_type FOREIGN KEY (type) diff --git a/mbdata/sql/CreateFunctions.sql b/mbdata/sql/CreateFunctions.sql index 89696ef..53cc407 100644 --- a/mbdata/sql/CreateFunctions.sql +++ b/mbdata/sql/CreateFunctions.sql @@ -101,13 +101,12 @@ DECLARE ref_count integer; BEGIN -- decrement ref_count for the old name, - -- or delete it if ref_count would drop to 0 + -- or prepare it for deletion if ref_count would drop to 0 EXECUTE 'SELECT ref_count FROM ' || tbl || ' WHERE id = ' || row_id || ' FOR UPDATE' INTO ref_count; IF ref_count <= val THEN - EXECUTE 'DELETE FROM ' || tbl || ' WHERE id = ' || row_id; - ELSE - EXECUTE 'UPDATE ' || tbl || ' SET ref_count = ref_count - ' || val || ' WHERE id = ' || row_id; + EXECUTE 'INSERT INTO unreferenced_row_log (table_name, row_id) VALUES ($1, $2)' USING tbl, row_id; END IF; + EXECUTE 'UPDATE ' || tbl || ' SET ref_count = ref_count - ' || val || ' WHERE id = ' || row_id; RETURN; END; $$ LANGUAGE 'plpgsql'; @@ -204,21 +203,6 @@ $$ LANGUAGE 'plpgsql'; -- editor triggers ----------------------------------------------------------------------- -CREATE OR REPLACE FUNCTION a_ins_editor() RETURNS trigger AS $$ -BEGIN - -- add a new entry to the editor_watch_preference table - INSERT INTO editor_watch_preferences (editor) VALUES (NEW.id); - - -- by default watch for new official albums - INSERT INTO editor_watch_release_group_type (editor, release_group_type) - VALUES (NEW.id, 2); - INSERT INTO editor_watch_release_status (editor, release_status) - VALUES (NEW.id, 1); - - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - CREATE OR REPLACE FUNCTION check_editor_name() RETURNS trigger AS $$ BEGIN IF (SELECT 1 FROM old_editor_name WHERE lower(name) = lower(NEW.name)) @@ -495,6 +479,19 @@ BEGIN PERFORM dec_ref_count('artist_credit', OLD.artist_credit, 1); PERFORM inc_ref_count('artist_credit', NEW.artist_credit, 1); END IF; + IF ( + NEW.status IS DISTINCT FROM OLD.status AND + (NEW.status = 6 OR OLD.status = 6) + ) THEN + PERFORM set_release_first_release_date(NEW.id); + + -- avoid executing it twice as this will be executed a few lines below if RG changes + IF NEW.release_group = OLD.release_group THEN + PERFORM set_release_group_first_release_date(NEW.release_group); + END IF; + + PERFORM set_releases_recordings_first_release_dates(ARRAY[NEW.id]); + END IF; IF NEW.release_group != OLD.release_group THEN -- release group is changed, decrement release_count in the original RG, increment in the new one UPDATE release_group_meta SET release_count = release_count - 1 WHERE id = OLD.release_group; @@ -1082,7 +1079,13 @@ BEGIN SELECT release, date_year, date_month, date_day FROM release_unknown_country ) all_dates WHERE ' || condition || - ' ORDER BY release, year NULLS LAST, month NULLS LAST, day NULLS LAST'; + ' AND NOT EXISTS ( + SELECT TRUE + FROM release + WHERE release.id = all_dates.release + AND status = 6 + ) + ORDER BY release, year NULLS LAST, month NULLS LAST, day NULLS LAST'; END; $$ LANGUAGE 'plpgsql' STRICT; diff --git a/mbdata/sql/CreateIndexes.sql b/mbdata/sql/CreateIndexes.sql index c242c6a..b5c0b69 100644 --- a/mbdata/sql/CreateIndexes.sql +++ b/mbdata/sql/CreateIndexes.sql @@ -147,7 +147,7 @@ CREATE INDEX edit_data_idx_link_type ON edit_data USING GIN ( (data#>>'{link,link_type,id}')::int, (data#>>'{old,link_type,id}')::int, (data#>>'{new,link_type,id}')::int, - (data#>>'{relationship,link_type,id}')::int + (data#>>'{relationship,link,type,id}')::int ], NULL) ); @@ -170,6 +170,8 @@ CREATE INDEX edit_url_idx ON edit_url (url); CREATE INDEX edit_note_idx_edit ON edit_note (edit); CREATE INDEX edit_note_idx_editor ON edit_note (editor); +CREATE INDEX edit_note_change_idx_edit_note ON edit_note_change (edit_note); + CREATE INDEX edit_note_recipient_idx_recipient ON edit_note_recipient (recipient); CREATE UNIQUE INDEX event_idx_gid ON event (gid); @@ -671,6 +673,8 @@ CREATE INDEX track_raw_idx_release ON track_raw (release); CREATE INDEX medium_idx_track_count ON medium (track_count); CREATE INDEX medium_index_idx ON medium_index USING gist (toc); +CREATE INDEX unreferenced_row_log_idx_inserted ON unreferenced_row_log USING BRIN (inserted); + CREATE UNIQUE INDEX url_idx_gid ON url (gid); CREATE UNIQUE INDEX url_idx_url ON url (url); diff --git a/mbdata/sql/CreatePrimaryKeys.sql b/mbdata/sql/CreatePrimaryKeys.sql index 1242b32..8724bab 100644 --- a/mbdata/sql/CreatePrimaryKeys.sql +++ b/mbdata/sql/CreatePrimaryKeys.sql @@ -54,6 +54,7 @@ ALTER TABLE edit_instrument ADD CONSTRAINT edit_instrument_pkey PRIMARY KEY (edi ALTER TABLE edit_label ADD CONSTRAINT edit_label_pkey PRIMARY KEY (edit, label); ALTER TABLE edit_mood ADD CONSTRAINT edit_mood_pkey PRIMARY KEY (edit, mood); ALTER TABLE edit_note ADD CONSTRAINT edit_note_pkey PRIMARY KEY (id); +ALTER TABLE edit_note_change ADD CONSTRAINT edit_note_change_pkey PRIMARY KEY (id); ALTER TABLE edit_note_recipient ADD CONSTRAINT edit_note_recipient_pkey PRIMARY KEY (recipient, edit_note); ALTER TABLE edit_place ADD CONSTRAINT edit_place_pkey PRIMARY KEY (edit, place); ALTER TABLE edit_recording ADD CONSTRAINT edit_recording_pkey PRIMARY KEY (edit, recording); @@ -69,6 +70,7 @@ ALTER TABLE editor_collection_artist ADD CONSTRAINT editor_collection_artist_pke ALTER TABLE editor_collection_collaborator ADD CONSTRAINT editor_collection_collaborator_pkey PRIMARY KEY (collection, editor); ALTER TABLE editor_collection_deleted_entity ADD CONSTRAINT editor_collection_deleted_entity_pkey PRIMARY KEY (collection, gid); ALTER TABLE editor_collection_event ADD CONSTRAINT editor_collection_event_pkey PRIMARY KEY (collection, event); +ALTER TABLE editor_collection_genre ADD CONSTRAINT editor_collection_genre_pkey PRIMARY KEY (collection, genre); ALTER TABLE editor_collection_gid_redirect ADD CONSTRAINT editor_collection_gid_redirect_pkey PRIMARY KEY (gid); ALTER TABLE editor_collection_instrument ADD CONSTRAINT editor_collection_instrument_pkey PRIMARY KEY (collection, instrument); ALTER TABLE editor_collection_label ADD CONSTRAINT editor_collection_label_pkey PRIMARY KEY (collection, label); @@ -90,10 +92,6 @@ ALTER TABLE editor_subscribe_label ADD CONSTRAINT editor_subscribe_label_pkey PR ALTER TABLE editor_subscribe_label_deleted ADD CONSTRAINT editor_subscribe_label_deleted_pkey PRIMARY KEY (editor, gid); ALTER TABLE editor_subscribe_series ADD CONSTRAINT editor_subscribe_series_pkey PRIMARY KEY (id); ALTER TABLE editor_subscribe_series_deleted ADD CONSTRAINT editor_subscribe_series_deleted_pkey PRIMARY KEY (editor, gid); -ALTER TABLE editor_watch_artist ADD CONSTRAINT editor_watch_artist_pkey PRIMARY KEY (artist, editor); -ALTER TABLE editor_watch_preferences ADD CONSTRAINT editor_watch_preferences_pkey PRIMARY KEY (editor); -ALTER TABLE editor_watch_release_group_type ADD CONSTRAINT editor_watch_release_group_type_pkey PRIMARY KEY (editor, release_group_type); -ALTER TABLE editor_watch_release_status ADD CONSTRAINT editor_watch_release_status_pkey PRIMARY KEY (editor, release_status); ALTER TABLE event ADD CONSTRAINT event_pkey PRIMARY KEY (id); ALTER TABLE event_alias ADD CONSTRAINT event_alias_pkey PRIMARY KEY (id); ALTER TABLE event_alias_type ADD CONSTRAINT event_alias_type_pkey PRIMARY KEY (id); @@ -350,6 +348,7 @@ ALTER TABLE tag_relation ADD CONSTRAINT tag_relation_pkey PRIMARY KEY (tag1, tag ALTER TABLE track ADD CONSTRAINT track_pkey PRIMARY KEY (id); ALTER TABLE track_gid_redirect ADD CONSTRAINT track_gid_redirect_pkey PRIMARY KEY (gid); ALTER TABLE track_raw ADD CONSTRAINT track_raw_pkey PRIMARY KEY (id); +ALTER TABLE unreferenced_row_log ADD CONSTRAINT unreferenced_row_log_pkey PRIMARY KEY (table_name, row_id); ALTER TABLE url ADD CONSTRAINT url_pkey PRIMARY KEY (id); ALTER TABLE url_gid_redirect ADD CONSTRAINT url_gid_redirect_pkey PRIMARY KEY (gid); ALTER TABLE vote ADD CONSTRAINT vote_pkey PRIMARY KEY (id); diff --git a/mbdata/sql/CreateTables.sql b/mbdata/sql/CreateTables.sql index 30e3f70..7f3fabe 100644 --- a/mbdata/sql/CreateTables.sql +++ b/mbdata/sql/CreateTables.sql @@ -524,7 +524,6 @@ CREATE TABLE cdtoc ( -- replicate track_count INTEGER NOT NULL, leadout_offset INTEGER NOT NULL, track_offset INTEGER[] NOT NULL, - degraded BOOLEAN NOT NULL DEFAULT FALSE, created TIMESTAMP WITH TIME ZONE DEFAULT NOW() ); @@ -576,6 +575,18 @@ CREATE TABLE edit_note post_time TIMESTAMP WITH TIME ZONE DEFAULT NOW() ); +CREATE TABLE edit_note_change +( + id SERIAL, -- PK + status edit_note_status, + edit_note INTEGER NOT NULL, -- references edit_note.id + change_editor INTEGER NOT NULL, -- references editor.id + change_time TIMESTAMP WITH TIME ZONE DEFAULT NOW(), + old_note TEXT NOT NULL, + new_note TEXT NOT NULL, + reason TEXT NOT NULL DEFAULT '' +); + CREATE TABLE edit_note_recipient ( recipient INTEGER NOT NULL, -- PK, references editor.id edit_note INTEGER NOT NULL -- PK, references edit_note.id @@ -2456,7 +2467,7 @@ CREATE TABLE label ( -- replicate (verbose) end_date_year SMALLINT, end_date_month SMALLINT, end_date_day SMALLINT, - label_code INTEGER CHECK (label_code > 0 AND label_code < 100000), + label_code INTEGER, type INTEGER, -- references label_type.id area INTEGER, -- references area.id comment VARCHAR(255) NOT NULL DEFAULT '', @@ -2718,7 +2729,6 @@ CREATE TABLE link_type ( -- replicate link_phrase VARCHAR(255) NOT NULL, reverse_link_phrase VARCHAR(255) NOT NULL, long_link_phrase VARCHAR(255) NOT NULL, - priority INTEGER NOT NULL DEFAULT 0, last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), is_deprecated BOOLEAN NOT NULL DEFAULT false, has_dates BOOLEAN NOT NULL DEFAULT true, @@ -2790,6 +2800,14 @@ CREATE TABLE editor_collection_event ( comment TEXT DEFAULT '' NOT NULL ); +CREATE TABLE editor_collection_genre ( + collection INTEGER NOT NULL, -- PK, references editor_collection.id + genre INTEGER NOT NULL, -- PK, references genre.id + added TIMESTAMP WITH TIME ZONE DEFAULT NOW(), + position INTEGER NOT NULL DEFAULT 0 CHECK (position >= 0), + comment TEXT DEFAULT '' NOT NULL +); + CREATE TABLE editor_collection_instrument ( collection INTEGER NOT NULL, -- PK, references editor_collection.id instrument INTEGER NOT NULL, -- PK, references instrument.id @@ -2881,32 +2899,6 @@ CREATE TABLE editor_oauth_token ) ); -CREATE TABLE editor_watch_preferences -( - editor INTEGER NOT NULL, -- PK, references editor.id CASCADE - notify_via_email BOOLEAN NOT NULL DEFAULT TRUE, - notification_timeframe INTERVAL NOT NULL DEFAULT '1 week', - last_checked TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() -); - -CREATE TABLE editor_watch_artist -( - artist INTEGER NOT NULL, -- PK, references artist.id CASCADE - editor INTEGER NOT NULL -- PK, references editor.id CASCADE -); - -CREATE TABLE editor_watch_release_group_type -( - editor INTEGER NOT NULL, -- PK, references editor.id CASCADE - release_group_type INTEGER NOT NULL -- PK, references release_group_primary_type.id -); - -CREATE TABLE editor_watch_release_status -( - editor INTEGER NOT NULL, -- PK, references editor.id CASCADE - release_status INTEGER NOT NULL -- PK, references release_status.id -); - CREATE TABLE medium ( -- replicate (verbose) id SERIAL, release INTEGER NOT NULL, -- references release.id @@ -3890,6 +3882,12 @@ CREATE TABLE medium_index ( -- replicate toc CUBE ); +CREATE TABLE unreferenced_row_log ( + table_name VARCHAR NOT NULL, -- PK + row_id INTEGER NOT NULL, -- PK + inserted TIMESTAMP WITH TIME ZONE DEFAULT NOW() +); + CREATE TABLE url ( -- replicate id SERIAL, gid UUID NOT NULL, diff --git a/mbdata/sql/CreateTriggers.sql b/mbdata/sql/CreateTriggers.sql index 7bc0cb8..148c7f8 100644 --- a/mbdata/sql/CreateTriggers.sql +++ b/mbdata/sql/CreateTriggers.sql @@ -64,9 +64,6 @@ CREATE TRIGGER b_upd_artist_tag BEFORE UPDATE ON artist_tag CREATE TRIGGER b_upd_editor BEFORE UPDATE ON editor FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); -CREATE TRIGGER a_ins_editor AFTER INSERT ON editor - FOR EACH ROW EXECUTE PROCEDURE a_ins_editor(); - CREATE TRIGGER check_editor_name BEFORE UPDATE OR INSERT ON editor FOR EACH ROW EXECUTE PROCEDURE check_editor_name(); diff --git a/mbdata/sql/CreateTypes.sql b/mbdata/sql/CreateTypes.sql index 2f1d9f3..0017064 100644 --- a/mbdata/sql/CreateTypes.sql +++ b/mbdata/sql/CreateTypes.sql @@ -3,6 +3,8 @@ BEGIN; CREATE TYPE cover_art_presence AS ENUM ('absent', 'present', 'darkened'); +CREATE TYPE edit_note_status AS ENUM ('deleted', 'edited'); + CREATE TYPE event_art_presence AS ENUM ('absent', 'present', 'darkened'); CREATE TYPE fluency AS ENUM ( diff --git a/mbdata/sql/DropFKConstraints.sql b/mbdata/sql/DropFKConstraints.sql index 6106915..0d4eadf 100644 --- a/mbdata/sql/DropFKConstraints.sql +++ b/mbdata/sql/DropFKConstraints.sql @@ -98,6 +98,8 @@ ALTER TABLE edit_mood DROP CONSTRAINT IF EXISTS edit_mood_fk_edit; ALTER TABLE edit_mood DROP CONSTRAINT IF EXISTS edit_mood_fk_mood; ALTER TABLE edit_note DROP CONSTRAINT IF EXISTS edit_note_fk_editor; ALTER TABLE edit_note DROP CONSTRAINT IF EXISTS edit_note_fk_edit; +ALTER TABLE edit_note_change DROP CONSTRAINT IF EXISTS edit_note_change_fk_edit_note; +ALTER TABLE edit_note_change DROP CONSTRAINT IF EXISTS edit_note_change_fk_change_editor; ALTER TABLE edit_note_recipient DROP CONSTRAINT IF EXISTS edit_note_recipient_fk_recipient; ALTER TABLE edit_note_recipient DROP CONSTRAINT IF EXISTS edit_note_recipient_fk_edit_note; ALTER TABLE edit_place DROP CONSTRAINT IF EXISTS edit_place_fk_edit; @@ -128,6 +130,8 @@ ALTER TABLE editor_collection_deleted_entity DROP CONSTRAINT IF EXISTS editor_co ALTER TABLE editor_collection_deleted_entity DROP CONSTRAINT IF EXISTS editor_collection_deleted_entity_fk_gid; ALTER TABLE editor_collection_event DROP CONSTRAINT IF EXISTS editor_collection_event_fk_collection; ALTER TABLE editor_collection_event DROP CONSTRAINT IF EXISTS editor_collection_event_fk_event; +ALTER TABLE editor_collection_genre DROP CONSTRAINT IF EXISTS editor_collection_genre_fk_collection; +ALTER TABLE editor_collection_genre DROP CONSTRAINT IF EXISTS editor_collection_genre_fk_genre; ALTER TABLE editor_collection_gid_redirect DROP CONSTRAINT IF EXISTS editor_collection_gid_redirect_fk_new_id; ALTER TABLE editor_collection_instrument DROP CONSTRAINT IF EXISTS editor_collection_instrument_fk_collection; ALTER TABLE editor_collection_instrument DROP CONSTRAINT IF EXISTS editor_collection_instrument_fk_instrument; @@ -172,13 +176,6 @@ ALTER TABLE editor_subscribe_series DROP CONSTRAINT IF EXISTS editor_subscribe_s ALTER TABLE editor_subscribe_series_deleted DROP CONSTRAINT IF EXISTS editor_subscribe_series_deleted_fk_editor; ALTER TABLE editor_subscribe_series_deleted DROP CONSTRAINT IF EXISTS editor_subscribe_series_deleted_fk_gid; ALTER TABLE editor_subscribe_series_deleted DROP CONSTRAINT IF EXISTS editor_subscribe_series_deleted_fk_deleted_by; -ALTER TABLE editor_watch_artist DROP CONSTRAINT IF EXISTS editor_watch_artist_fk_artist; -ALTER TABLE editor_watch_artist DROP CONSTRAINT IF EXISTS editor_watch_artist_fk_editor; -ALTER TABLE editor_watch_preferences DROP CONSTRAINT IF EXISTS editor_watch_preferences_fk_editor; -ALTER TABLE editor_watch_release_group_type DROP CONSTRAINT IF EXISTS editor_watch_release_group_type_fk_editor; -ALTER TABLE editor_watch_release_group_type DROP CONSTRAINT IF EXISTS editor_watch_release_group_type_fk_release_group_type; -ALTER TABLE editor_watch_release_status DROP CONSTRAINT IF EXISTS editor_watch_release_status_fk_editor; -ALTER TABLE editor_watch_release_status DROP CONSTRAINT IF EXISTS editor_watch_release_status_fk_release_status; ALTER TABLE event DROP CONSTRAINT IF EXISTS event_fk_type; ALTER TABLE event_alias DROP CONSTRAINT IF EXISTS event_alias_fk_event; ALTER TABLE event_alias DROP CONSTRAINT IF EXISTS event_alias_fk_type; diff --git a/mbdata/sql/DropFunctions.sql b/mbdata/sql/DropFunctions.sql index ad6d583..e37ad16 100644 --- a/mbdata/sql/DropFunctions.sql +++ b/mbdata/sql/DropFunctions.sql @@ -17,7 +17,6 @@ DROP FUNCTION a_ins_alternative_medium_track(); DROP FUNCTION a_ins_alternative_release_or_track(); DROP FUNCTION a_ins_artist(); DROP FUNCTION a_ins_edit_note(); -DROP FUNCTION a_ins_editor(); DROP FUNCTION a_ins_event(); DROP FUNCTION a_ins_instrument(); DROP FUNCTION a_ins_l_area_area_mirror(); diff --git a/mbdata/sql/DropIndexes.sql b/mbdata/sql/DropIndexes.sql index e73d78f..4e83c1e 100644 --- a/mbdata/sql/DropIndexes.sql +++ b/mbdata/sql/DropIndexes.sql @@ -84,6 +84,7 @@ DROP INDEX edit_instrument_idx; DROP INDEX edit_label_idx; DROP INDEX edit_label_idx_status; DROP INDEX edit_mood_idx; +DROP INDEX edit_note_change_idx_edit_note; DROP INDEX edit_note_idx_edit; DROP INDEX edit_note_idx_editor; DROP INDEX edit_note_recipient_idx_recipient; @@ -506,6 +507,7 @@ DROP INDEX track_idx_artist_credit; DROP INDEX track_idx_gid; DROP INDEX track_idx_recording; DROP INDEX track_raw_idx_release; +DROP INDEX unreferenced_row_log_idx_inserted; DROP INDEX url_gid_redirect_idx_new_id; DROP INDEX url_idx_gid; DROP INDEX url_idx_url; diff --git a/mbdata/sql/DropPrimaryKeys.sql b/mbdata/sql/DropPrimaryKeys.sql index 48bad50..b16b198 100644 --- a/mbdata/sql/DropPrimaryKeys.sql +++ b/mbdata/sql/DropPrimaryKeys.sql @@ -54,6 +54,7 @@ ALTER TABLE edit_instrument DROP CONSTRAINT IF EXISTS edit_instrument_pkey; ALTER TABLE edit_label DROP CONSTRAINT IF EXISTS edit_label_pkey; ALTER TABLE edit_mood DROP CONSTRAINT IF EXISTS edit_mood_pkey; ALTER TABLE edit_note DROP CONSTRAINT IF EXISTS edit_note_pkey; +ALTER TABLE edit_note_change DROP CONSTRAINT IF EXISTS edit_note_change_pkey; ALTER TABLE edit_note_recipient DROP CONSTRAINT IF EXISTS edit_note_recipient_pkey; ALTER TABLE edit_place DROP CONSTRAINT IF EXISTS edit_place_pkey; ALTER TABLE edit_recording DROP CONSTRAINT IF EXISTS edit_recording_pkey; @@ -69,6 +70,7 @@ ALTER TABLE editor_collection_artist DROP CONSTRAINT IF EXISTS editor_collection ALTER TABLE editor_collection_collaborator DROP CONSTRAINT IF EXISTS editor_collection_collaborator_pkey; ALTER TABLE editor_collection_deleted_entity DROP CONSTRAINT IF EXISTS editor_collection_deleted_entity_pkey; ALTER TABLE editor_collection_event DROP CONSTRAINT IF EXISTS editor_collection_event_pkey; +ALTER TABLE editor_collection_genre DROP CONSTRAINT IF EXISTS editor_collection_genre_pkey; ALTER TABLE editor_collection_gid_redirect DROP CONSTRAINT IF EXISTS editor_collection_gid_redirect_pkey; ALTER TABLE editor_collection_instrument DROP CONSTRAINT IF EXISTS editor_collection_instrument_pkey; ALTER TABLE editor_collection_label DROP CONSTRAINT IF EXISTS editor_collection_label_pkey; @@ -90,10 +92,6 @@ ALTER TABLE editor_subscribe_label DROP CONSTRAINT IF EXISTS editor_subscribe_la ALTER TABLE editor_subscribe_label_deleted DROP CONSTRAINT IF EXISTS editor_subscribe_label_deleted_pkey; ALTER TABLE editor_subscribe_series DROP CONSTRAINT IF EXISTS editor_subscribe_series_pkey; ALTER TABLE editor_subscribe_series_deleted DROP CONSTRAINT IF EXISTS editor_subscribe_series_deleted_pkey; -ALTER TABLE editor_watch_artist DROP CONSTRAINT IF EXISTS editor_watch_artist_pkey; -ALTER TABLE editor_watch_preferences DROP CONSTRAINT IF EXISTS editor_watch_preferences_pkey; -ALTER TABLE editor_watch_release_group_type DROP CONSTRAINT IF EXISTS editor_watch_release_group_type_pkey; -ALTER TABLE editor_watch_release_status DROP CONSTRAINT IF EXISTS editor_watch_release_status_pkey; ALTER TABLE event DROP CONSTRAINT IF EXISTS event_pkey; ALTER TABLE event_alias DROP CONSTRAINT IF EXISTS event_alias_pkey; ALTER TABLE event_alias_type DROP CONSTRAINT IF EXISTS event_alias_type_pkey; @@ -350,6 +348,7 @@ ALTER TABLE tag_relation DROP CONSTRAINT IF EXISTS tag_relation_pkey; ALTER TABLE track DROP CONSTRAINT IF EXISTS track_pkey; ALTER TABLE track_gid_redirect DROP CONSTRAINT IF EXISTS track_gid_redirect_pkey; ALTER TABLE track_raw DROP CONSTRAINT IF EXISTS track_raw_pkey; +ALTER TABLE unreferenced_row_log DROP CONSTRAINT IF EXISTS unreferenced_row_log_pkey; ALTER TABLE url DROP CONSTRAINT IF EXISTS url_pkey; ALTER TABLE url_gid_redirect DROP CONSTRAINT IF EXISTS url_gid_redirect_pkey; ALTER TABLE vote DROP CONSTRAINT IF EXISTS vote_pkey; diff --git a/mbdata/sql/DropTables.sql b/mbdata/sql/DropTables.sql index af0ec88..8eb5357 100644 --- a/mbdata/sql/DropTables.sql +++ b/mbdata/sql/DropTables.sql @@ -58,6 +58,7 @@ DROP TABLE edit_instrument; DROP TABLE edit_label; DROP TABLE edit_mood; DROP TABLE edit_note; +DROP TABLE edit_note_change; DROP TABLE edit_note_recipient; DROP TABLE edit_place; DROP TABLE edit_recording; @@ -73,6 +74,7 @@ DROP TABLE editor_collection_artist; DROP TABLE editor_collection_collaborator; DROP TABLE editor_collection_deleted_entity; DROP TABLE editor_collection_event; +DROP TABLE editor_collection_genre; DROP TABLE editor_collection_gid_redirect; DROP TABLE editor_collection_instrument; DROP TABLE editor_collection_label; @@ -94,10 +96,6 @@ DROP TABLE editor_subscribe_label; DROP TABLE editor_subscribe_label_deleted; DROP TABLE editor_subscribe_series; DROP TABLE editor_subscribe_series_deleted; -DROP TABLE editor_watch_artist; -DROP TABLE editor_watch_preferences; -DROP TABLE editor_watch_release_group_type; -DROP TABLE editor_watch_release_status; DROP TABLE event; DROP TABLE event_alias; DROP TABLE event_alias_type; @@ -355,6 +353,7 @@ DROP TABLE tag_relation; DROP TABLE track; DROP TABLE track_gid_redirect; DROP TABLE track_raw; +DROP TABLE unreferenced_row_log; DROP TABLE url; DROP TABLE url_gid_redirect; DROP TABLE vote; diff --git a/mbdata/sql/DropTriggers.sql b/mbdata/sql/DropTriggers.sql index b781c53..17e54e9 100644 --- a/mbdata/sql/DropTriggers.sql +++ b/mbdata/sql/DropTriggers.sql @@ -22,7 +22,6 @@ DROP TRIGGER IF EXISTS restore_collection_sub_on_public ON editor_collection; DROP TRIGGER IF EXISTS search_hint ON artist_alias; DROP TRIGGER IF EXISTS b_upd_artist_tag ON artist_tag; DROP TRIGGER IF EXISTS b_upd_editor ON editor; -DROP TRIGGER IF EXISTS a_ins_editor ON editor; DROP TRIGGER IF EXISTS check_editor_name ON editor; DROP TRIGGER IF EXISTS a_ins_event ON event; DROP TRIGGER IF EXISTS b_upd_event ON event; diff --git a/mbdata/sql/DropTypes.sql b/mbdata/sql/DropTypes.sql index 6ae9a9a..b4c83ae 100644 --- a/mbdata/sql/DropTypes.sql +++ b/mbdata/sql/DropTypes.sql @@ -2,6 +2,7 @@ \unset ON_ERROR_STOP DROP TYPE IF EXISTS cover_art_presence; +DROP TYPE IF EXISTS edit_note_status; DROP TYPE IF EXISTS event_art_presence; DROP TYPE IF EXISTS fluency; DROP TYPE IF EXISTS oauth_code_challenge_method; diff --git a/mbdata/sql/InsertTestData.sql b/mbdata/sql/InsertTestData.sql index 4938e39..0fecd6c 100644 --- a/mbdata/sql/InsertTestData.sql +++ b/mbdata/sql/InsertTestData.sql @@ -48,8 +48,8 @@ INSERT INTO artist_credit_name (artist_credit, position, artist, name) VALUES (2 INSERT INTO recording (id, gid, name, artist_credit, length) VALUES (1, '123c079d-374e-4436-9448-da92dedef3ce', 'Dancing Queen', 2, 123456); -INSERT INTO release_group (id, gid, name, artist_credit, type) VALUES - (1, '234c079d-374e-4436-9448-da92dedef3ce', 'Arrival', 2, 1); +INSERT INTO release_group (id, gid, name, artist_credit, type, last_updated) VALUES + (1, '234c079d-374e-4436-9448-da92dedef3ce', 'Arrival', 2, 1, '2003-03-03'); -- Test multiple release groups on a page INSERT INTO artist_credit (id, name, artist_count, gid) VALUES (4, 'Test Artist', 1, '261f02c2-75a6-313f-9dd8-1716f73f3ce8'); @@ -61,12 +61,12 @@ INSERT INTO release_group (id, gid, name, artist_credit, type) VALUES INSERT INTO release_group (id, gid, name, artist_credit, type) VALUES (4, '7348f3a0-454e-11de-8a39-0800200c9a66', 'Test RG 2', 4, 1); -INSERT INTO release_group_alias (id, name, sort_name, release_group, edits_pending) - VALUES (1, 'Test RG 1 Alias 1', 'Test RG 1 Alias Sort Name 1', 3, 0), - (2, 'Test RG 1 Alias 2', 'Test RG 1 Alias Sort Name 2', 3, 0); +INSERT INTO release_group_alias (id, name, sort_name, release_group, type, edits_pending) + VALUES (1, 'Test RG 1 Alias 1', 'Test RG 1 Alias Sort Name 1', 3, 1, 0), + (2, 'Test RG 1 Alias 2', 'Test RG 1 Alias Sort Name 2', 3, 2, 0); -INSERT INTO work (id, gid, name, type) VALUES - (1, '745c079d-374e-4436-9448-da92dedef3ce', 'Dancing Queen', 1); +INSERT INTO work (id, gid, name, type, last_updated) VALUES + (1, '745c079d-374e-4436-9448-da92dedef3ce', 'Dancing Queen', 1, '1999-01-02 12:00'); INSERT INTO iswc (work, iswc) VALUES (1, 'T-000.000.001-0'); -- Special Labels @@ -75,9 +75,11 @@ INSERT INTO label (id, gid, name, type) VALUES INSERT INTO label (id, gid, name, type, area, label_code, begin_date_year, begin_date_month, begin_date_day, - end_date_year, end_date_month, end_date_day, comment) + end_date_year, end_date_month, end_date_day, comment, + last_updated) VALUES (2, '46f0f4cd-8aab-4b33-b698-f459faf64190', 'Warp Records', 4, 221, 2070, - 1989, 02, 03, 2008, 05, 19, 'Sheffield based electronica label'); + 1989, 02, 03, 2008, 05, 19, 'Sheffield based electronica label', + '2014-01-12 18:00:27.843631-06'); -- recording contract relationships for Warp Records INSERT INTO link (attribute_count, begin_date_day, begin_date_month, begin_date_year, created, end_date_day, end_date_month, end_date_year, ended, id, link_type) VALUES @@ -140,11 +142,11 @@ INSERT INTO artist_credit_name (artist_credit, position, artist, name) VALUES (3 INSERT INTO release_group (id, gid, name, artist_credit, type) VALUES (2, '7c3218d7-75e0-4e8c-971f-f097b6c308c5', 'Aerial', 3, 1); -INSERT INTO release (id, gid, name, artist_credit, release_group, status, barcode) VALUES (2, 'f205627f-b70a-409d-adbe-66289b614e80', 'Aerial', 3, 2, 1, '0094634396028'); +INSERT INTO release (id, gid, name, artist_credit, release_group, status, barcode, last_updated) VALUES (2, 'f205627f-b70a-409d-adbe-66289b614e80', 'Aerial', 3, 2, 1, '0094634396028', '2020-02-20'); INSERT INTO release_country (release, country, date_year, date_month, date_day) VALUES (2, 221, 2005, 11, 7); -INSERT INTO release_alias (id, name, sort_name, release, edits_pending) - VALUES (1, 'Ærial', 'Ærial', 2, 0); +INSERT INTO release_alias (id, name, sort_name, release, type, edits_pending) + VALUES (1, 'Ærial', 'Ærial', 2, 1, 0); INSERT INTO release (id, gid, name, artist_credit, release_group, status, barcode) VALUES (3, '9b3d9383-3d2a-417f-bfbb-56f7c15f075b', 'Aerial', 3, 2, 1, '0827969777220'); INSERT INTO release_country (release, country, date_year, date_month, date_day) VALUES (3, 222, 2005, 11, 8); @@ -161,8 +163,8 @@ INSERT INTO medium (id, release, position, format, name) VALUES (4, 2, 2, 1, 'A INSERT INTO medium (id, release, position, format, name) VALUES (5, 3, 1, 1, 'A Sea of Honey'); INSERT INTO medium (id, release, position, format, name) VALUES (6, 3, 2, 1, 'A Sky of Honey'); -INSERT INTO recording (id, gid, name, artist_credit, length) VALUES - (2, '54b9d183-7dab-42ba-94a3-7388a66604b8', 'King of the Mountain', 3, 293720); +INSERT INTO recording (id, gid, name, artist_credit, length, last_updated) VALUES + (2, '54b9d183-7dab-42ba-94a3-7388a66604b8', 'King of the Mountain', 3, 293720, '2020-02-20 19:00:00'); INSERT INTO recording (id, gid, name, artist_credit, length) VALUES (3, '659f405b-b4ee-4033-868a-0daa27784b89', 'π', 3, 369680); INSERT INTO recording (id, gid, name, artist_credit, length) VALUES @@ -195,8 +197,8 @@ INSERT INTO recording (id, gid, name, artist_credit, length) VALUES INSERT INTO recording (id, gid, name, artist_credit, length) VALUES (17, '1539ac10-5081-4469-b8f2-c5896132724e', 'Aerial', 3, 472880); -INSERT INTO recording_alias (id, name, sort_name, recording, edits_pending) - VALUES (1, 'King of the Mt.', 'King of the Mt.', 2, 0); +INSERT INTO recording_alias (id, name, sort_name, recording, type, edits_pending) + VALUES (1, 'King of the Mt.', 'King of the Mt.', 2, 1, 0); INSERT INTO track (id, gid, medium, position, number, recording, name, artist_credit, length) VALUES (4, '39164965-d4bd-49e6-925d-72026ad03dce', 3, 1, 1, 2, 'King of the Mountain', 3, 293720); INSERT INTO track (id, gid, medium, position, number, recording, name, artist_credit, length) VALUES (5, '82edb036-4097-484d-ac8a-cf4971451ca0', 3, 2, 2, 3, 'π', 3, 369680); @@ -251,6 +253,9 @@ INSERT INTO artist (id, gid, name, sort_name) INSERT INTO artist (id, gid, name, sort_name, comment) VALUES (9, '2fed031c-0e89-406e-b9f0-3d192637907a', 'Test Alias', 'Kate Bush', 'Second'); +INSERT INTO event (id, gid, name, begin_date_year, begin_date_month, begin_date_day, end_date_year, end_date_month, end_date_day, time, type, cancelled, setlist, comment, ended) + VALUES (59357, 'ca1d24c1-1999-46fd-8a95-3d4108df5cb2', 'BBC Open Music Prom', 2022, 9, 1, 2022, 9, 1, '19:30:00', 1, 'f', NULL, '2022, Prom 60', 't'); + INSERT INTO l_artist_recording (id, link, entity0, entity1) VALUES (1, 1, 8, 2); INSERT INTO l_artist_recording (id, link, entity0, entity1, edits_pending) VALUES (2, 1, 9, 2, 1); INSERT INTO l_artist_recording (id, link, entity0, entity1) VALUES (3, 2, 8, 3); diff --git a/mbdata/sql/SetSequences.sql b/mbdata/sql/SetSequences.sql index 44b7763..6aa8c87 100644 --- a/mbdata/sql/SetSequences.sql +++ b/mbdata/sql/SetSequences.sql @@ -28,6 +28,7 @@ SELECT setval('cdtoc_id_seq', COALESCE((SELECT MAX(id) FROM cdtoc), 0) + 1, FALS SELECT setval('cdtoc_raw_id_seq', COALESCE((SELECT MAX(id) FROM cdtoc_raw), 0) + 1, FALSE); SELECT setval('edit_id_seq', COALESCE((SELECT MAX(id) FROM edit), 0) + 1, FALSE); SELECT setval('edit_note_id_seq', COALESCE((SELECT MAX(id) FROM edit_note), 0) + 1, FALSE); +SELECT setval('edit_note_change_id_seq', COALESCE((SELECT MAX(id) FROM edit_note_change), 0) + 1, FALSE); SELECT setval('editor_id_seq', COALESCE((SELECT MAX(id) FROM editor), 0) + 1, FALSE); SELECT setval('editor_preference_id_seq', COALESCE((SELECT MAX(id) FROM editor_preference), 0) + 1, FALSE); SELECT setval('editor_subscribe_artist_id_seq', COALESCE((SELECT MAX(id) FROM editor_subscribe_artist), 0) + 1, FALSE); diff --git a/mbdata/sql/TruncateTables.sql b/mbdata/sql/TruncateTables.sql index e2d83b0..db1e112 100644 --- a/mbdata/sql/TruncateTables.sql +++ b/mbdata/sql/TruncateTables.sql @@ -58,6 +58,7 @@ TRUNCATE TABLE edit_instrument RESTART IDENTITY CASCADE; TRUNCATE TABLE edit_label RESTART IDENTITY CASCADE; TRUNCATE TABLE edit_mood RESTART IDENTITY CASCADE; TRUNCATE TABLE edit_note RESTART IDENTITY CASCADE; +TRUNCATE TABLE edit_note_change RESTART IDENTITY CASCADE; TRUNCATE TABLE edit_note_recipient RESTART IDENTITY CASCADE; TRUNCATE TABLE edit_place RESTART IDENTITY CASCADE; TRUNCATE TABLE edit_recording RESTART IDENTITY CASCADE; @@ -73,6 +74,7 @@ TRUNCATE TABLE editor_collection_artist RESTART IDENTITY CASCADE; TRUNCATE TABLE editor_collection_collaborator RESTART IDENTITY CASCADE; TRUNCATE TABLE editor_collection_deleted_entity RESTART IDENTITY CASCADE; TRUNCATE TABLE editor_collection_event RESTART IDENTITY CASCADE; +TRUNCATE TABLE editor_collection_genre RESTART IDENTITY CASCADE; TRUNCATE TABLE editor_collection_gid_redirect RESTART IDENTITY CASCADE; TRUNCATE TABLE editor_collection_instrument RESTART IDENTITY CASCADE; TRUNCATE TABLE editor_collection_label RESTART IDENTITY CASCADE; @@ -94,10 +96,6 @@ TRUNCATE TABLE editor_subscribe_label RESTART IDENTITY CASCADE; TRUNCATE TABLE editor_subscribe_label_deleted RESTART IDENTITY CASCADE; TRUNCATE TABLE editor_subscribe_series RESTART IDENTITY CASCADE; TRUNCATE TABLE editor_subscribe_series_deleted RESTART IDENTITY CASCADE; -TRUNCATE TABLE editor_watch_artist RESTART IDENTITY CASCADE; -TRUNCATE TABLE editor_watch_preferences RESTART IDENTITY CASCADE; -TRUNCATE TABLE editor_watch_release_group_type RESTART IDENTITY CASCADE; -TRUNCATE TABLE editor_watch_release_status RESTART IDENTITY CASCADE; TRUNCATE TABLE event RESTART IDENTITY CASCADE; TRUNCATE TABLE event_alias RESTART IDENTITY CASCADE; TRUNCATE TABLE event_alias_type RESTART IDENTITY CASCADE; @@ -355,6 +353,7 @@ TRUNCATE TABLE tag_relation RESTART IDENTITY CASCADE; TRUNCATE TABLE track RESTART IDENTITY CASCADE; TRUNCATE TABLE track_gid_redirect RESTART IDENTITY CASCADE; TRUNCATE TABLE track_raw RESTART IDENTITY CASCADE; +TRUNCATE TABLE unreferenced_row_log RESTART IDENTITY CASCADE; TRUNCATE TABLE url RESTART IDENTITY CASCADE; TRUNCATE TABLE url_gid_redirect RESTART IDENTITY CASCADE; TRUNCATE TABLE vote RESTART IDENTITY CASCADE; diff --git a/mbdata/sql/caa/CreateMQTriggers.sql b/mbdata/sql/caa/CreateMQTriggers.sql deleted file mode 100644 index b508800..0000000 --- a/mbdata/sql/caa/CreateMQTriggers.sql +++ /dev/null @@ -1,148 +0,0 @@ -BEGIN; - -SET search_path = 'cover_art_archive'; - -CREATE OR REPLACE FUNCTION reindex_release() RETURNS trigger AS $$ - DECLARE - release_mbid UUID; - BEGIN - SELECT gid INTO release_mbid - FROM musicbrainz.release r - JOIN cover_art_archive.cover_art caa_r ON r.id = caa_r.release - WHERE r.id = NEW.id; - - IF FOUND THEN - PERFORM amqp.publish(1, 'cover-art-archive', 'index', release_mbid::text); - END IF; - RETURN NULL; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE TRIGGER caa_reindex AFTER UPDATE OR INSERT -ON musicbrainz.release FOR EACH ROW -EXECUTE PROCEDURE reindex_release(); - -CREATE OR REPLACE FUNCTION reindex_artist() RETURNS trigger AS $$ - BEGIN - -- Short circuit if the name hasn't changed - IF NEW.name = OLD.name AND NEW.sort_name = OLD.sort_name THEN - RETURN NULL; - END IF; - - PERFORM amqp.publish(1, 'cover-art-archive', 'index', r.gid::text) - FROM musicbrainz.release r - JOIN cover_art_archive.cover_art caa_r ON r.id = caa_r.release - JOIN musicbrainz.artist_credit_name acn ON r.artist_credit = acn.artist_credit - WHERE acn.artist = NEW.id; - - RETURN NULL; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE TRIGGER caa_reindex AFTER UPDATE -ON musicbrainz.artist FOR EACH ROW -EXECUTE PROCEDURE reindex_artist(); - -CREATE OR REPLACE FUNCTION reindex_release_via_catno() RETURNS trigger AS $$ - DECLARE - release_mbid UUID; - BEGIN - SELECT gid INTO release_mbid - FROM musicbrainz.release - JOIN musicbrainz.release_label ON release_label.release = release.id - JOIN cover_art_archive.cover_art caa_r ON release.id = caa_r.release - WHERE release.id = NEW.release; - - IF FOUND THEN - PERFORM amqp.publish(1, 'cover-art-archive', 'index', release_mbid::text); - END IF; - RETURN NULL; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE TRIGGER caa_reindex AFTER UPDATE OR INSERT -ON musicbrainz.release_label FOR EACH ROW -EXECUTE PROCEDURE reindex_release_via_catno(); - -CREATE OR REPLACE FUNCTION reindex_caa() RETURNS trigger AS $$ - BEGIN - PERFORM amqp.publish(1, 'cover-art-archive', 'index', gid::text) - FROM musicbrainz.release - WHERE id = coalesce(( - CASE TG_OP - WHEN 'DELETE' THEN OLD.release - ELSE NEW.release - END)); - RETURN NULL; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE TRIGGER caa_reindex AFTER UPDATE OR INSERT OR DELETE -ON cover_art_archive.cover_art FOR EACH ROW -EXECUTE PROCEDURE reindex_caa(); - -CREATE OR REPLACE FUNCTION reindex_caa_type() RETURNS trigger AS $$ - BEGIN - PERFORM amqp.publish(1, 'cover-art-archive', 'index', r.gid::text) - FROM musicbrainz.release r - JOIN cover_art_archive.cover_art ca ON r.id = ca.release - WHERE ca.id = coalesce(( - CASE TG_OP - WHEN 'DELETE' THEN OLD.id - ELSE NEW.id - END)); - RETURN NULL; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE TRIGGER caa_reindex AFTER UPDATE OR INSERT OR DELETE -ON cover_art_archive.cover_art_type FOR EACH ROW -EXECUTE PROCEDURE reindex_caa_type(); - -CREATE OR REPLACE FUNCTION caa_move() RETURNS trigger AS $$ - BEGIN - IF OLD.release != NEW.release THEN - PERFORM amqp.publish(1, 'cover-art-archive', 'move', - (SELECT ca.id || E'\n' || - old_release.gid || E'\n' || - new_release.gid || E'\n' || - it.suffix || E'\n' - FROM cover_art_archive.cover_art ca - JOIN cover_art_archive.image_type it ON it.mime_type = ca.mime_type, - musicbrainz.release old_release, - musicbrainz.release new_release - WHERE ca.id = OLD.id - AND old_release.id = OLD.release - AND new_release.id = NEW.release)); - END IF; - RETURN NEW; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE TRIGGER caa_move BEFORE UPDATE -ON cover_art_archive.cover_art FOR EACH ROW -EXECUTE PROCEDURE caa_move(); - -CREATE OR REPLACE FUNCTION delete_release() RETURNS trigger AS $$ - BEGIN - PERFORM - amqp.publish(1, 'cover-art-archive', 'delete', - (cover_art.id || E'\n' || OLD.gid || E'\n' || image_type.suffix)::text) - FROM cover_art_archive.cover_art - JOIN cover_art_archive.image_type ON image_type.mime_type = cover_art.mime_type - WHERE release = OLD.id; - - PERFORM amqp.publish(1, 'cover-art-archive', 'delete', - ('index.json' || E'\n' || OLD.gid)::text) - FROM musicbrainz.release - WHERE release.id = OLD.id; - - RETURN OLD; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE TRIGGER caa_delete BEFORE DELETE -ON musicbrainz.release FOR EACH ROW -EXECUTE PROCEDURE delete_release(); - -COMMIT; diff --git a/mbdata/sql/caa/DropMQTriggers.sql b/mbdata/sql/caa/DropMQTriggers.sql deleted file mode 100644 index b6449b2..0000000 --- a/mbdata/sql/caa/DropMQTriggers.sql +++ /dev/null @@ -1,19 +0,0 @@ -BEGIN; - -DROP TRIGGER caa_reindex ON musicbrainz.artist; -DROP TRIGGER caa_reindex ON musicbrainz.release; -DROP TRIGGER caa_reindex ON musicbrainz.release_label; -DROP TRIGGER caa_reindex ON cover_art_archive.cover_art; -DROP TRIGGER caa_reindex ON cover_art_archive.cover_art_type; -DROP TRIGGER caa_move ON cover_art_archive.cover_art; -DROP TRIGGER caa_delete ON musicbrainz.release; - -DROP FUNCTION cover_art_archive.reindex_release (); -DROP FUNCTION cover_art_archive.reindex_artist (); -DROP FUNCTION cover_art_archive.reindex_release_via_catno (); -DROP FUNCTION cover_art_archive.reindex_caa (); -DROP FUNCTION cover_art_archive.reindex_caa_type (); -DROP FUNCTION cover_art_archive.caa_move (); -DROP FUNCTION cover_art_archive.delete_release (); - -COMMIT; diff --git a/mbdata/sql/dbmirror2/MasterSetup.sql b/mbdata/sql/dbmirror2/MasterSetup.sql index c4fed3c..d4c6481 100644 --- a/mbdata/sql/dbmirror2/MasterSetup.sql +++ b/mbdata/sql/dbmirror2/MasterSetup.sql @@ -71,19 +71,6 @@ BEGIN pg_get_serial_sequence('dbmirror2.pending_data', 'seqid') ); - INSERT INTO dbmirror2.pending_keys (tablename, keys) - VALUES ( - _tablename, - ( - SELECT array_agg(column_name) - FROM dbmirror2.column_info - WHERE table_schema = TG_TABLE_SCHEMA - AND table_name = TG_TABLE_NAME - AND is_primary = TRUE - ) - ) - ON CONFLICT DO NOTHING; - INSERT INTO dbmirror2.pending_ts (xid, ts) VALUES (txid_current(), transaction_timestamp()) ON CONFLICT DO NOTHING; diff --git a/mbdata/sql/dbmirror2/README b/mbdata/sql/dbmirror2/README index 62b6330..1598c4a 100644 --- a/mbdata/sql/dbmirror2/README +++ b/mbdata/sql/dbmirror2/README @@ -1,5 +1,5 @@ ReplicationSetup.sql and MasterSetup.sql are copied from -https://github.com/metabrainz/dbmirror2, commit 7ba6422. (These are the only +https://github.com/metabrainz/dbmirror2, commit eda9923. (These are the only two files we need, and submodules are "difficult.") This is not a fork; please do not make any changes to the files here without diff --git a/mbdata/sql/eaa/CreateMQTriggers.sql b/mbdata/sql/eaa/CreateMQTriggers.sql deleted file mode 100644 index 4aee8d7..0000000 --- a/mbdata/sql/eaa/CreateMQTriggers.sql +++ /dev/null @@ -1,161 +0,0 @@ -BEGIN; - -SET search_path = 'event_art_archive'; - -CREATE OR REPLACE FUNCTION reindex_event() RETURNS trigger AS $$ - DECLARE - event_mbid UUID; - BEGIN - SELECT gid INTO event_mbid - FROM musicbrainz.event e - JOIN event_art_archive.event_art ea ON e.id = ea.event - WHERE e.id = NEW.id; - - IF FOUND THEN - PERFORM amqp.publish(1, 'event-art-archive', 'index', event_mbid::text); - END IF; - RETURN NULL; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE TRIGGER eaa_reindex AFTER UPDATE OR INSERT -ON musicbrainz.event FOR EACH ROW -EXECUTE PROCEDURE reindex_event(); - -CREATE OR REPLACE FUNCTION reindex_artist() RETURNS trigger AS $$ - BEGIN - -- Short circuit if the name hasn't changed - IF NEW.name = OLD.name AND NEW.sort_name = OLD.sort_name THEN - RETURN NULL; - END IF; - - PERFORM amqp.publish(1, 'event-art-archive', 'index', e.gid::text) - FROM musicbrainz.event e - JOIN event_art_archive.event_art ea ON e.id = ea.event - JOIN musicbrainz.l_artist_event lae ON e.id = lae.entity1 - WHERE lae.entity0 = NEW.id; - - RETURN NULL; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE TRIGGER eaa_reindex AFTER UPDATE -ON musicbrainz.artist FOR EACH ROW -EXECUTE PROCEDURE reindex_artist(); - -CREATE OR REPLACE FUNCTION reindex_l_artist_event() RETURNS trigger AS $$ - BEGIN - PERFORM amqp.publish(1, 'event-art-archive', 'index', e.gid::text) - FROM musicbrainz.event e - JOIN event_art_archive.event_art ea ON e.id = ea.event - JOIN musicbrainz.l_artist_event lae ON e.id = lae.entity1 - WHERE lae.id = (CASE TG_OP - WHEN 'DELETE' THEN OLD.id - ELSE NEW.id - END); - RETURN NULL; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE TRIGGER eaa_reindex AFTER UPDATE OR INSERT OR DELETE -ON musicbrainz.l_artist_event FOR EACH ROW -EXECUTE PROCEDURE reindex_l_artist_event(); - -CREATE OR REPLACE FUNCTION reindex_place() RETURNS trigger AS $$ - BEGIN - PERFORM amqp.publish(1, 'event-art-archive', 'index', e.gid::text) - FROM musicbrainz.event e - JOIN event_art_archive.event_art ea ON e.id = ea.event - JOIN musicbrainz.l_event_place lep ON e.id = lep.entity0 - WHERE lep.entity1 = NEW.id; - - RETURN NULL; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE TRIGGER eaa_reindex AFTER UPDATE -ON musicbrainz.place FOR EACH ROW -EXECUTE PROCEDURE reindex_place(); - -CREATE OR REPLACE FUNCTION reindex_l_event_place() RETURNS trigger AS $$ - BEGIN - PERFORM amqp.publish(1, 'event-art-archive', 'index', e.gid::text) - FROM musicbrainz.event e - JOIN event_art_archive.event_art ea ON e.id = ea.event - JOIN musicbrainz.l_event_place lep ON e.id = lep.entity0 - WHERE lep.id = (CASE TG_OP - WHEN 'DELETE' THEN OLD.id - ELSE NEW.id - END); - RETURN NULL; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE TRIGGER eaa_reindex AFTER UPDATE OR INSERT OR DELETE -ON musicbrainz.l_event_place FOR EACH ROW -EXECUTE PROCEDURE reindex_l_event_place(); - -CREATE OR REPLACE FUNCTION reindex_eaa() RETURNS trigger AS $$ - BEGIN - PERFORM amqp.publish(1, 'event-art-archive', 'index', gid::text) - FROM musicbrainz.event - WHERE id = coalesce(( - CASE TG_OP - WHEN 'DELETE' THEN OLD.event - ELSE NEW.event - END)); - RETURN NULL; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE TRIGGER eaa_reindex AFTER UPDATE OR INSERT OR DELETE -ON event_art_archive.event_art FOR EACH ROW -EXECUTE PROCEDURE reindex_eaa(); - -CREATE OR REPLACE FUNCTION move_event() RETURNS trigger AS $$ - BEGIN - IF OLD.event != NEW.event THEN - PERFORM amqp.publish(1, 'event-art-archive', 'move', - (SELECT ea.id || E'\n' || - old_event.gid || E'\n' || - new_event.gid || E'\n' || - it.suffix || E'\n' - FROM event_art_archive.event_art ea - JOIN cover_art_archive.image_type it ON it.mime_type = ea.mime_type, - musicbrainz.event old_event, - musicbrainz.event new_event - WHERE ea.id = OLD.id - AND old_event.id = OLD.event - AND new_event.id = NEW.event)); - END IF; - RETURN NEW; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE TRIGGER eaa_move BEFORE UPDATE -ON event_art_archive.event_art FOR EACH ROW -EXECUTE PROCEDURE move_event(); - -CREATE OR REPLACE FUNCTION delete_event() RETURNS trigger AS $$ - BEGIN - PERFORM - amqp.publish(1, 'event-art-archive', 'delete', - (event_art.id || E'\n' || OLD.gid || E'\n' || image_type.suffix)::text) - FROM event_art_archive.event_art - JOIN cover_art_archive.image_type ON image_type.mime_type = event_art.mime_type - WHERE event = OLD.id; - - PERFORM amqp.publish(1, 'event-art-archive', 'delete', - ('index.json' || E'\n' || OLD.gid)::text) - FROM musicbrainz.event - WHERE event.id = OLD.id; - - RETURN OLD; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE TRIGGER eaa_delete BEFORE DELETE -ON musicbrainz.event FOR EACH ROW -EXECUTE PROCEDURE delete_event(); - -COMMIT; diff --git a/mbdata/sql/eaa/DropMQTriggers.sql b/mbdata/sql/eaa/DropMQTriggers.sql deleted file mode 100644 index 3651e68..0000000 --- a/mbdata/sql/eaa/DropMQTriggers.sql +++ /dev/null @@ -1,21 +0,0 @@ -BEGIN; - -DROP TRIGGER eaa_delete ON musicbrainz.event; -DROP TRIGGER eaa_move ON event_art_archive.event_art; -DROP TRIGGER eaa_reindex ON event_art_archive.event_art; -DROP TRIGGER eaa_reindex ON musicbrainz.artist; -DROP TRIGGER eaa_reindex ON musicbrainz.event; -DROP TRIGGER eaa_reindex ON musicbrainz.l_artist_event; -DROP TRIGGER eaa_reindex ON musicbrainz.l_event_place; -DROP TRIGGER eaa_reindex ON musicbrainz.place; - -DROP FUNCTION event_art_archive.delete_event (); -DROP FUNCTION event_art_archive.move_event (); -DROP FUNCTION event_art_archive.reindex_artist (); -DROP FUNCTION event_art_archive.reindex_eaa (); -DROP FUNCTION event_art_archive.reindex_event (); -DROP FUNCTION event_art_archive.reindex_l_artist_event (); -DROP FUNCTION event_art_archive.reindex_l_event_place (); -DROP FUNCTION event_art_archive.reindex_place (); - -COMMIT; diff --git a/mbdata/sql/updates/20130309-migrate-transclusion-table.pl b/mbdata/sql/updates/20130309-migrate-transclusion-table.pl index 4f1b6ea..7884e70 100755 --- a/mbdata/sql/updates/20130309-migrate-transclusion-table.pl +++ b/mbdata/sql/updates/20130309-migrate-transclusion-table.pl @@ -2,6 +2,7 @@ use strict; use warnings; +use English; use MusicBrainz::Server::Context; use DBDefs; @@ -33,10 +34,10 @@ sub _load_index_from_disk { my $index_file = DBDefs->STATIC_FILES_DIR . '/wikidocs/index.txt'; if (!open(FILE, "<" . $index_file)) { - warn "Could not open wikitrans index file '$index_file': $!."; + warn "Could not open wikitrans index file '$index_file': $OS_ERROR."; return {}; } - my $data = do { local $/; }; + my $data = do { local $INPUT_RECORD_SEPARATOR; }; close(FILE); return _parse_index($data); diff --git a/mbdata/sql/updates/20130313-bcrypt-passwords.pl b/mbdata/sql/updates/20130313-bcrypt-passwords.pl index 319c522..050c455 100755 --- a/mbdata/sql/updates/20130313-bcrypt-passwords.pl +++ b/mbdata/sql/updates/20130313-bcrypt-passwords.pl @@ -3,11 +3,12 @@ use Authen::Passphrase::BlowfishCrypt; use Authen::Passphrase::RejectAll; +use English; use MusicBrainz::Server::Context; use Sql; use Try::Tiny; -$| = 1; +$OUTPUT_AUTOFLUSH = 1; my $c = MusicBrainz::Server::Context->create_script_context; diff --git a/mbdata/sql/updates/20130322-init-bundled-replication.pl b/mbdata/sql/updates/20130322-init-bundled-replication.pl deleted file mode 100755 index 978f10b..0000000 --- a/mbdata/sql/updates/20130322-init-bundled-replication.pl +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -use DBDefs; -use MusicBrainz::Server::Context; - -my $c = MusicBrainz::Server::Context->create_script_context; - -my $replication_sequence = $c->sql->select_single_value('SELECT current_replication_sequence FROM replication_control'); -my $FTP_DATA_DIR = `grep FTP_DATA_DIR admin/config.sh`; -$FTP_DATA_DIR =~ s/^FTP_DATA_DIR=//; -chomp $FTP_DATA_DIR; - -system("./admin/replication/BundleReplicationPackets $FTP_DATA_DIR/replication --period daily --start $replication_sequence"); -system("./admin/replication/BundleReplicationPackets $FTP_DATA_DIR/replication --period weekly --start $replication_sequence"); diff --git a/mbdata/sql/updates/20130724-refresh-release_meta-asin.sql b/mbdata/sql/updates/20130724-refresh-release_meta-asin.sql index a140e6a..1859099 100644 --- a/mbdata/sql/updates/20130724-refresh-release_meta-asin.sql +++ b/mbdata/sql/updates/20130724-refresh-release_meta-asin.sql @@ -6,7 +6,7 @@ FROM ( FROM ( SELECT entity0 AS release, array_agg( - regexp_replace(url.url, E'^http://(?:www.)?(.*?)(?:\\:[0-9]+)?/.*/([0-9B][0-9A-Z]{9})(?:[^0-9A-Z]|$)', E'\\2') + regexp_replace(url.url, E'^https?://(?:www.)?(.*?)(?:\\:[0-9]+)?/.*/([0-9B][0-9A-Z]{9})(?:[^0-9A-Z]|$)', E'\\2') ORDER BY l_release_url.last_updated DESC ) asins FROM l_release_url diff --git a/mbdata/sql/updates/20130906-materialise-recording-lengths.pl b/mbdata/sql/updates/20130906-materialise-recording-lengths.pl index 0509c69..71e1ef1 100755 --- a/mbdata/sql/updates/20130906-materialise-recording-lengths.pl +++ b/mbdata/sql/updates/20130906-materialise-recording-lengths.pl @@ -1,10 +1,11 @@ use strict; use warnings; +use English; use MusicBrainz::Server::Context; use Sql; -$| = 1; +$OUTPUT_AUTOFLUSH = 1; my $c = MusicBrainz::Server::Context->create_script_context; my $i = 0; diff --git a/mbdata/sql/updates/20220207-mbs-12224-mirror.sql b/mbdata/sql/updates/20220207-mbs-12224-mirror.sql index 7b5c2fa..651622f 100644 --- a/mbdata/sql/updates/20220207-mbs-12224-mirror.sql +++ b/mbdata/sql/updates/20220207-mbs-12224-mirror.sql @@ -2,168 +2,6 @@ BEGIN; -DELETE FROM area_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM area_tag_raw r - WHERE r.area = a.area AND r.tag = a.tag -); - -UPDATE area_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM area_tag_raw r - WHERE r.area = a.area AND r.tag = a.tag - GROUP BY r.area, r.tag -); - -DELETE FROM artist_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM artist_tag_raw r - WHERE r.artist = a.artist AND r.tag = a.tag -); - -UPDATE artist_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM artist_tag_raw r - WHERE r.artist = a.artist AND r.tag = a.tag - GROUP BY r.artist, r.tag -); - -DELETE FROM event_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM event_tag_raw r - WHERE r.event = a.event AND r.tag = a.tag -); - -UPDATE event_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM event_tag_raw r - WHERE r.event = a.event AND r.tag = a.tag - GROUP BY r.event, r.tag -); - -DELETE FROM instrument_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM instrument_tag_raw r - WHERE r.instrument = a.instrument AND r.tag = a.tag -); - -UPDATE instrument_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM instrument_tag_raw r - WHERE r.instrument = a.instrument AND r.tag = a.tag - GROUP BY r.instrument, r.tag -); - -DELETE FROM label_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM label_tag_raw r - WHERE r.label = a.label AND r.tag = a.tag -); - -UPDATE label_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM label_tag_raw r - WHERE r.label = a.label AND r.tag = a.tag - GROUP BY r.label, r.tag -); - -DELETE FROM place_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM place_tag_raw r - WHERE r.place = a.place AND r.tag = a.tag -); - -UPDATE place_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM place_tag_raw r - WHERE r.place = a.place AND r.tag = a.tag - GROUP BY r.place, r.tag -); - -DELETE FROM recording_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM recording_tag_raw r - WHERE r.recording = a.recording AND r.tag = a.tag -); - -UPDATE recording_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM recording_tag_raw r - WHERE r.recording = a.recording AND r.tag = a.tag - GROUP BY r.recording, r.tag -); - -DELETE FROM release_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM release_tag_raw r - WHERE r.release = a.release AND r.tag = a.tag -); - -UPDATE release_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM release_tag_raw r - WHERE r.release = a.release AND r.tag = a.tag - GROUP BY r.release, r.tag -); - -DELETE FROM release_group_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM release_group_tag_raw r - WHERE r.release_group = a.release_group AND r.tag = a.tag -); - -UPDATE release_group_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM release_group_tag_raw r - WHERE r.release_group = a.release_group AND r.tag = a.tag - GROUP BY r.release_group, r.tag -); - -DELETE FROM series_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM series_tag_raw r - WHERE r.series = a.series AND r.tag = a.tag -); - -UPDATE series_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM series_tag_raw r - WHERE r.series = a.series AND r.tag = a.tag - GROUP BY r.series, r.tag -); - -DELETE FROM work_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM work_tag_raw r - WHERE r.work = a.work AND r.tag = a.tag -); - -UPDATE work_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM work_tag_raw r - WHERE r.work = a.work AND r.tag = a.tag - GROUP BY r.work, r.tag -); - -UPDATE tag t SET ref_count = ( - (SELECT count(*) FROM area_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM artist_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM event_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM instrument_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM label_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM place_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM recording_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM release_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM release_group_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM series_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM work_tag_raw r WHERE r.tag = t.id) -); - --- Unused, non-replicated table that holds FKs to tag. -TRUNCATE tag_relation; - -DELETE FROM tag WHERE ref_count = 0; - CREATE TYPE taggable_entity_type AS ENUM ( 'area', 'artist', diff --git a/mbdata/sql/updates/20220207-mbs-12224-standalone.sql b/mbdata/sql/updates/20220207-mbs-12224-standalone.sql index 0fd2878..4eded9e 100644 --- a/mbdata/sql/updates/20220207-mbs-12224-standalone.sql +++ b/mbdata/sql/updates/20220207-mbs-12224-standalone.sql @@ -2,6 +2,168 @@ BEGIN; +DELETE FROM area_tag a WHERE NOT EXISTS ( + SELECT 1 + FROM area_tag_raw r + WHERE r.area = a.area AND r.tag = a.tag +); + +UPDATE area_tag a SET count = ( + SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) + FROM area_tag_raw r + WHERE r.area = a.area AND r.tag = a.tag + GROUP BY r.area, r.tag +); + +DELETE FROM artist_tag a WHERE NOT EXISTS ( + SELECT 1 + FROM artist_tag_raw r + WHERE r.artist = a.artist AND r.tag = a.tag +); + +UPDATE artist_tag a SET count = ( + SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) + FROM artist_tag_raw r + WHERE r.artist = a.artist AND r.tag = a.tag + GROUP BY r.artist, r.tag +); + +DELETE FROM event_tag a WHERE NOT EXISTS ( + SELECT 1 + FROM event_tag_raw r + WHERE r.event = a.event AND r.tag = a.tag +); + +UPDATE event_tag a SET count = ( + SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) + FROM event_tag_raw r + WHERE r.event = a.event AND r.tag = a.tag + GROUP BY r.event, r.tag +); + +DELETE FROM instrument_tag a WHERE NOT EXISTS ( + SELECT 1 + FROM instrument_tag_raw r + WHERE r.instrument = a.instrument AND r.tag = a.tag +); + +UPDATE instrument_tag a SET count = ( + SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) + FROM instrument_tag_raw r + WHERE r.instrument = a.instrument AND r.tag = a.tag + GROUP BY r.instrument, r.tag +); + +DELETE FROM label_tag a WHERE NOT EXISTS ( + SELECT 1 + FROM label_tag_raw r + WHERE r.label = a.label AND r.tag = a.tag +); + +UPDATE label_tag a SET count = ( + SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) + FROM label_tag_raw r + WHERE r.label = a.label AND r.tag = a.tag + GROUP BY r.label, r.tag +); + +DELETE FROM place_tag a WHERE NOT EXISTS ( + SELECT 1 + FROM place_tag_raw r + WHERE r.place = a.place AND r.tag = a.tag +); + +UPDATE place_tag a SET count = ( + SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) + FROM place_tag_raw r + WHERE r.place = a.place AND r.tag = a.tag + GROUP BY r.place, r.tag +); + +DELETE FROM recording_tag a WHERE NOT EXISTS ( + SELECT 1 + FROM recording_tag_raw r + WHERE r.recording = a.recording AND r.tag = a.tag +); + +UPDATE recording_tag a SET count = ( + SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) + FROM recording_tag_raw r + WHERE r.recording = a.recording AND r.tag = a.tag + GROUP BY r.recording, r.tag +); + +DELETE FROM release_tag a WHERE NOT EXISTS ( + SELECT 1 + FROM release_tag_raw r + WHERE r.release = a.release AND r.tag = a.tag +); + +UPDATE release_tag a SET count = ( + SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) + FROM release_tag_raw r + WHERE r.release = a.release AND r.tag = a.tag + GROUP BY r.release, r.tag +); + +DELETE FROM release_group_tag a WHERE NOT EXISTS ( + SELECT 1 + FROM release_group_tag_raw r + WHERE r.release_group = a.release_group AND r.tag = a.tag +); + +UPDATE release_group_tag a SET count = ( + SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) + FROM release_group_tag_raw r + WHERE r.release_group = a.release_group AND r.tag = a.tag + GROUP BY r.release_group, r.tag +); + +DELETE FROM series_tag a WHERE NOT EXISTS ( + SELECT 1 + FROM series_tag_raw r + WHERE r.series = a.series AND r.tag = a.tag +); + +UPDATE series_tag a SET count = ( + SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) + FROM series_tag_raw r + WHERE r.series = a.series AND r.tag = a.tag + GROUP BY r.series, r.tag +); + +DELETE FROM work_tag a WHERE NOT EXISTS ( + SELECT 1 + FROM work_tag_raw r + WHERE r.work = a.work AND r.tag = a.tag +); + +UPDATE work_tag a SET count = ( + SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) + FROM work_tag_raw r + WHERE r.work = a.work AND r.tag = a.tag + GROUP BY r.work, r.tag +); + +UPDATE tag t SET ref_count = ( + (SELECT count(*) FROM area_tag_raw r WHERE r.tag = t.id) + + (SELECT count(*) FROM artist_tag_raw r WHERE r.tag = t.id) + + (SELECT count(*) FROM event_tag_raw r WHERE r.tag = t.id) + + (SELECT count(*) FROM instrument_tag_raw r WHERE r.tag = t.id) + + (SELECT count(*) FROM label_tag_raw r WHERE r.tag = t.id) + + (SELECT count(*) FROM place_tag_raw r WHERE r.tag = t.id) + + (SELECT count(*) FROM recording_tag_raw r WHERE r.tag = t.id) + + (SELECT count(*) FROM release_tag_raw r WHERE r.tag = t.id) + + (SELECT count(*) FROM release_group_tag_raw r WHERE r.tag = t.id) + + (SELECT count(*) FROM series_tag_raw r WHERE r.tag = t.id) + + (SELECT count(*) FROM work_tag_raw r WHERE r.tag = t.id) +); + +-- Unused, non-replicated table that holds FKs to tag. +TRUNCATE tag_relation; + +DELETE FROM tag WHERE ref_count = 0; + CREATE TRIGGER update_counts_for_insert AFTER INSERT ON area_tag_raw FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_insert('area'); diff --git a/mbdata/sql/updates/schema-change/20.mirror.sql b/mbdata/sql/updates/schema-change/20.mirror.sql deleted file mode 100644 index e215ffc..0000000 --- a/mbdata/sql/updates/schema-change/20.mirror.sql +++ /dev/null @@ -1,1844 +0,0 @@ --- Generated by CompileSchemaScripts.pl from: --- 20140310-dates.sql --- 20140212-ordering-columns.sql --- 20140208-drop-script_language.sql --- 20140407-link-cardinality.sql --- 20140311-remove-area-sortnames.sql --- 20140313-remove-label-sortnames.sql --- 20140214-add-instruments.sql --- 20140215-add-instruments-documentation.sql --- 20140318-series.sql --- 20140418-series-instrument-functions.sql --- 20140429-area-view.sql -\set ON_ERROR_STOP 1 -BEGIN; -SET search_path = musicbrainz, public; -SET LOCAL statement_timeout = 0; --------------------------------------------------------------------------------- -SELECT '20140310-dates.sql'; - ------------------------ --- CREATE NEW COLUMN -- ------------------------ - -ALTER TABLE link_type ADD COLUMN has_dates BOOLEAN NOT NULL DEFAULT TRUE; - --------------------------------------------------------------------------------- -SELECT '20140212-ordering-columns.sql'; - - -ALTER TABLE area_alias_type ADD COLUMN parent INTEGER; -ALTER TABLE area_alias_type ADD COLUMN child_order INTEGER NOT NULL DEFAULT 0; -ALTER TABLE area_alias_type ADD COLUMN description TEXT; - -ALTER TABLE area_type ADD COLUMN parent INTEGER; -ALTER TABLE area_type ADD COLUMN child_order INTEGER NOT NULL DEFAULT 0; -ALTER TABLE area_type ADD COLUMN description TEXT; - -ALTER TABLE artist_type ADD COLUMN parent INTEGER; -ALTER TABLE artist_type ADD COLUMN child_order INTEGER NOT NULL DEFAULT 0; -ALTER TABLE artist_type ADD COLUMN description TEXT; - -ALTER TABLE artist_alias_type ADD COLUMN parent INTEGER; -ALTER TABLE artist_alias_type ADD COLUMN child_order INTEGER NOT NULL DEFAULT 0; -ALTER TABLE artist_alias_type ADD COLUMN description TEXT; - -ALTER TABLE gender ADD COLUMN parent INTEGER; -ALTER TABLE gender ADD COLUMN child_order INTEGER NOT NULL DEFAULT 0; -ALTER TABLE gender ADD COLUMN description TEXT; - -ALTER TABLE label_type ADD COLUMN parent INTEGER; -ALTER TABLE label_type ADD COLUMN child_order INTEGER NOT NULL DEFAULT 0; -ALTER TABLE label_type ADD COLUMN description TEXT; - -ALTER TABLE label_alias_type ADD COLUMN parent INTEGER; -ALTER TABLE label_alias_type ADD COLUMN child_order INTEGER NOT NULL DEFAULT 0; -ALTER TABLE label_alias_type ADD COLUMN description TEXT; - -ALTER TABLE medium_format ADD COLUMN description TEXT; - -ALTER TABLE place_type ADD COLUMN parent INTEGER; -ALTER TABLE place_type ADD COLUMN child_order INTEGER NOT NULL DEFAULT 0; -ALTER TABLE place_type ADD COLUMN description TEXT; - -ALTER TABLE place_alias_type ADD COLUMN parent INTEGER; -ALTER TABLE place_alias_type ADD COLUMN child_order INTEGER NOT NULL DEFAULT 0; -ALTER TABLE place_alias_type ADD COLUMN description TEXT; - -ALTER TABLE release_group_primary_type ADD COLUMN parent INTEGER; -ALTER TABLE release_group_primary_type ADD COLUMN child_order INTEGER NOT NULL DEFAULT 0; -ALTER TABLE release_group_primary_type ADD COLUMN description TEXT; - -ALTER TABLE release_group_secondary_type ADD COLUMN parent INTEGER; -ALTER TABLE release_group_secondary_type ADD COLUMN child_order INTEGER NOT NULL DEFAULT 0; -ALTER TABLE release_group_secondary_type ADD COLUMN description TEXT; - -ALTER TABLE release_packaging ADD COLUMN parent INTEGER; -ALTER TABLE release_packaging ADD COLUMN child_order INTEGER NOT NULL DEFAULT 0; -ALTER TABLE release_packaging ADD COLUMN description TEXT; - -ALTER TABLE release_status ADD COLUMN parent INTEGER; -ALTER TABLE release_status ADD COLUMN child_order INTEGER NOT NULL DEFAULT 0; -ALTER TABLE release_status ADD COLUMN description TEXT; - -ALTER TABLE work_alias_type ADD COLUMN parent INTEGER; -ALTER TABLE work_alias_type ADD COLUMN child_order INTEGER NOT NULL DEFAULT 0; -ALTER TABLE work_alias_type ADD COLUMN description TEXT; - -ALTER TABLE work_attribute_type ADD COLUMN parent INTEGER; -ALTER TABLE work_attribute_type ADD COLUMN child_order INTEGER NOT NULL DEFAULT 0; -ALTER TABLE work_attribute_type ADD COLUMN description TEXT; - -ALTER TABLE work_attribute_type_allowed_value ADD COLUMN parent INTEGER; -ALTER TABLE work_attribute_type_allowed_value ADD COLUMN child_order INTEGER NOT NULL DEFAULT 0; -ALTER TABLE work_attribute_type_allowed_value ADD COLUMN description TEXT; - -ALTER TABLE work_type ADD COLUMN parent INTEGER; -ALTER TABLE work_type ADD COLUMN child_order INTEGER NOT NULL DEFAULT 0; -ALTER TABLE work_type ADD COLUMN description TEXT; - -ALTER TABLE cover_art_archive.art_type ADD COLUMN parent INTEGER; -ALTER TABLE cover_art_archive.art_type ADD COLUMN child_order INTEGER NOT NULL DEFAULT 0; -ALTER TABLE cover_art_archive.art_type ADD COLUMN description TEXT; - - --- set Original Production, Bootleg Production and Reissue Production as children of Production, like pre-NGS (MBS-2410) -UPDATE label_type SET parent = 3 WHERE id IN (4, 5, 6); - --- put Other second to last and None last (MBS-6709) -UPDATE release_packaging SET child_order = 1 WHERE id = 5; -UPDATE release_packaging SET child_order = 2 WHERE id = 7; - --- put Other last -UPDATE cover_art_archive.art_type SET child_order = 1 WHERE id = 8; - --------------------------------------------------------------------------------- -SELECT '20140208-drop-script_language.sql'; - - DROP TABLE script_language; - --------------------------------------------------------------------------------- -SELECT '20140407-link-cardinality.sql'; - ALTER TABLE link_type ADD COLUMN entity0_cardinality integer, - ADD COLUMN entity1_cardinality integer; - - -- Type pairs where the info is central to entity1, but many-valued to entity0 - -- e.g. artist-recording (performer, mastering, etc.) - UPDATE link_type SET entity0_cardinality = 1, entity1_cardinality = 0 - WHERE (entity_type0 = 'artist' AND entity_type1 IN ('recording', 'release', 'release_group', 'work')) - OR (entity_type0 = 'label' AND entity_type1 IN ('recording', 'release', 'work')); - - -- Type pairs where the info is central to entity0, but many-valued to entity1 - -- e.g. recording-work (performance, medley, etc.) - UPDATE link_type SET entity0_cardinality = 0, entity1_cardinality = 1 - WHERE (entity_type0 = 'artist' AND entity_type1 = 'label') - OR (entity_type0 = 'recording' AND entity_type1 IN ('release', 'work')); - - -- Type pairs where the info is central to both entities. Default. - UPDATE link_type SET entity0_cardinality = 0, entity1_cardinality = 0 WHERE entity0_cardinality IS NULL AND entity1_cardinality IS NULL; - - ALTER TABLE link_type ALTER COLUMN entity0_cardinality SET NOT NULL, - ALTER COLUMN entity0_cardinality SET DEFAULT 0, - ALTER COLUMN entity1_cardinality SET NOT NULL, - ALTER COLUMN entity1_cardinality SET DEFAULT 0; --------------------------------------------------------------------------------- -SELECT '20140311-remove-area-sortnames.sql'; - - -ALTER TABLE area DROP COLUMN sort_name; - --------------------------------------------------------------------------------- -SELECT '20140313-remove-label-sortnames.sql'; - - -SELECT setval('label_alias_id_seq', (SELECT MAX(id) FROM label_alias)); - --- Migrate existing sortnames - --- If the name contains non-Latin scripts, we currently have a weird mixture of non-Latin name and Latin sortname. --- The guidelines for alias sortnames say not to do that, so for those we'll reuse the sortname as the alias name. -INSERT INTO label_alias (label, name, sort_name) -SELECT l.id, l.sort_name, l.sort_name -FROM label l -WHERE l.name != l.sort_name -AND l.name ~ '[\u0370-\u1DFF\u2E80-\u9FFF\uAC00-\uD7FF]' -AND l.sort_name NOT IN (SELECT sort_name FROM label_alias WHERE label = l.id) -- If there's already an alias with this sortname, we're not losing anything by dropping it -ORDER BY l.name; - --- If the name doesn't contain non-Latin scripts, we can just create an alias with the current name and sortname. -INSERT INTO label_alias (label, name, sort_name) -SELECT l.id, l.name, l.sort_name -FROM label l -WHERE l.name != l.sort_name -AND l.name !~ '[\u0370-\u1DFF\u2E80-\u9FFF\uAC00-\uD7FF]' -AND l.id NOT IN (SELECT label FROM label_alias WHERE name = l.name AND sort_name = l.sort_name) -ORDER BY l.name; - --- Drop the column - -ALTER TABLE label DROP COLUMN sort_name; - --------------------------------------------------------------------------------- -SELECT '20140214-add-instruments.sql'; - - - -CREATE TABLE instrument_type ( - id SERIAL, -- PK - name VARCHAR(255) NOT NULL, - parent INTEGER, -- references instrument_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT -); - -CREATE TABLE instrument ( - id SERIAL, -- PK - gid uuid NOT NULL, - name VARCHAR NOT NULL, - type INTEGER, -- references instrument_type.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >=0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - comment VARCHAR(255) NOT NULL DEFAULT '', - description TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE instrument_gid_redirect -( - gid UUID NOT NULL, -- PK - new_id INTEGER NOT NULL, -- references instrument.id - created TIMESTAMP WITH TIME ZONE DEFAULT NOW() -); - -CREATE TABLE instrument_alias_type ( - id SERIAL, -- PK, - name TEXT NOT NULL, - parent INTEGER, -- references instrument_alias_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT -); - -CREATE TABLE instrument_alias ( - id SERIAL, --PK - instrument INTEGER NOT NULL, -- references instrument.id - name VARCHAR NOT NULL, - locale TEXT, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >=0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - type INTEGER, -- references instrument_alias_type.id - sort_name VARCHAR NOT NULL, - begin_date_year SMALLINT, - begin_date_month SMALLINT, - begin_date_day SMALLINT, - end_date_year SMALLINT, - end_date_month SMALLINT, - end_date_day SMALLINT, - primary_for_locale BOOLEAN NOT NULL DEFAULT false, - ended BOOLEAN NOT NULL DEFAULT FALSE - CHECK ( - ( - -- If any end date fields are not null, then ended must be true - (end_date_year IS NOT NULL OR - end_date_month IS NOT NULL OR - end_date_day IS NOT NULL) AND - ended = TRUE - ) OR ( - -- Otherwise, all end date fields must be null - (end_date_year IS NULL AND - end_date_month IS NULL AND - end_date_day IS NULL) - ) - ), - CONSTRAINT primary_check CHECK ((locale IS NULL AND primary_for_locale IS FALSE) OR (locale IS NOT NULL)), - CONSTRAINT search_hints_are_empty - CHECK ( - (type <> 2) OR ( - type = 2 AND sort_name = name AND - begin_date_year IS NULL AND begin_date_month IS NULL AND begin_date_day IS NULL AND - end_date_year IS NULL AND end_date_month IS NULL AND end_date_day IS NULL AND - primary_for_locale IS FALSE AND locale IS NULL - ) - ) -); - -CREATE TABLE instrument_annotation ( - instrument INTEGER NOT NULL, -- PK, references instrument.id - annotation INTEGER NOT NULL -- PK, references annotation.id -); - -CREATE TABLE edit_instrument -( - edit INTEGER NOT NULL, -- PK, references edit.id - instrument INTEGER NOT NULL -- PK, references instrument.id CASCADE -); - -CREATE TABLE l_area_instrument -( - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references area.id - entity1 INTEGER NOT NULL, -- references instrument.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_artist_instrument -( - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references artist.id - entity1 INTEGER NOT NULL, -- references instrument.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_instrument_label -( - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references instrument.id - entity1 INTEGER NOT NULL, -- references label.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_instrument_instrument -( - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references instrument.id - entity1 INTEGER NOT NULL, -- references instrument.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_instrument_place -( - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references instrument.id - entity1 INTEGER NOT NULL, -- references recording.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_instrument_recording -( - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references instrument.id - entity1 INTEGER NOT NULL, -- references recording.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_instrument_release -( - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references instrument.id - entity1 INTEGER NOT NULL, -- references release.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_instrument_release_group -( - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references instrument.id - entity1 INTEGER NOT NULL, -- references release_group.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_instrument_url -( - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references instrument.id - entity1 INTEGER NOT NULL, -- references url.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_instrument_work -( - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references instrument.id - entity1 INTEGER NOT NULL, -- references work.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -SELECT setval('link_id_seq', (SELECT MAX(id) FROM link)); -SELECT setval('link_type_id_seq', (SELECT MAX(id) FROM link_type)); -SELECT setval('url_id_seq', (SELECT MAX(id) FROM url)); - -INSERT INTO instrument_type (name) VALUES ('Wind instrument'), ('String instrument'), ('Percussion instrument'), ('Electronic instrument'), ('Other instrument'); - -INSERT INTO instrument_alias_type (name) VALUES ('Instrument name'), ('Search hint'); - -INSERT INTO instrument (gid, name, description) SELECT gid, name, COALESCE(description, '') FROM link_attribute_type WHERE parent IS NOT NULL AND root = 14 ORDER BY id; - -INSERT INTO link_type (gid, entity_type0, entity_type1, name, description, link_phrase, reverse_link_phrase, long_link_phrase, priority) VALUES - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/instrument/url/wikipedia'), 'instrument', 'url', 'wikipedia', 'wikipedia', 'Wikipedia', 'Wikipedia', 'Wikipedia', 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/instrument/url/image'), 'instrument', 'url', 'image', 'image', 'image', 'image', 'image', 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/instrument/url/wikidata'), 'instrument', 'url', 'wikidata', 'wikidata', 'Wikidata', 'Wikidata', 'Wikidata', 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/instrument/url/information page'), 'instrument', 'url', 'information page', 'information page', 'information page', 'information page', 'information page', 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/instrument/instrument/child'), 'instrument', 'instrument', 'child', '', 'child of', 'children', 'is a child of', 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/instrument/instrument/type of'), 'instrument', 'instrument', 'type of', 'type of', 'type of', 'subtypes', 'is a type of', 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/instrument/instrument/derived from'), 'instrument', 'instrument', 'derived from', 'derived from', 'derived from', 'derivations', 'is derived from', 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/instrument/instrument/related to'), 'instrument', 'instrument', 'related to', 'related to', 'related to', 'related instruments', 'is related to', 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/instrument/instrument/parts'), 'instrument', 'instrument', 'parts', 'parts', 'consists of', 'part of', 'has parts', 0); - -INSERT INTO link (link_type) SELECT id FROM link_type WHERE entity_type0 = 'instrument' ORDER BY id; - - --- Remove descriptions which are just the same as the name -UPDATE instrument SET description = '' WHERE description = name; -UPDATE link_attribute_type SET description = '' WHERE description = name AND root = 14; - - --- Migrate URLs from instrument descriptions to URL relationships - --- 1. Insert the URLs into the url table -WITH urls AS ( - SELECT DISTINCT regexp_replace(description, '.*\(Wikipedia\)$', E'\\1') as url - FROM link_attribute_type - WHERE root = 14 - AND description ~ '.*\(Wikipedia\)$' -) -INSERT INTO url (gid, url) -SELECT generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', url), url -FROM urls -WHERE url NOT IN (SELECT url FROM url WHERE url = urls.url) -ORDER BY url; - - --- 2. Insert relationships into l_instrument_url -INSERT INTO l_instrument_url (link, entity0, entity1) -SELECT link.id, i.id, url.id -FROM ( - SELECT l.id - FROM link_type lt - JOIN link l ON l.link_type = lt.id - WHERE lt.name = 'wikipedia' - AND lt.entity_type0 = 'instrument' -) AS link, instrument i -JOIN url ON regexp_replace(description, '.*\(Wikipedia\)$', E'\\1') = url -WHERE i.description ~ '.*\(Wikipedia\)$' -ORDER BY link.id, i.id, url.id; - - --- 3. Remove the URLs from the instrument descriptions -UPDATE instrument -SET description = regexp_replace(description, ' *\(Wikipedia\)$', '') -WHERE description ~ '.*\(Wikipedia\)$'; - -UPDATE link_attribute_type -SET description = regexp_replace(description, ' *\(Wikipedia\)$', '') -WHERE description ~ '.*\(Wikipedia\)$' -AND root = 14; - - --- Migrate aliases from instrument descriptions to instrument aliases - --- 1. Insert the aliases into instrument_alias -WITH rows AS ( - SELECT id, unnest(regexp_split_to_array(regexp_replace(description, '.*Other names(?: include)?:? (.*?)\.? *$', E'\\1'), ', +| +and +')) AS name - FROM instrument - WHERE description ~ 'Other name' -) -INSERT INTO instrument_alias (instrument, name, sort_name) SELECT id, name, name FROM rows ORDER BY id, name; - --- 2. Remove the aliases from the instrument descriptions -UPDATE instrument -SET description = regexp_replace(description, ' ?Other names(?: include)?:? (.*?)\.? *$', '') -WHERE description ~ '.*Other names(?: include)?:? (.*?)\.? *$'; - -UPDATE link_attribute_type -SET description = regexp_replace(description, ' ?Other names(?: include)?:? (.*?)\.? *$', '') -WHERE description ~ '.*Other names(?: include)?:? (.*?)\.? *$' -AND root = 14; - - --- Turn instrument tree into relationships -INSERT INTO l_instrument_instrument (link, entity0, entity1) -SELECT link.id, i_parent.id, i_child.id -FROM ( - SELECT l.id - FROM link_type lt - JOIN link l ON l.link_type = lt.id - WHERE lt.name = 'child' - AND lt.entity_type0 = 'instrument' -) AS link, -link_attribute_type a_child -JOIN link_attribute_type a_parent ON a_parent.id = a_child.parent -JOIN instrument i_parent ON i_parent.gid = a_parent.gid -JOIN instrument i_child ON i_child.gid = a_child.gid -WHERE a_child.root = 14 -AND a_child.parent != 14 -ORDER BY link.id, i_parent.id, i_child.id; - - --- Flatten the instrument tree -UPDATE link_attribute_type SET child_order = 0, parent = 14 WHERE root = 14 AND id != 14; - - -SELECT setval('instrument_type_id_seq', (SELECT MAX(id) FROM instrument_type)); -SELECT setval('instrument_id_seq', (SELECT MAX(id) FROM instrument)); -SELECT setval('instrument_alias_type_id_seq', (SELECT MAX(id) FROM instrument_alias_type)); -SELECT setval('instrument_alias_id_seq', (SELECT MAX(id) FROM instrument_alias)); -SELECT setval('l_instrument_instrument_id_seq', (SELECT MAX(id) FROM l_instrument_instrument)); -SELECT setval('l_instrument_url_id_seq', (SELECT MAX(id) FROM l_instrument_url)); -SELECT setval('link_id_seq', (SELECT MAX(id) FROM link)); -SELECT setval('link_type_id_seq', (SELECT MAX(id) FROM link_type)); -SELECT setval('url_id_seq', (SELECT MAX(id) FROM url)); - -ALTER TABLE edit_instrument ADD CONSTRAINT edit_instrument_pkey PRIMARY KEY (edit, instrument); -ALTER TABLE instrument ADD CONSTRAINT instrument_pkey PRIMARY KEY (id); -ALTER TABLE instrument_alias ADD CONSTRAINT instrument_alias_pkey PRIMARY KEY (id); -ALTER TABLE instrument_alias_type ADD CONSTRAINT instrument_alias_type_pkey PRIMARY KEY (id); -ALTER TABLE instrument_annotation ADD CONSTRAINT instrument_annotation_pkey PRIMARY KEY (instrument, annotation); -ALTER TABLE instrument_gid_redirect ADD CONSTRAINT instrument_gid_redirect_pkey PRIMARY KEY (gid); -ALTER TABLE instrument_type ADD CONSTRAINT instrument_type_pkey PRIMARY KEY (id); -ALTER TABLE l_area_instrument ADD CONSTRAINT l_area_instrument_pkey PRIMARY KEY (id); -ALTER TABLE l_artist_instrument ADD CONSTRAINT l_artist_instrument_pkey PRIMARY KEY (id); -ALTER TABLE l_instrument_instrument ADD CONSTRAINT l_instrument_instrument_pkey PRIMARY KEY (id); -ALTER TABLE l_instrument_label ADD CONSTRAINT l_instrument_label_pkey PRIMARY KEY (id); -ALTER TABLE l_instrument_place ADD CONSTRAINT l_instrument_place_pkey PRIMARY KEY (id); -ALTER TABLE l_instrument_recording ADD CONSTRAINT l_instrument_recording_pkey PRIMARY KEY (id); -ALTER TABLE l_instrument_release ADD CONSTRAINT l_instrument_release_pkey PRIMARY KEY (id); -ALTER TABLE l_instrument_release_group ADD CONSTRAINT l_instrument_release_group_pkey PRIMARY KEY (id); -ALTER TABLE l_instrument_url ADD CONSTRAINT l_instrument_url_pkey PRIMARY KEY (id); -ALTER TABLE l_instrument_work ADD CONSTRAINT l_instrument_work_pkey PRIMARY KEY (id); - -CREATE INDEX edit_instrument_idx ON edit_label (label); -CREATE UNIQUE INDEX instrument_idx_gid ON instrument (gid); -CREATE INDEX instrument_idx_name ON instrument (name); - -CREATE INDEX instrument_alias_idx_instrument ON instrument_alias (instrument); -CREATE UNIQUE INDEX instrument_alias_idx_primary ON instrument_alias (instrument, locale) WHERE primary_for_locale = TRUE AND locale IS NOT NULL; -CREATE UNIQUE INDEX l_area_instrument_idx_uniq ON l_area_label (entity0, entity1, link); -CREATE UNIQUE INDEX l_artist_instrument_idx_uniq ON l_artist_label (entity0, entity1, link); -CREATE UNIQUE INDEX l_instrument_instrument_idx_uniq ON l_instrument_instrument (entity0, entity1, link); -CREATE UNIQUE INDEX l_instrument_label_idx_uniq ON l_instrument_label (entity0, entity1, link); -CREATE UNIQUE INDEX l_instrument_place_idx_uniq ON l_instrument_place (entity0, entity1, link); -CREATE UNIQUE INDEX l_instrument_recording_idx_uniq ON l_instrument_recording (entity0, entity1, link); -CREATE UNIQUE INDEX l_instrument_release_idx_uniq ON l_instrument_release (entity0, entity1, link); -CREATE UNIQUE INDEX l_instrument_release_group_idx_uniq ON l_instrument_release_group (entity0, entity1, link); -CREATE UNIQUE INDEX l_instrument_url_idx_uniq ON l_instrument_url (entity0, entity1, link); -CREATE UNIQUE INDEX l_instrument_work_idx_uniq ON l_instrument_work (entity0, entity1, link); -CREATE INDEX l_area_instrument_idx_entity1 ON l_area_label (entity1); -CREATE INDEX l_artist_instrument_idx_entity1 ON l_artist_label (entity1); -CREATE INDEX l_instrument_instrument_idx_entity1 ON l_instrument_instrument (entity1); -CREATE INDEX l_instrument_label_idx_entity1 ON l_instrument_label (entity1); -CREATE INDEX l_instrument_place_idx_entity1 ON l_instrument_place (entity1); -CREATE INDEX l_instrument_recording_idx_entity1 ON l_instrument_recording (entity1); -CREATE INDEX l_instrument_release_idx_entity1 ON l_instrument_release (entity1); -CREATE INDEX l_instrument_release_group_idx_entity1 ON l_instrument_release_group (entity1); -CREATE INDEX l_instrument_url_idx_entity1 ON l_instrument_url (entity1); -CREATE INDEX l_instrument_work_idx_entity1 ON l_instrument_work (entity1); - -CREATE INDEX instrument_idx_txt ON instrument USING gin(to_tsvector('mb_simple', name)); - --------------------------------------------------------------------------------- -SELECT '20140215-add-instruments-documentation.sql'; - - -CREATE TABLE documentation.l_area_instrument_example ( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_area_instrument.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_artist_instrument_example ( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_artist_instrument.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_instrument_instrument_example ( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_instrument_instrument.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_instrument_label_example ( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_instrument_label.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_instrument_place_example ( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_instrument_place.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_instrument_recording_example ( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_instrument_recording.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_instrument_release_example ( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_instrument_release.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_instrument_release_group_example ( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_instrument_release_group.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_instrument_url_example ( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_instrument_url.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_instrument_work_example ( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_instrument_work.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -ALTER TABLE documentation.l_area_instrument_example ADD CONSTRAINT l_area_instrument_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_artist_instrument_example ADD CONSTRAINT l_artist_instrument_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_instrument_instrument_example ADD CONSTRAINT l_instrument_instrument_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_instrument_label_example ADD CONSTRAINT l_instrument_label_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_instrument_place_example ADD CONSTRAINT l_instrument_place_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_instrument_recording_example ADD CONSTRAINT l_instrument_recording_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_instrument_release_example ADD CONSTRAINT l_instrument_release_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_instrument_release_group_example ADD CONSTRAINT l_instrument_release_group_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_instrument_url_example ADD CONSTRAINT l_instrument_url_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_instrument_work_example ADD CONSTRAINT l_instrument_work_example_pkey PRIMARY KEY (id); - --------------------------------------------------------------------------------- -SELECT '20140318-series.sql'; - ------------------------ --- CREATE NEW TABLES -- ------------------------ - -CREATE TABLE series -( - id SERIAL, - gid UUID NOT NULL, - name VARCHAR NOT NULL, - comment VARCHAR(255) NOT NULL DEFAULT '', - type INTEGER NOT NULL, -- references series_type.id - ordering_attribute INTEGER NOT NULL, -- references link_text_attribute_type.attribute_type - ordering_type INTEGER NOT NULL, -- references series_ordering_type.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW() -); - -CREATE TABLE series_type -( - id SERIAL, - name VARCHAR(255) NOT NULL, - entity_type VARCHAR(50) NOT NULL, - parent INTEGER, -- references series_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT -); - -CREATE TABLE series_ordering_type -( - id SERIAL, - name VARCHAR(255) NOT NULL, - parent INTEGER, -- references series_ordering_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT -); - -CREATE TABLE series_deletion -( - gid UUID NOT NULL, -- PK - last_known_name VARCHAR NOT NULL, - last_known_comment TEXT NOT NULL, - deleted_at timestamptz NOT NULL DEFAULT now() -); - -CREATE TABLE series_gid_redirect -( - gid UUID NOT NULL, -- PK - new_id INTEGER NOT NULL, - created TIMESTAMP WITH TIME ZONE DEFAULT NOW() -); - -CREATE TABLE series_alias_type -( - id SERIAL, -- PK - name TEXT NOT NULL, - parent INTEGER, -- references series_alias_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT -); - -CREATE TABLE series_alias -( - id SERIAL, - series INTEGER NOT NULL, -- references series.id - name VARCHAR NOT NULL, - locale TEXT, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - type INTEGER, -- references series_alias_type.id - sort_name VARCHAR NOT NULL, - begin_date_year SMALLINT, - begin_date_month SMALLINT, - begin_date_day SMALLINT, - end_date_year SMALLINT, - end_date_month SMALLINT, - end_date_day SMALLINT, - primary_for_locale BOOLEAN NOT NULL DEFAULT FALSE, - ended BOOLEAN NOT NULL DEFAULT FALSE - CHECK ( - ( - -- If any end date fields are not null, then ended must be true - (end_date_year IS NOT NULL OR - end_date_month IS NOT NULL OR - end_date_day IS NOT NULL) AND - ended = TRUE - ) OR ( - -- Otherwise, all end date fields must be null - (end_date_year IS NULL AND - end_date_month IS NULL AND - end_date_day IS NULL) - ) - ), - CONSTRAINT primary_check CHECK ((locale IS NULL AND primary_for_locale IS FALSE) OR (locale IS NOT NULL)), - CONSTRAINT search_hints_are_empty - CHECK ( - (type <> 2) OR ( - type = 2 AND sort_name = name AND - begin_date_year IS NULL AND begin_date_month IS NULL AND begin_date_day IS NULL AND - end_date_year IS NULL AND end_date_month IS NULL AND end_date_day IS NULL AND - primary_for_locale IS FALSE AND locale IS NULL - ) - ) -); - -CREATE TABLE series_annotation ( - series INTEGER NOT NULL, -- PK, references series.id - annotation INTEGER NOT NULL -- PK, references annotation.id -); - -CREATE TABLE documentation.l_area_series_example -( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_area_series.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_artist_series_example -( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_artist_series.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_instrument_series_example -( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_instrument_series.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_label_series_example -( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_label_series.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_place_series_example -( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_place_series.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_recording_series_example -( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_recording_series.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_release_series_example -( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_release_series.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_release_group_series_example -( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_release_group_series.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_series_series_example -( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_series_series.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_series_url_example -( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_series_url.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_series_work_example -( - id INTEGER NOT NULL, -- PK, references musicbrainz.l_series_work.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE edit_series -( - edit INTEGER NOT NULL, -- PK, references edit.id - series INTEGER NOT NULL -- PK, references series.id CASCADE -); - -CREATE TABLE editor_subscribe_series -( - id SERIAL, - editor INTEGER NOT NULL, -- references editor.id - series INTEGER NOT NULL, -- references series.id - last_edit_sent INTEGER NOT NULL -- references edit.id -); - -CREATE TABLE editor_subscribe_series_deleted -( - editor INTEGER NOT NULL, -- PK, references editor.id - gid UUID NOT NULL, -- PK, references series_deletion.gid - deleted_by INTEGER NOT NULL -- references edit.id -); - -CREATE TABLE l_area_series -( - id SERIAL, - link INTEGER NOT NULL, - entity0 INTEGER NOT NULL, - entity1 INTEGER NOT NULL, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_artist_series -( - id SERIAL, - link INTEGER NOT NULL, - entity0 INTEGER NOT NULL, - entity1 INTEGER NOT NULL, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_instrument_series -( - id SERIAL, - link INTEGER NOT NULL, - entity0 INTEGER NOT NULL, - entity1 INTEGER NOT NULL, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_label_series -( - id SERIAL, - link INTEGER NOT NULL, - entity0 INTEGER NOT NULL, - entity1 INTEGER NOT NULL, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_place_series -( - id SERIAL, - link INTEGER NOT NULL, - entity0 INTEGER NOT NULL, - entity1 INTEGER NOT NULL, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_recording_series -( - id SERIAL, - link INTEGER NOT NULL, - entity0 INTEGER NOT NULL, - entity1 INTEGER NOT NULL, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_release_series -( - id SERIAL, - link INTEGER NOT NULL, - entity0 INTEGER NOT NULL, - entity1 INTEGER NOT NULL, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_release_group_series -( - id SERIAL, - link INTEGER NOT NULL, - entity0 INTEGER NOT NULL, - entity1 INTEGER NOT NULL, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_series_series -( - id SERIAL, - link INTEGER NOT NULL, - entity0 INTEGER NOT NULL, - entity1 INTEGER NOT NULL, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_series_url -( - id SERIAL, - link INTEGER NOT NULL, - entity0 INTEGER NOT NULL, - entity1 INTEGER NOT NULL, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_series_work -( - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references series.id - entity1 INTEGER NOT NULL, -- references work.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE link_text_attribute_type ( - attribute_type INT NOT NULL -- PK, references link_attribute_type.id CASCADE -); - -CREATE TABLE link_attribute_text_value ( - link INT NOT NULL, -- PK, references link.id - attribute_type INT NOT NULL, -- PK, references link_text_attribute_type.attribute_type - text_value TEXT NOT NULL -); - -CREATE TABLE orderable_link_type ( - link_type INTEGER NOT NULL, -- PK - direction SMALLINT NOT NULL DEFAULT 1 CHECK (direction = 1 OR direction = 2) -); - ------------------------ --- CREATE NEW VIEWS -- ------------------------ - -CREATE OR REPLACE VIEW recording_series AS - SELECT entity0 AS recording, - entity1 AS series, - lrs.id AS relationship, - link_order, - lrs.link, - COALESCE(text_value, '') AS text_value - FROM l_recording_series lrs - JOIN series s ON s.id = lrs.entity1 - JOIN link l ON l.id = lrs.link - JOIN link_type lt ON (lt.id = l.link_type AND lt.gid = 'ea6f0698-6782-30d6-b16d-293081b66774') - LEFT OUTER JOIN link_attribute_text_value latv ON (latv.attribute_type = s.ordering_attribute AND latv.link = l.id) - ORDER BY series, link_order; - -CREATE OR REPLACE VIEW release_series AS - SELECT entity0 AS release, - entity1 AS series, - lrs.id AS relationship, - link_order, - lrs.link, - COALESCE(text_value, '') AS text_value - FROM l_release_series lrs - JOIN series s ON s.id = lrs.entity1 - JOIN link l ON l.id = lrs.link - JOIN link_type lt ON (lt.id = l.link_type AND lt.gid = '3fa29f01-8e13-3e49-9b0a-ad212aa2f81d') - LEFT OUTER JOIN link_attribute_text_value latv ON (latv.attribute_type = s.ordering_attribute AND latv.link = l.id) - ORDER BY series, link_order; - -CREATE OR REPLACE VIEW release_group_series AS - SELECT entity0 AS release_group, - entity1 AS series, - lrgs.id AS relationship, - link_order, - lrgs.link, - COALESCE(text_value, '') AS text_value - FROM l_release_group_series lrgs - JOIN series s ON s.id = lrgs.entity1 - JOIN link l ON l.id = lrgs.link - JOIN link_type lt ON (lt.id = l.link_type AND lt.gid = '01018437-91d8-36b9-bf89-3f885d53b5bd') - LEFT OUTER JOIN link_attribute_text_value latv ON (latv.attribute_type = s.ordering_attribute AND latv.link = l.id) - ORDER BY series, link_order; - -CREATE OR REPLACE VIEW work_series AS - SELECT entity1 AS work, - entity0 AS series, - lsw.id AS relationship, - link_order, - lsw.link, - COALESCE(text_value, '') AS text_value - FROM l_series_work lsw - JOIN series s ON s.id = lsw.entity0 - JOIN link l ON l.id = lsw.link - JOIN link_type lt ON (lt.id = l.link_type AND lt.gid = 'b0d44366-cdf0-3acb-bee6-0f65a77a6ef0') - LEFT OUTER JOIN link_attribute_text_value latv ON (latv.attribute_type = s.ordering_attribute AND latv.link = l.id) - ORDER BY series, link_order; - -------------------------- --- INSERT INITIAL DATA -- -------------------------- - --- new relationship types -SELECT setval('link_type_id_seq', (SELECT MAX(id) FROM link_type)); -SELECT setval('link_attribute_type_id_seq', (SELECT MAX(id) FROM link_attribute_type)); - -\set RECORDING_PART_OF_SERIES_GID 'generate_uuid_v3(''6ba7b8119dad11d180b400c04fd430c8'', ''http://musicbrainz.org/linktype/recording/series/part_of'')' -\set RELEASE_PART_OF_SERIES_GID 'generate_uuid_v3(''6ba7b8119dad11d180b400c04fd430c8'', ''http://musicbrainz.org/linktype/release/series/part_of'')' -\set RELEASE_GROUP_PART_OF_SERIES_GID 'generate_uuid_v3(''6ba7b8119dad11d180b400c04fd430c8'', ''http://musicbrainz.org/linktype/release_group/series/part_of'')' -\set WORK_PART_OF_SERIES_GID 'generate_uuid_v3(''6ba7b8119dad11d180b400c04fd430c8'', ''http://musicbrainz.org/linktype/series/work/part_of'')' -\set SERIES_WIKIPEDIA_URL_GID 'generate_uuid_v3(''6ba7b8119dad11d180b400c04fd430c8'', ''http://musicbrainz.org/linktype/series/url/wikipedia'')' -\set ORDERING_ATTRIBUTE_GID 'generate_uuid_v3(''6ba7b8119dad11d180b400c04fd430c8'', ''http://musicbrainz.org/linkattributetype/ordering'')' - -INSERT INTO link_type (gid, entity_type0, entity_type1, entity0_cardinality, - entity1_cardinality, name, description, link_phrase, - reverse_link_phrase, long_link_phrase) VALUES - ( - :RECORDING_PART_OF_SERIES_GID, - 'recording', 'series', 0, 0, 'part of', - 'Indicates that the recording is part of a series.', - 'part of', 'has parts', 'is a part of' - ), - ( - :RELEASE_PART_OF_SERIES_GID, - 'release', 'series', 0, 0, 'part of', - 'Indicates that the release is part of a series.', - 'part of', 'has parts', 'is a part of' - ), - ( - :RELEASE_GROUP_PART_OF_SERIES_GID, - 'release_group', 'series', 0, 0, 'part of', - 'Indicates that the release group is part of a series.', - 'part of', 'has parts', 'is a part of' - ), - ( - :WORK_PART_OF_SERIES_GID, - 'series', 'work', 0, 0, 'part of', - 'Indicates that the work is part of a series.', - 'has parts', 'part of', 'has part' - ), - ( - :SERIES_WIKIPEDIA_URL_GID, - 'series', 'url', 0, 0, 'wikipedia', - 'Points to the Wikipedia page for this series.', - 'Wikipedia', 'Wikipedia page for', 'has a Wikipedia page at' - ) - RETURNING id, gid, entity_type0, entity_type1, name, long_link_phrase; - -INSERT INTO orderable_link_type (link_type, direction) VALUES - ((SELECT id FROM link_type WHERE gid = :RECORDING_PART_OF_SERIES_GID), 2), - ((SELECT id FROM link_type WHERE gid = :RELEASE_PART_OF_SERIES_GID), 2), - ((SELECT id FROM link_type WHERE gid = :RELEASE_GROUP_PART_OF_SERIES_GID), 2), - ((SELECT id FROM link_type WHERE gid = :WORK_PART_OF_SERIES_GID), 1); - -INSERT INTO series_type (name, entity_type, parent, child_order, description) VALUES - ('Release group', 'release_group', NULL, 0, 'Indicates that the series is of release groups.'), - ('Release', 'release', NULL, 1, 'Indicates that the series is of releases.'), - ('Recording', 'recording', NULL, 2, 'Indicates that the series is of recordings.'), - ('Work', 'work', NULL, 3, 'Indicates that the series is of works.'), - ('Catalog', 'work', 4, 0, 'Indicates that the series is a works catalog.'); - -INSERT INTO series_ordering_type (name, parent, child_order, description) VALUES - ('Automatic', NULL, 0, - 'Sorts the items in the series automatically by their number attributes, using a natural sort order.' - ), - ('Manual', NULL, 1, - 'Allows for manually setting the position of each item in the series.' - ); - -INSERT INTO series_alias_type (name) VALUES ('Series name'), ('Search hint'); - -INSERT INTO link_attribute_type (root, child_order, gid, name, description) VALUES - (1, 0, :ORDERING_ATTRIBUTE_GID, 'number', - 'This attribute indicates the number of a work in a series.' - ); - -UPDATE link_attribute_type SET root = id WHERE gid = :ORDERING_ATTRIBUTE_GID; - -INSERT INTO link_text_attribute_type ( - SELECT id FROM link_attribute_type WHERE gid = :ORDERING_ATTRIBUTE_GID -); - -INSERT INTO link_type_attribute_type (link_type, attribute_type, min, max) VALUES - ((SELECT id FROM link_type WHERE gid = :RECORDING_PART_OF_SERIES_GID), - (SELECT id FROM link_attribute_type WHERE gid = :ORDERING_ATTRIBUTE_GID), - 0, 1 - ), - ((SELECT id FROM link_type WHERE gid = :RELEASE_PART_OF_SERIES_GID), - (SELECT id FROM link_attribute_type WHERE gid = :ORDERING_ATTRIBUTE_GID), - 0, 1 - ), - ((SELECT id FROM link_type WHERE gid = :RELEASE_GROUP_PART_OF_SERIES_GID), - (SELECT id FROM link_attribute_type WHERE gid = :ORDERING_ATTRIBUTE_GID), - 0, 1 - ), - ((SELECT id FROM link_type WHERE gid = :WORK_PART_OF_SERIES_GID), - (SELECT id FROM link_attribute_type WHERE gid = :ORDERING_ATTRIBUTE_GID), - 0, 1 - ); - -\unset RECORDING_PART_OF_SERIES_GID -\unset RELEASE_PART_OF_SERIES_GID -\unset RELEASE_GROUP_PART_OF_SERIES_GID -\unset WORK_PART_OF_SERIES_GID -\unset SERIES_WIKIPEDIA_URL_GID -\unset ORDERING_ATTRIBUTE_GID - ------------------------------ --- MIGRATE EXISTING TABLES -- ------------------------------ - -ALTER TABLE l_area_area ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_area_artist ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_area_label ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_area_place ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_area_recording ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_area_release ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_area_release_group ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_area_url ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_area_work ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_artist_artist ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_artist_label ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_artist_place ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_artist_recording ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_artist_release ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_artist_release_group ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_artist_url ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_artist_work ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_label_label ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_label_place ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_label_recording ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_label_release ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_label_release_group ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_label_url ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_label_work ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_place_place ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_place_recording ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_place_release ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_place_release_group ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_place_url ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_place_work ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_recording_recording ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_recording_release ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_recording_release_group ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_recording_url ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_recording_work ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_release_release ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_release_release_group ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_release_url ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_release_work ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_release_group_release_group ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_release_group_url ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_release_group_work ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_url_url ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_url_work ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); -ALTER TABLE l_work_work ADD COLUMN link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0); - --------------------- --- CREATE INDEXES -- --------------------- - -ALTER TABLE documentation.l_area_series_example ADD CONSTRAINT l_area_series_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_artist_series_example ADD CONSTRAINT l_artist_series_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_instrument_series_example ADD CONSTRAINT l_instrument_series_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_label_series_example ADD CONSTRAINT l_label_series_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_place_series_example ADD CONSTRAINT l_place_series_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_recording_series_example ADD CONSTRAINT l_recording_series_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_release_group_series_example ADD CONSTRAINT l_release_group_series_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_release_series_example ADD CONSTRAINT l_release_series_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_series_series_example ADD CONSTRAINT l_series_series_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_series_url_example ADD CONSTRAINT l_series_url_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_series_work_example ADD CONSTRAINT l_series_work_example_pkey PRIMARY KEY (id); -ALTER TABLE editor_subscribe_series ADD CONSTRAINT editor_subscribe_series_pkey PRIMARY KEY (id); -ALTER TABLE editor_subscribe_series_deleted ADD CONSTRAINT editor_subscribe_series_deleted_pkey PRIMARY KEY (editor, gid); - -ALTER TABLE l_area_series ADD CONSTRAINT l_area_series_pkey PRIMARY KEY (id); -ALTER TABLE l_artist_series ADD CONSTRAINT l_artist_series_pkey PRIMARY KEY (id); -ALTER TABLE l_instrument_series ADD CONSTRAINT l_instrument_series_pkey PRIMARY KEY (id); -ALTER TABLE l_label_series ADD CONSTRAINT l_label_series_pkey PRIMARY KEY (id); -ALTER TABLE l_place_series ADD CONSTRAINT l_place_series_pkey PRIMARY KEY (id); -ALTER TABLE l_recording_series ADD CONSTRAINT l_recording_series_pkey PRIMARY KEY (id); -ALTER TABLE l_release_group_series ADD CONSTRAINT l_release_group_series_pkey PRIMARY KEY (id); -ALTER TABLE l_release_series ADD CONSTRAINT l_release_series_pkey PRIMARY KEY (id); -ALTER TABLE l_series_series ADD CONSTRAINT l_series_series_pkey PRIMARY KEY (id); -ALTER TABLE l_series_url ADD CONSTRAINT l_series_url_pkey PRIMARY KEY (id); -ALTER TABLE l_series_work ADD CONSTRAINT l_series_work_pkey PRIMARY KEY (id); - -ALTER TABLE link_attribute_text_value ADD CONSTRAINT link_attribute_text_value_pkey PRIMARY KEY (link, attribute_type); -ALTER TABLE link_text_attribute_type ADD CONSTRAINT link_text_attribute_type_pkey PRIMARY KEY (attribute_type); -ALTER TABLE edit_series ADD CONSTRAINT edit_series_pkey PRIMARY KEY (edit, series); -ALTER TABLE series ADD CONSTRAINT series_pkey PRIMARY KEY (id); -ALTER TABLE series_alias ADD CONSTRAINT series_alias_pkey PRIMARY KEY (id); -ALTER TABLE series_alias_type ADD CONSTRAINT series_alias_type_pkey PRIMARY KEY (id); -ALTER TABLE series_annotation ADD CONSTRAINT series_annotation_pkey PRIMARY KEY (series, annotation); -ALTER TABLE series_deletion ADD CONSTRAINT series_deletion_pkey PRIMARY KEY (gid); -ALTER TABLE series_gid_redirect ADD CONSTRAINT series_gid_redirect_pkey PRIMARY KEY (gid); -ALTER TABLE series_ordering_type ADD CONSTRAINT series_ordering_type_pkey PRIMARY KEY (id); -ALTER TABLE series_type ADD CONSTRAINT series_type_pkey PRIMARY KEY (id); - -DROP INDEX IF EXISTS l_area_area_idx_uniq; -DROP INDEX IF EXISTS l_area_artist_idx_uniq; -DROP INDEX IF EXISTS l_area_instrument_idx_uniq; -DROP INDEX IF EXISTS l_area_label_idx_uniq; -DROP INDEX IF EXISTS l_area_place_idx_uniq; -DROP INDEX IF EXISTS l_area_recording_idx_uniq; -DROP INDEX IF EXISTS l_area_release_idx_uniq; -DROP INDEX IF EXISTS l_area_release_group_idx_uniq; -DROP INDEX IF EXISTS l_area_series_idx_uniq; -DROP INDEX IF EXISTS l_area_url_idx_uniq; -DROP INDEX IF EXISTS l_area_work_idx_uniq; - -DROP INDEX IF EXISTS l_artist_artist_idx_uniq; -DROP INDEX IF EXISTS l_artist_instrument_idx_uniq; -DROP INDEX IF EXISTS l_artist_label_idx_uniq; -DROP INDEX IF EXISTS l_artist_place_idx_uniq; -DROP INDEX IF EXISTS l_artist_recording_idx_uniq; -DROP INDEX IF EXISTS l_artist_release_idx_uniq; -DROP INDEX IF EXISTS l_artist_release_group_idx_uniq; -DROP INDEX IF EXISTS l_artist_series_idx_uniq; -DROP INDEX IF EXISTS l_artist_url_idx_uniq; -DROP INDEX IF EXISTS l_artist_work_idx_uniq; - -DROP INDEX IF EXISTS l_instrument_instrument_idx_uniq; -DROP INDEX IF EXISTS l_instrument_label_idx_uniq; -DROP INDEX IF EXISTS l_instrument_place_idx_uniq; -DROP INDEX IF EXISTS l_instrument_recording_idx_uniq; -DROP INDEX IF EXISTS l_instrument_release_idx_uniq; -DROP INDEX IF EXISTS l_instrument_release_group_idx_uniq; -DROP INDEX IF EXISTS l_instrument_series_idx_uniq; -DROP INDEX IF EXISTS l_instrument_url_idx_uniq; -DROP INDEX IF EXISTS l_instrument_work_idx_uniq; - -DROP INDEX IF EXISTS l_label_label_idx_uniq; -DROP INDEX IF EXISTS l_label_place_idx_uniq; -DROP INDEX IF EXISTS l_label_recording_idx_uniq; -DROP INDEX IF EXISTS l_label_release_idx_uniq; -DROP INDEX IF EXISTS l_label_release_group_idx_uniq; -DROP INDEX IF EXISTS l_label_series_idx_uniq; -DROP INDEX IF EXISTS l_label_url_idx_uniq; -DROP INDEX IF EXISTS l_label_work_idx_uniq; - -DROP INDEX IF EXISTS l_place_place_idx_uniq; -DROP INDEX IF EXISTS l_place_recording_idx_uniq; -DROP INDEX IF EXISTS l_place_release_idx_uniq; -DROP INDEX IF EXISTS l_place_release_group_idx_uniq; -DROP INDEX IF EXISTS l_place_series_idx_uniq; -DROP INDEX IF EXISTS l_place_url_idx_uniq; -DROP INDEX IF EXISTS l_place_work_idx_uniq; - -DROP INDEX IF EXISTS l_recording_recording_idx_uniq; -DROP INDEX IF EXISTS l_recording_release_idx_uniq; -DROP INDEX IF EXISTS l_recording_release_group_idx_uniq; -DROP INDEX IF EXISTS l_recording_series_idx_uniq; -DROP INDEX IF EXISTS l_recording_url_idx_uniq; -DROP INDEX IF EXISTS l_recording_work_idx_uniq; - -DROP INDEX IF EXISTS l_release_release_idx_uniq; -DROP INDEX IF EXISTS l_release_release_group_idx_uniq; -DROP INDEX IF EXISTS l_release_series_idx_uniq; -DROP INDEX IF EXISTS l_release_url_idx_uniq; -DROP INDEX IF EXISTS l_release_work_idx_uniq; - -DROP INDEX IF EXISTS l_release_group_release_group_idx_uniq; -DROP INDEX IF EXISTS l_release_group_series_idx_uniq; -DROP INDEX IF EXISTS l_release_group_url_idx_uniq; -DROP INDEX IF EXISTS l_release_group_work_idx_uniq; - -DROP INDEX IF EXISTS l_series_series_idx_uniq; -DROP INDEX IF EXISTS l_series_url_idx_uniq; -DROP INDEX IF EXISTS l_series_work_idx_uniq; - -DROP INDEX IF EXISTS l_url_url_idx_uniq; -DROP INDEX IF EXISTS l_url_work_idx_uniq; - -DROP INDEX IF EXISTS l_work_work_idx_uniq; - -CREATE UNIQUE INDEX l_area_area_idx_uniq ON l_area_area (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_area_artist_idx_uniq ON l_area_artist (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_area_instrument_idx_uniq ON l_area_label (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_area_label_idx_uniq ON l_area_label (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_area_place_idx_uniq ON l_area_place (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_area_recording_idx_uniq ON l_area_recording (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_area_release_idx_uniq ON l_area_release (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_area_release_group_idx_uniq ON l_area_release_group (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_area_series_idx_uniq ON l_area_series (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_area_url_idx_uniq ON l_area_url (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_area_work_idx_uniq ON l_area_work (entity0, entity1, link, link_order); - -CREATE UNIQUE INDEX l_artist_artist_idx_uniq ON l_artist_artist (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_artist_instrument_idx_uniq ON l_artist_label (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_artist_label_idx_uniq ON l_artist_label (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_artist_place_idx_uniq ON l_artist_place (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_artist_recording_idx_uniq ON l_artist_recording (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_artist_release_idx_uniq ON l_artist_release (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_artist_release_group_idx_uniq ON l_artist_release_group (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_artist_series_idx_uniq ON l_artist_series (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_artist_url_idx_uniq ON l_artist_url (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_artist_work_idx_uniq ON l_artist_work (entity0, entity1, link, link_order); - -CREATE UNIQUE INDEX l_instrument_instrument_idx_uniq ON l_instrument_instrument (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_instrument_label_idx_uniq ON l_instrument_label (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_instrument_place_idx_uniq ON l_instrument_place (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_instrument_recording_idx_uniq ON l_instrument_recording (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_instrument_release_idx_uniq ON l_instrument_release (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_instrument_release_group_idx_uniq ON l_instrument_release_group (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_instrument_series_idx_uniq ON l_instrument_series (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_instrument_url_idx_uniq ON l_instrument_url (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_instrument_work_idx_uniq ON l_instrument_work (entity0, entity1, link, link_order); - -CREATE UNIQUE INDEX l_label_label_idx_uniq ON l_label_label (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_label_place_idx_uniq ON l_label_place (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_label_recording_idx_uniq ON l_label_recording (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_label_release_idx_uniq ON l_label_release (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_label_release_group_idx_uniq ON l_label_release_group (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_label_series_idx_uniq ON l_label_series (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_label_url_idx_uniq ON l_label_url (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_label_work_idx_uniq ON l_label_work (entity0, entity1, link, link_order); - -CREATE UNIQUE INDEX l_place_place_idx_uniq ON l_place_place (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_place_recording_idx_uniq ON l_place_recording (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_place_release_idx_uniq ON l_place_release (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_place_release_group_idx_uniq ON l_place_release_group (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_place_series_idx_uniq ON l_place_series (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_place_url_idx_uniq ON l_place_url (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_place_work_idx_uniq ON l_place_work (entity0, entity1, link, link_order); - -CREATE UNIQUE INDEX l_recording_recording_idx_uniq ON l_recording_recording (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_recording_release_idx_uniq ON l_recording_release (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_recording_release_group_idx_uniq ON l_recording_release_group (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_recording_series_idx_uniq ON l_recording_series (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_recording_url_idx_uniq ON l_recording_url (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_recording_work_idx_uniq ON l_recording_work (entity0, entity1, link, link_order); - -CREATE UNIQUE INDEX l_release_release_idx_uniq ON l_release_release (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_release_release_group_idx_uniq ON l_release_release_group (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_release_series_idx_uniq ON l_release_series (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_release_url_idx_uniq ON l_release_url (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_release_work_idx_uniq ON l_release_work (entity0, entity1, link, link_order); - -CREATE UNIQUE INDEX l_release_group_release_group_idx_uniq ON l_release_group_release_group (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_release_group_series_idx_uniq ON l_release_group_series (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_release_group_url_idx_uniq ON l_release_group_url (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_release_group_work_idx_uniq ON l_release_group_work (entity0, entity1, link, link_order); - -CREATE UNIQUE INDEX l_series_series_idx_uniq ON l_series_series (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_series_url_idx_uniq ON l_series_url (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_series_work_idx_uniq ON l_series_work (entity0, entity1, link, link_order); - -CREATE UNIQUE INDEX l_url_url_idx_uniq ON l_url_url (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_url_work_idx_uniq ON l_url_work (entity0, entity1, link, link_order); - -CREATE UNIQUE INDEX l_work_work_idx_uniq ON l_work_work (entity0, entity1, link, link_order); - -CREATE INDEX l_area_series_idx_entity1 ON l_area_series (entity1); -CREATE INDEX l_artist_series_idx_entity1 ON l_artist_series (entity1); -CREATE INDEX l_instrument_series_idx_entity1 ON l_instrument_series (entity1); -CREATE INDEX l_label_series_idx_entity1 ON l_label_series (entity1); -CREATE INDEX l_place_series_idx_entity1 ON l_place_series (entity1); -CREATE INDEX l_recording_series_idx_entity1 ON l_recording_series (entity1); -CREATE INDEX l_release_series_idx_entity1 ON l_release_series (entity1); -CREATE INDEX l_release_group_series_idx_entity1 ON l_release_group_series (entity1); -CREATE INDEX l_series_series_idx_entity1 ON l_series_series (entity1); -CREATE INDEX l_series_url_idx_entity1 ON l_series_url (entity1); -CREATE INDEX l_series_work_idx_entity1 ON l_series_work (entity1); - -CREATE UNIQUE INDEX series_idx_gid ON series (gid); -CREATE INDEX series_idx_name ON series (name); - -CREATE INDEX series_alias_idx_series ON series_alias (series); -CREATE UNIQUE INDEX series_alias_idx_primary ON series_alias (series, locale) WHERE primary_for_locale = TRUE AND locale IS NOT NULL; - -CREATE INDEX series_idx_txt ON series USING gin(to_tsvector('mb_simple', name)); - -CREATE INDEX series_alias_idx_txt ON series_alias USING gin(to_tsvector('mb_simple', name)); -CREATE INDEX series_alias_idx_txt_sort ON series_alias USING gin(to_tsvector('mb_simple', sort_name)); - -CREATE INDEX edit_series_idx ON edit_series (series); - -CREATE INDEX editor_subscribe_series_idx_uniq ON editor_subscribe_series (editor, series); -CREATE INDEX editor_subscribe_series_idx_series ON editor_subscribe_series (series); - --------------------------------------------------------------------------------- -SELECT '20140418-series-instrument-functions.sql'; - -CREATE OR REPLACE FUNCTION empty_artists() RETURNS SETOF int AS -$BODY$ - SELECT id FROM artist - WHERE - id > 2 AND - edits_pending = 0 AND - ( - last_updated < now() - '1 day'::interval OR last_updated is NULL - ) - EXCEPT - SELECT artist FROM edit_artist WHERE edit_artist.status = 1 - EXCEPT - SELECT artist FROM artist_credit_name - EXCEPT - SELECT entity1 FROM l_area_artist - EXCEPT - SELECT entity0 FROM l_artist_artist - EXCEPT - SELECT entity1 FROM l_artist_artist - EXCEPT - SELECT entity0 FROM l_artist_instrument - EXCEPT - SELECT entity0 FROM l_artist_label - EXCEPT - SELECT entity0 FROM l_artist_place - EXCEPT - SELECT entity0 FROM l_artist_recording - EXCEPT - SELECT entity0 FROM l_artist_release - EXCEPT - SELECT entity0 FROM l_artist_release_group - EXCEPT - SELECT entity0 FROM l_artist_series - EXCEPT - SELECT entity0 FROM l_artist_url - EXCEPT - SELECT entity0 FROM l_artist_work; -$BODY$ -LANGUAGE 'sql'; - -CREATE OR REPLACE FUNCTION empty_labels() RETURNS SETOF int AS -$BODY$ - SELECT id FROM label - WHERE - id > 1 AND - edits_pending = 0 AND - ( - last_updated < now() - '1 day'::interval OR last_updated is NULL - ) - EXCEPT - SELECT label FROM edit_label WHERE edit_label.status = 1 - EXCEPT - SELECT label FROM release_label - EXCEPT - SELECT entity1 FROM l_area_label - EXCEPT - SELECT entity1 FROM l_artist_label - EXCEPT - SELECT entity1 FROM l_instrument_label - EXCEPT - SELECT entity1 FROM l_label_label - EXCEPT - SELECT entity0 FROM l_label_label - EXCEPT - SELECT entity0 FROM l_label_place - EXCEPT - SELECT entity0 FROM l_label_recording - EXCEPT - SELECT entity0 FROM l_label_release - EXCEPT - SELECT entity0 FROM l_label_release_group - EXCEPT - SELECT entity0 FROM l_label_series - EXCEPT - SELECT entity0 FROM l_label_url - EXCEPT - SELECT entity0 FROM l_label_work; -$BODY$ -LANGUAGE 'sql'; - -CREATE OR REPLACE FUNCTION empty_release_groups() RETURNS SETOF int AS -$BODY$ - SELECT id FROM release_group - WHERE - edits_pending = 0 AND - ( - last_updated < now() - '1 day'::interval OR last_updated is NULL - ) - EXCEPT - SELECT release_group - FROM edit_release_group - JOIN edit ON (edit.id = edit_release_group.edit) - WHERE edit.status = 1 - EXCEPT - SELECT release_group FROM release - EXCEPT - SELECT entity1 FROM l_area_release_group - EXCEPT - SELECT entity1 FROM l_artist_release_group - EXCEPT - SELECT entity1 FROM l_instrument_release_group - EXCEPT - SELECT entity1 FROM l_label_release_group - EXCEPT - SELECT entity1 FROM l_place_release_group - EXCEPT - SELECT entity1 FROM l_recording_release_group - EXCEPT - SELECT entity1 FROM l_release_release_group - EXCEPT - SELECT entity1 FROM l_release_group_release_group - EXCEPT - SELECT entity0 FROM l_release_group_release_group - EXCEPT - SELECT entity0 FROM l_release_group_series - EXCEPT - SELECT entity0 FROM l_release_group_url - EXCEPT - SELECT entity0 FROM l_release_group_work; -$BODY$ -LANGUAGE 'sql'; - -CREATE OR REPLACE FUNCTION empty_works() RETURNS SETOF int AS -$BODY$ - SELECT id FROM work - WHERE - edits_pending = 0 AND - ( - last_updated < now() - '1 day'::interval OR last_updated is NULL - ) - EXCEPT - SELECT work - FROM edit_work - JOIN edit ON (edit.id = edit_work.edit) - WHERE edit.status = 1 - EXCEPT - SELECT entity1 FROM l_area_work - EXCEPT - SELECT entity1 FROM l_artist_work - EXCEPT - SELECT entity1 FROM l_instrument_work - EXCEPT - SELECT entity1 FROM l_label_work - EXCEPT - SELECT entity1 FROM l_place_work - EXCEPT - SELECT entity1 FROM l_recording_work - EXCEPT - SELECT entity1 FROM l_release_work - EXCEPT - SELECT entity1 FROM l_release_group_work - EXCEPT - SELECT entity1 FROM l_series_work - EXCEPT - SELECT entity1 FROM l_url_work - EXCEPT - SELECT entity1 FROM l_work_work - EXCEPT - SELECT entity0 FROM l_work_work; -$BODY$ -LANGUAGE 'sql'; - -CREATE OR REPLACE FUNCTION empty_places() RETURNS SETOF int AS -$BODY$ - SELECT id FROM place - WHERE - edits_pending = 0 AND - ( - last_updated < now() - '1 day'::interval OR last_updated is NULL - ) - EXCEPT - SELECT place - FROM edit_place - JOIN edit ON (edit.id = edit_place.edit) - WHERE edit.status = 1 - EXCEPT - SELECT entity1 FROM l_area_place - EXCEPT - SELECT entity1 FROM l_artist_place - EXCEPT - SELECT entity1 FROM l_instrument_place - EXCEPT - SELECT entity1 FROM l_label_place - EXCEPT - SELECT entity1 FROM l_place_place - EXCEPT - SELECT entity0 FROM l_place_place - EXCEPT - SELECT entity0 FROM l_place_recording - EXCEPT - SELECT entity0 FROM l_place_release - EXCEPT - SELECT entity0 FROM l_place_release_group - EXCEPT - SELECT entity0 FROM l_place_series - EXCEPT - SELECT entity0 FROM l_place_url - EXCEPT - SELECT entity0 FROM l_place_work; -$BODY$ -LANGUAGE 'sql'; - -CREATE OR REPLACE FUNCTION empty_series() RETURNS SETOF int AS -$BODY$ - SELECT id FROM series - WHERE - edits_pending = 0 AND - ( - last_updated < now() - '1 day'::interval OR last_updated is NULL - ) - EXCEPT - SELECT series - FROM edit_series - JOIN edit ON (edit.id = edit_series.edit) - WHERE edit.status = 1 - EXCEPT - SELECT entity1 FROM l_area_series - EXCEPT - SELECT entity1 FROM l_artist_series - EXCEPT - SELECT entity1 FROM l_instrument_series - EXCEPT - SELECT entity1 FROM l_label_series - EXCEPT - SELECT entity1 FROM l_place_series - EXCEPT - SELECT entity1 FROM l_recording_series - EXCEPT - SELECT entity1 FROM l_release_series - EXCEPT - SELECT entity1 FROM l_release_group_series - EXCEPT - SELECT entity0 FROM l_series_series - EXCEPT - SELECT entity1 FROM l_series_series - EXCEPT - SELECT entity0 FROM l_series_url - EXCEPT - SELECT entity0 FROM l_series_work; -$BODY$ -LANGUAGE 'sql'; - -CREATE OR REPLACE FUNCTION delete_unused_url(ids INTEGER[]) -RETURNS VOID AS $$ -DECLARE - clear_up INTEGER[]; -BEGIN - SELECT ARRAY( - SELECT id FROM url url_row WHERE id = any(ids) - AND NOT ( - EXISTS ( - SELECT TRUE FROM l_area_url - WHERE entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_artist_url - WHERE entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_instrument_url - WHERE entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_label_url - WHERE entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_place_url - WHERE entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_recording_url - WHERE entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_release_url - WHERE entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_release_group_url - WHERE entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_series_url - WHERE entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_url_url - WHERE entity0 = url_row.id OR entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_url_work - WHERE entity0 = url_row.id - LIMIT 1 - ) - ) - ) INTO clear_up; - - DELETE FROM url_gid_redirect WHERE new_id = any(clear_up); - DELETE FROM url WHERE id = any(clear_up); -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION delete_orphaned_recordings() -RETURNS TRIGGER -AS $$ - BEGIN - PERFORM TRUE - FROM recording outer_r - WHERE id = OLD.recording - AND edits_pending = 0 - AND NOT EXISTS ( - SELECT TRUE - FROM edit JOIN edit_recording er ON edit.id = er.edit - WHERE er.recording = outer_r.id - AND type IN (71, 207, 218) - LIMIT 1 - ) AND NOT EXISTS ( - SELECT TRUE FROM track WHERE track.recording = outer_r.id LIMIT 1 - ) AND NOT EXISTS ( - SELECT TRUE FROM l_area_recording WHERE entity1 = outer_r.id - UNION ALL - SELECT TRUE FROM l_artist_recording WHERE entity1 = outer_r.id - UNION ALL - SELECT TRUE FROM l_instrument_recording WHERE entity1 = outer_r.id - UNION ALL - SELECT TRUE FROM l_label_recording WHERE entity1 = outer_r.id - UNION ALL - SELECT TRUE FROM l_place_recording WHERE entity1 = outer_r.id - UNION ALL - SELECT TRUE FROM l_recording_recording WHERE entity1 = outer_r.id OR entity0 = outer_r.id - UNION ALL - SELECT TRUE FROM l_recording_release WHERE entity0 = outer_r.id - UNION ALL - SELECT TRUE FROM l_recording_release_group WHERE entity0 = outer_r.id - UNION ALL - SELECT TRUE FROM l_recording_series WHERE entity0 = outer_r.id - UNION ALL - SELECT TRUE FROM l_recording_work WHERE entity0 = outer_r.id - UNION ALL - SELECT TRUE FROM l_recording_url WHERE entity0 = outer_r.id - ); - - IF FOUND THEN - -- Remove references from tables that don't change whether or not this recording - -- is orphaned. - DELETE FROM isrc WHERE recording = OLD.recording; - DELETE FROM recording_annotation WHERE recording = OLD.recording; - DELETE FROM recording_gid_redirect WHERE new_id = OLD.recording; - DELETE FROM recording_rating_raw WHERE recording = OLD.recording; - DELETE FROM recording_tag WHERE recording = OLD.recording; - DELETE FROM recording_tag_raw WHERE recording = OLD.recording; - - DELETE FROM recording WHERE id = OLD.recording; - END IF; - - RETURN NULL; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION remove_unused_links() RETURNS TRIGGER AS $$ -DECLARE - other_ars_exist BOOLEAN; -BEGIN - EXECUTE 'SELECT EXISTS (SELECT TRUE FROM ' || quote_ident(TG_TABLE_NAME) || - ' WHERE link = $1)' - INTO other_ars_exist - USING OLD.link; - - IF NOT other_ars_exist THEN - DELETE FROM link_attribute WHERE link = OLD.link; - DELETE FROM link_attribute_credit WHERE link = OLD.link; - DELETE FROM link_attribute_text_value WHERE link = OLD.link; - DELETE FROM link WHERE id = OLD.link; - END IF; - - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - --------------------------------------------------------------------------------- -SELECT '20140429-area-view.sql'; - - --- First, construct a table (recursively) of parent -> descendant connections --- for areas, including an array of the path (the 'descendants' array). - --- Then, find the shortest path to each type of parent by joining to area, --- distinct on descendant, type, and order by the length of the array of descendants. -CREATE OR REPLACE VIEW area_containment AS - WITH RECURSIVE area_descendants AS ( - SELECT entity0 AS parent, entity1 AS descendant, ARRAY[entity1] AS descendants - FROM l_area_area laa - JOIN link ON laa.link = link.id - JOIN link_type ON link.link_type = link_type.id - WHERE link_type.gid = 'de7cc874-8b1b-3a05-8272-f3834c968fb7' - UNION ALL - SELECT entity0 AS parent, descendant, descendants || entity1 - FROM l_area_area laa - JOIN link ON laa.link=link.id - JOIN link_type ON link.link_type = link_type.id - JOIN area_descendants ON area_descendants.parent = laa.entity1 - WHERE link_type.gid = 'de7cc874-8b1b-3a05-8272-f3834c968fb7' - AND NOT entity0 = ANY(descendants)) - SELECT DISTINCT ON (descendant, type) descendant, area_descendants.parent, area.type, area_type.name AS type_name, descendants || area_descendants.parent AS descendant_hierarchy - FROM area_descendants - JOIN area ON area_descendants.parent = area.id - JOIN area_type ON area.type = area_type.id - WHERE area.type IN (1, 2, 3) - ORDER BY descendant, type, array_length(descendants, 1) ASC; - -COMMIT; diff --git a/mbdata/sql/updates/schema-change/20.standalone.sql b/mbdata/sql/updates/schema-change/20.standalone.sql deleted file mode 100644 index a3a29dd..0000000 --- a/mbdata/sql/updates/schema-change/20.standalone.sql +++ /dev/null @@ -1,644 +0,0 @@ --- Generated by CompileSchemaScripts.pl from: --- 20140308-ordering-columns-fk.sql --- 20140312-dates-trigger.sql --- 20140217-instrument-triggers.sql --- 20140318-series-fks.sql -\set ON_ERROR_STOP 1 -BEGIN; --------------------------------------------------------------------------------- -SELECT '20140308-ordering-columns-fk.sql'; - - -ALTER TABLE area_alias_type - ADD CONSTRAINT area_alias_type_fk_parent - FOREIGN KEY (parent) - REFERENCES area_alias_type(id); - -ALTER TABLE area_type - ADD CONSTRAINT area_type_fk_parent - FOREIGN KEY (parent) - REFERENCES area_type(id); - -ALTER TABLE artist_type - ADD CONSTRAINT artist_type_fk_parent - FOREIGN KEY (parent) - REFERENCES artist_type(id); - -ALTER TABLE artist_alias_type - ADD CONSTRAINT artist_alias_type_fk_parent - FOREIGN KEY (parent) - REFERENCES artist_alias_type(id); - -ALTER TABLE gender - ADD CONSTRAINT gender_fk_parent - FOREIGN KEY (parent) - REFERENCES gender(id); - -ALTER TABLE label_type - ADD CONSTRAINT label_type_fk_parent - FOREIGN KEY (parent) - REFERENCES label_type(id); - -ALTER TABLE label_alias_type - ADD CONSTRAINT label_alias_type_fk_parent - FOREIGN KEY (parent) - REFERENCES label_alias_type(id); - -ALTER TABLE place_type - ADD CONSTRAINT place_type_fk_parent - FOREIGN KEY (parent) - REFERENCES place_type(id); - -ALTER TABLE place_alias_type - ADD CONSTRAINT place_alias_type_fk_parent - FOREIGN KEY (parent) - REFERENCES place_alias_type(id); - -ALTER TABLE release_group_primary_type - ADD CONSTRAINT release_group_primary_type_fk_parent - FOREIGN KEY (parent) - REFERENCES release_group_primary_type(id); - -ALTER TABLE release_group_secondary_type - ADD CONSTRAINT release_group_secondary_type_fk_parent - FOREIGN KEY (parent) - REFERENCES release_group_secondary_type(id); - -ALTER TABLE release_packaging - ADD CONSTRAINT release_packaging_fk_parent - FOREIGN KEY (parent) - REFERENCES release_packaging(id); - -ALTER TABLE release_status - ADD CONSTRAINT release_status_fk_parent - FOREIGN KEY (parent) - REFERENCES release_status(id); - -ALTER TABLE work_alias_type - ADD CONSTRAINT work_alias_type_fk_parent - FOREIGN KEY (parent) - REFERENCES work_alias_type(id); - -ALTER TABLE work_attribute_type - ADD CONSTRAINT work_attribute_type_fk_parent - FOREIGN KEY (parent) - REFERENCES work_attribute_type(id); - -ALTER TABLE work_attribute_type_allowed_value - ADD CONSTRAINT work_attribute_type_allowed_value_fk_parent - FOREIGN KEY (parent) - REFERENCES work_attribute_type_allowed_value(id); - -ALTER TABLE work_type - ADD CONSTRAINT work_type_fk_parent - FOREIGN KEY (parent) - REFERENCES work_type(id); - -ALTER TABLE cover_art_archive.art_type - ADD CONSTRAINT art_type_fk_parent - FOREIGN KEY (parent) - REFERENCES cover_art_archive.art_type(id); - --------------------------------------------------------------------------------- -SELECT '20140312-dates-trigger.sql'; - -CREATE OR REPLACE FUNCTION check_has_dates() -RETURNS trigger AS $$ -BEGIN - IF (NEW.begin_date_year IS NOT NULL OR - NEW.begin_date_month IS NOT NULL OR - NEW.begin_date_day IS NOT NULL OR - NEW.end_date_year IS NOT NULL OR - NEW.end_date_month IS NOT NULL OR - NEW.end_date_day IS NOT NULL OR - NEW.ended = TRUE) - AND NOT (SELECT has_dates FROM link_type WHERE id = NEW.link_type) - THEN - RAISE EXCEPTION 'Attempt to add dates to a relationship type that does not support dates.'; - END IF; - RETURN NEW; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE TRIGGER check_has_dates BEFORE UPDATE OR INSERT ON link - FOR EACH ROW EXECUTE PROCEDURE check_has_dates(); - --------------------------------------------------------------------------------- -SELECT '20140217-instrument-triggers.sql'; - - -CREATE OR REPLACE FUNCTION a_ins_instrument() RETURNS TRIGGER AS $$ -BEGIN - INSERT INTO link_attribute_type (parent, root, child_order, gid, name, description) VALUES (14, 14, 0, NEW.gid, NEW.name, NEW.description); - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE FUNCTION a_upd_instrument() RETURNS trigger AS $$ -BEGIN - UPDATE link_attribute_type SET name = NEW.name, description = NEW.description WHERE gid = NEW.gid; - IF NOT FOUND THEN - RAISE EXCEPTION 'no link_attribute_type found for instrument %', NEW.gid; - ELSE - RETURN NEW; - END IF; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE FUNCTION a_del_instrument() RETURNS trigger AS $$ -BEGIN - DELETE FROM link_attribute_type WHERE gid = OLD.gid; - IF NOT FOUND THEN - RAISE EXCEPTION 'no link_attribute_type found for instrument %', NEW.gid; - ELSE - RETURN NEW; - END IF; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE FUNCTION unique_primary_instrument_alias() -RETURNS trigger AS $$ -BEGIN - IF NEW.primary_for_locale THEN - UPDATE instrument_alias SET primary_for_locale = FALSE - WHERE locale = NEW.locale AND id != NEW.id - AND instrument = NEW.instrument; - END IF; - RETURN NEW; -END; -$$ LANGUAGE 'plpgsql'; - - -ALTER TABLE instrument ADD CHECK (controlled_for_whitespace(comment)); - -ALTER TABLE instrument - ADD CONSTRAINT control_for_whitespace CHECK (controlled_for_whitespace(name)), - ADD CONSTRAINT only_non_empty CHECK (name != ''); - -ALTER TABLE instrument_alias - ADD CONSTRAINT control_for_whitespace CHECK (controlled_for_whitespace(name)), - ADD CONSTRAINT only_non_empty CHECK (name != ''), - ADD CONSTRAINT control_for_whitespace_sort_name CHECK (controlled_for_whitespace(sort_name)), - ADD CONSTRAINT only_non_empty_sort_name CHECK (sort_name != ''); - -ALTER TABLE edit_instrument - ADD CONSTRAINT edit_instrument_fk_edit - FOREIGN KEY (edit) - REFERENCES edit(id); - -ALTER TABLE edit_instrument - ADD CONSTRAINT edit_instrument_fk_instrument - FOREIGN KEY (instrument) - REFERENCES instrument(id) - ON DELETE CASCADE; - -ALTER TABLE instrument - ADD CONSTRAINT instrument_fk_type - FOREIGN KEY (type) - REFERENCES instrument_type(id); - -ALTER TABLE instrument_alias - ADD CONSTRAINT instrument_alias_fk_instrument - FOREIGN KEY (instrument) - REFERENCES instrument(id); - -ALTER TABLE instrument_alias - ADD CONSTRAINT instrument_alias_fk_type - FOREIGN KEY (type) - REFERENCES instrument_alias_type(id); - -ALTER TABLE instrument_annotation - ADD CONSTRAINT instrument_annotation_fk_instrument - FOREIGN KEY (instrument) - REFERENCES instrument(id); - -ALTER TABLE instrument_annotation - ADD CONSTRAINT instrument_annotation_fk_annotation - FOREIGN KEY (annotation) - REFERENCES annotation(id); - -ALTER TABLE instrument_gid_redirect - ADD CONSTRAINT instrument_gid_redirect_fk_new_id - FOREIGN KEY (new_id) - REFERENCES instrument(id); - -ALTER TABLE l_area_instrument - ADD CONSTRAINT l_area_instrument_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_area_instrument - ADD CONSTRAINT l_area_instrument_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES area(id); - -ALTER TABLE l_area_instrument - ADD CONSTRAINT l_area_instrument_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES instrument(id); - -ALTER TABLE l_artist_instrument - ADD CONSTRAINT l_artist_instrument_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_artist_instrument - ADD CONSTRAINT l_artist_instrument_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES artist(id); - -ALTER TABLE l_artist_instrument - ADD CONSTRAINT l_artist_instrument_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES instrument(id); - -ALTER TABLE l_instrument_instrument - ADD CONSTRAINT l_instrument_instrument_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_instrument_instrument - ADD CONSTRAINT l_instrument_instrument_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES instrument(id); - -ALTER TABLE l_instrument_instrument - ADD CONSTRAINT l_instrument_instrument_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES instrument(id); - -ALTER TABLE l_instrument_label - ADD CONSTRAINT l_instrument_label_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_instrument_label - ADD CONSTRAINT l_instrument_label_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES instrument(id); - -ALTER TABLE l_instrument_label - ADD CONSTRAINT l_instrument_label_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES label(id); - -ALTER TABLE l_instrument_place - ADD CONSTRAINT l_instrument_place_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_instrument_place - ADD CONSTRAINT l_instrument_place_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES instrument(id); - -ALTER TABLE l_instrument_place - ADD CONSTRAINT l_instrument_place_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES place(id); - -ALTER TABLE l_instrument_recording - ADD CONSTRAINT l_instrument_recording_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_instrument_recording - ADD CONSTRAINT l_instrument_recording_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES instrument(id); - -ALTER TABLE l_instrument_recording - ADD CONSTRAINT l_instrument_recording_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES recording(id); - -ALTER TABLE l_instrument_release - ADD CONSTRAINT l_instrument_release_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_instrument_release - ADD CONSTRAINT l_instrument_release_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES instrument(id); - -ALTER TABLE l_instrument_release - ADD CONSTRAINT l_instrument_release_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES release(id); - -ALTER TABLE l_instrument_release_group - ADD CONSTRAINT l_instrument_release_group_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_instrument_release_group - ADD CONSTRAINT l_instrument_release_group_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES instrument(id); - -ALTER TABLE l_instrument_release_group - ADD CONSTRAINT l_instrument_release_group_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES release_group(id); - -ALTER TABLE l_instrument_url - ADD CONSTRAINT l_instrument_url_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_instrument_url - ADD CONSTRAINT l_instrument_url_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES instrument(id); - -ALTER TABLE l_instrument_url - ADD CONSTRAINT l_instrument_url_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES url(id); - -ALTER TABLE l_instrument_work - ADD CONSTRAINT l_instrument_work_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_instrument_work - ADD CONSTRAINT l_instrument_work_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES instrument(id); - -ALTER TABLE l_instrument_work - ADD CONSTRAINT l_instrument_work_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES work(id); - - -CREATE TRIGGER b_upd_instrument BEFORE UPDATE ON instrument - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER end_date_implies_ended BEFORE UPDATE OR INSERT ON instrument_alias - FOR EACH ROW EXECUTE PROCEDURE end_date_implies_ended(); - -CREATE TRIGGER b_upd_instrument_alias BEFORE UPDATE ON instrument_alias - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER unique_primary_for_locale BEFORE UPDATE OR INSERT ON instrument_alias - FOR EACH ROW EXECUTE PROCEDURE unique_primary_instrument_alias(); - -CREATE TRIGGER search_hint BEFORE UPDATE OR INSERT ON instrument_alias - FOR EACH ROW EXECUTE PROCEDURE simplify_search_hints(2); -CREATE TRIGGER b_upd_l_area_instrument BEFORE UPDATE ON l_area_instrument - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_artist_instrument BEFORE UPDATE ON l_artist_instrument - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_instrument_instrument BEFORE UPDATE ON l_instrument_instrument - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_instrument_label BEFORE UPDATE ON l_instrument_label - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_instrument_place BEFORE UPDATE ON l_instrument_place - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_instrument_recording BEFORE UPDATE ON l_instrument_recording - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_instrument_release BEFORE UPDATE ON l_instrument_release - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_instrument_release_group BEFORE UPDATE ON l_instrument_release_group - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_instrument_url BEFORE UPDATE ON l_instrument_url - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_instrument_work BEFORE UPDATE ON l_instrument_work - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER a_ins_instrument AFTER INSERT ON musicbrainz.instrument - FOR EACH ROW EXECUTE PROCEDURE a_ins_instrument(); - -CREATE TRIGGER a_upd_instrument AFTER UPDATE ON musicbrainz.instrument - FOR EACH ROW EXECUTE PROCEDURE a_upd_instrument(); - -CREATE TRIGGER a_del_instrument AFTER DELETE ON musicbrainz.instrument - FOR EACH ROW EXECUTE PROCEDURE a_del_instrument(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_area_instrument DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_artist_instrument DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - - CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_instrument_instrument DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_instrument_label DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_instrument_place DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_instrument_recording DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_instrument_release DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_instrument_release_group DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_instrument_url DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_instrument_work DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER url_gc_a_upd_l_instrument_url - AFTER UPDATE ON l_instrument_url DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_url(); - -CREATE CONSTRAINT TRIGGER url_gc_a_del_l_instrument_url - AFTER DELETE ON l_instrument_url DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_url(); - -ALTER TABLE documentation.l_area_instrument_example - ADD CONSTRAINT l_area_instrument_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_area_instrument(id); - -ALTER TABLE documentation.l_artist_instrument_example - ADD CONSTRAINT l_artist_instrument_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_artist_instrument(id); - -ALTER TABLE documentation.l_instrument_instrument_example - ADD CONSTRAINT l_instrument_instrument_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_instrument_instrument(id); - -ALTER TABLE documentation.l_instrument_label_example - ADD CONSTRAINT l_instrument_label_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_instrument_label(id); - -ALTER TABLE documentation.l_instrument_place_example - ADD CONSTRAINT l_instrument_place_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_instrument_place(id); - -ALTER TABLE documentation.l_instrument_recording_example - ADD CONSTRAINT l_instrument_recording_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_instrument_recording(id); - -ALTER TABLE documentation.l_instrument_release_example - ADD CONSTRAINT l_instrument_release_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_instrument_release(id); - -ALTER TABLE documentation.l_instrument_release_group_example - ADD CONSTRAINT l_instrument_release_group_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_instrument_release_group(id); - -ALTER TABLE documentation.l_instrument_url_example - ADD CONSTRAINT l_instrument_url_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_instrument_url(id); - -ALTER TABLE documentation.l_instrument_work_example - ADD CONSTRAINT l_instrument_work_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_instrument_work(id); - --------------------------------------------------------------------------------- -SELECT '20140318-series-fks.sql'; - ------------------- --- constraints -- ------------------- - -ALTER TABLE series ADD CHECK (controlled_for_whitespace(comment)); - -ALTER TABLE link_attribute_text_value - ADD CONSTRAINT control_for_whitespace CHECK (controlled_for_whitespace(text_value)), - ADD CONSTRAINT only_non_empty CHECK (text_value != ''); - -ALTER TABLE series - ADD CONSTRAINT control_for_whitespace CHECK (controlled_for_whitespace(name)), - ADD CONSTRAINT only_non_empty CHECK (name != ''); - -ALTER TABLE series_type ADD CONSTRAINT allowed_series_entity_type - CHECK ( - entity_type IN ( - 'recording', - 'release', - 'release_group', - 'work' - ) - ); - ------------------- --- foreign keys -- ------------------- - -ALTER TABLE documentation.l_area_series_example ADD CONSTRAINT l_area_series_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_area_series(id); -ALTER TABLE documentation.l_artist_series_example ADD CONSTRAINT l_artist_series_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_artist_series(id); -ALTER TABLE documentation.l_instrument_series_example ADD CONSTRAINT l_instrument_series_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_instrument_series(id); -ALTER TABLE documentation.l_label_series_example ADD CONSTRAINT l_label_series_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_label_series(id); -ALTER TABLE documentation.l_place_series_example ADD CONSTRAINT l_place_series_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_place_series(id); -ALTER TABLE documentation.l_recording_series_example ADD CONSTRAINT l_recording_series_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_recording_series(id); -ALTER TABLE documentation.l_release_group_series_example ADD CONSTRAINT l_release_group_series_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_release_group_series(id); -ALTER TABLE documentation.l_release_series_example ADD CONSTRAINT l_release_series_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_release_series(id); -ALTER TABLE documentation.l_series_series_example ADD CONSTRAINT l_series_series_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_series_series(id); -ALTER TABLE documentation.l_series_url_example ADD CONSTRAINT l_series_url_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_series_url(id); -ALTER TABLE documentation.l_series_work_example ADD CONSTRAINT l_series_work_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_series_work(id); - -ALTER TABLE editor_subscribe_series ADD CONSTRAINT editor_subscribe_series_fk_editor FOREIGN KEY (editor) REFERENCES editor(id); -ALTER TABLE editor_subscribe_series ADD CONSTRAINT editor_subscribe_series_fk_series FOREIGN KEY (series) REFERENCES series(id); -ALTER TABLE editor_subscribe_series ADD CONSTRAINT editor_subscribe_series_fk_last_edit_sent FOREIGN KEY (last_edit_sent) REFERENCES edit(id); - -ALTER TABLE editor_subscribe_series_deleted ADD CONSTRAINT editor_subscribe_series_deleted_fk_editor FOREIGN KEY (editor) REFERENCES editor(id); -ALTER TABLE editor_subscribe_series_deleted ADD CONSTRAINT editor_subscribe_series_deleted_fk_gid FOREIGN KEY (gid) REFERENCES series_deletion(gid); -ALTER TABLE editor_subscribe_series_deleted ADD CONSTRAINT editor_subscribe_series_deleted_fk_deleted_by FOREIGN KEY (deleted_by) REFERENCES edit(id); - -ALTER TABLE l_area_series ADD CONSTRAINT l_area_series_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_area_series ADD CONSTRAINT l_area_series_fk_entity0 FOREIGN KEY (entity0) REFERENCES area(id); -ALTER TABLE l_area_series ADD CONSTRAINT l_area_series_fk_entity1 FOREIGN KEY (entity1) REFERENCES series(id); - -ALTER TABLE l_artist_series ADD CONSTRAINT l_artist_series_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_artist_series ADD CONSTRAINT l_artist_series_fk_entity0 FOREIGN KEY (entity0) REFERENCES artist(id); -ALTER TABLE l_artist_series ADD CONSTRAINT l_artist_series_fk_entity1 FOREIGN KEY (entity1) REFERENCES series(id); - -ALTER TABLE l_instrument_series ADD CONSTRAINT l_instrument_series_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_instrument_series ADD CONSTRAINT l_instrument_series_fk_entity0 FOREIGN KEY (entity0) REFERENCES instrument(id); -ALTER TABLE l_instrument_series ADD CONSTRAINT l_instrument_series_fk_entity1 FOREIGN KEY (entity1) REFERENCES series(id); - -ALTER TABLE l_label_series ADD CONSTRAINT l_label_series_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_label_series ADD CONSTRAINT l_label_series_fk_entity0 FOREIGN KEY (entity0) REFERENCES label(id); -ALTER TABLE l_label_series ADD CONSTRAINT l_label_series_fk_entity1 FOREIGN KEY (entity1) REFERENCES series(id); - -ALTER TABLE l_place_series ADD CONSTRAINT l_place_series_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_place_series ADD CONSTRAINT l_place_series_fk_entity0 FOREIGN KEY (entity0) REFERENCES place(id); -ALTER TABLE l_place_series ADD CONSTRAINT l_place_series_fk_entity1 FOREIGN KEY (entity1) REFERENCES series(id); - -ALTER TABLE l_recording_series ADD CONSTRAINT l_recording_series_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_recording_series ADD CONSTRAINT l_recording_series_fk_entity0 FOREIGN KEY (entity0) REFERENCES recording(id); -ALTER TABLE l_recording_series ADD CONSTRAINT l_recording_series_fk_entity1 FOREIGN KEY (entity1) REFERENCES series(id); - -ALTER TABLE l_release_group_series ADD CONSTRAINT l_release_group_series_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_release_group_series ADD CONSTRAINT l_release_group_series_fk_entity0 FOREIGN KEY (entity0) REFERENCES release_group(id); -ALTER TABLE l_release_group_series ADD CONSTRAINT l_release_group_series_fk_entity1 FOREIGN KEY (entity1) REFERENCES series(id); - -ALTER TABLE l_release_series ADD CONSTRAINT l_release_series_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_release_series ADD CONSTRAINT l_release_series_fk_entity0 FOREIGN KEY (entity0) REFERENCES release(id); -ALTER TABLE l_release_series ADD CONSTRAINT l_release_series_fk_entity1 FOREIGN KEY (entity1) REFERENCES series(id); - -ALTER TABLE l_series_series ADD CONSTRAINT l_series_series_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_series_series ADD CONSTRAINT l_series_series_fk_entity0 FOREIGN KEY (entity0) REFERENCES series(id); -ALTER TABLE l_series_series ADD CONSTRAINT l_series_series_fk_entity1 FOREIGN KEY (entity1) REFERENCES series(id); - -ALTER TABLE l_series_url ADD CONSTRAINT l_series_url_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_series_url ADD CONSTRAINT l_series_url_fk_entity0 FOREIGN KEY (entity0) REFERENCES series(id); -ALTER TABLE l_series_url ADD CONSTRAINT l_series_url_fk_entity1 FOREIGN KEY (entity1) REFERENCES url(id); - -ALTER TABLE l_series_work ADD CONSTRAINT l_series_work_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_series_work ADD CONSTRAINT l_series_work_fk_entity0 FOREIGN KEY (entity0) REFERENCES series(id); -ALTER TABLE l_series_work ADD CONSTRAINT l_series_work_fk_entity1 FOREIGN KEY (entity1) REFERENCES work(id); - -ALTER TABLE link_attribute_text_value ADD CONSTRAINT link_attribute_text_value_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE link_attribute_text_value ADD CONSTRAINT link_attribute_text_value_fk_attribute_type FOREIGN KEY (attribute_type) REFERENCES link_text_attribute_type(attribute_type); -ALTER TABLE link_text_attribute_type ADD CONSTRAINT link_text_attribute_type_fk_attribute_type FOREIGN KEY (attribute_type) REFERENCES link_attribute_type(id) ON DELETE CASCADE; - -ALTER TABLE orderable_link_type ADD CONSTRAINT orderable_link_type_fk_link_type FOREIGN KEY (link_type) REFERENCES link_type(id); - -ALTER TABLE series ADD CONSTRAINT series_fk_type FOREIGN KEY (type) REFERENCES series_type(id); -ALTER TABLE series ADD CONSTRAINT series_fk_ordering_attribute FOREIGN KEY (ordering_attribute) REFERENCES link_text_attribute_type(attribute_type); -ALTER TABLE series ADD CONSTRAINT series_fk_ordering_type FOREIGN KEY (ordering_type) REFERENCES series_ordering_type(id); - -ALTER TABLE series_alias ADD CONSTRAINT series_alias_fk_series FOREIGN KEY (series) REFERENCES series(id); -ALTER TABLE series_alias ADD CONSTRAINT series_alias_fk_type FOREIGN KEY (type) REFERENCES series_alias_type(id); - -ALTER TABLE series_annotation ADD CONSTRAINT series_annotation_fk_series FOREIGN KEY (series) REFERENCES series(id); -ALTER TABLE series_annotation ADD CONSTRAINT series_annotation_fk_annotation FOREIGN KEY (annotation) REFERENCES annotation(id); - -ALTER TABLE series_gid_redirect ADD CONSTRAINT series_gid_redirect_fk_new_id FOREIGN KEY (new_id) REFERENCES series(id); - -ALTER TABLE series_ordering_type ADD CONSTRAINT series_ordering_type_fk_parent FOREIGN KEY (parent) REFERENCES series_ordering_type(id); - -ALTER TABLE series_type ADD CONSTRAINT series_type_fk_parent FOREIGN KEY (parent) REFERENCES series_type(id); - -COMMIT; diff --git a/mbdata/sql/updates/schema-change/21.mirror.sql b/mbdata/sql/updates/schema-change/21.mirror.sql deleted file mode 100644 index d4df492..0000000 --- a/mbdata/sql/updates/schema-change/21.mirror.sql +++ /dev/null @@ -1,1160 +0,0 @@ --- Generated by CompileSchemaScripts.pl from: --- 20140606-events.sql --- 20141008-instrument-indexes.sql --- 20141014-mbs-7784-data-tracks.sql --- 20140806-collection-types.sql --- 20140906-event-collections.sql --- 20141014-mbs-7551-tags.sql --- 20141031-unused-url.sql -\set ON_ERROR_STOP 1 -BEGIN; -SET search_path = musicbrainz, public; -SET LOCAL statement_timeout = 0; --------------------------------------------------------------------------------- -SELECT '20140606-events.sql'; - ------------------------ --- CREATE NEW TABLES -- ------------------------ - -CREATE TABLE edit_event -( - edit INTEGER NOT NULL, -- PK, references edit.id - event INTEGER NOT NULL -- PK, references event.id CASCADE -); - -CREATE TABLE event ( -- replicate (verbose) - id SERIAL, - gid UUID NOT NULL, - name VARCHAR NOT NULL, - begin_date_year SMALLINT, - begin_date_month SMALLINT, - begin_date_day SMALLINT, - end_date_year SMALLINT, - end_date_month SMALLINT, - end_date_day SMALLINT, - time TIME WITHOUT TIME ZONE, - type INTEGER, -- references event_type.id - cancelled BOOLEAN NOT NULL DEFAULT FALSE, - setlist TEXT, - comment VARCHAR(255) NOT NULL DEFAULT '', - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - ended BOOLEAN NOT NULL DEFAULT FALSE - CONSTRAINT event_ended_check CHECK ( - ( - -- If any end date fields are not null, then ended must be true - (end_date_year IS NOT NULL OR - end_date_month IS NOT NULL OR - end_date_day IS NOT NULL) AND - ended = TRUE - ) OR ( - -- Otherwise, all end date fields must be null - (end_date_year IS NULL AND - end_date_month IS NULL AND - end_date_day IS NULL) - ) - ) -); - -CREATE TABLE event_meta ( -- replicate - id INTEGER NOT NULL, -- PK, references event.id CASCADE - rating SMALLINT CHECK (rating >= 0 AND rating <= 100), - rating_count INTEGER -); - -CREATE TABLE event_rating_raw ( - event INTEGER NOT NULL, -- PK, references event.id - editor INTEGER NOT NULL, -- PK, references editor.id - rating SMALLINT NOT NULL CHECK (rating >= 0 AND rating <= 100) -); - -CREATE TABLE event_tag_raw ( - event INTEGER NOT NULL, -- PK, references event.id - editor INTEGER NOT NULL, -- PK, references editor.id - tag INTEGER NOT NULL -- PK, references tag.id -); - -CREATE TABLE event_alias_type ( -- replicate - id SERIAL, - name TEXT NOT NULL, - parent INTEGER, -- references event_alias_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT -); - -CREATE TABLE event_alias ( -- replicate (verbose) - id SERIAL, - event INTEGER NOT NULL, -- references event.id - name VARCHAR NOT NULL, - locale TEXT, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - type INTEGER, -- references event_alias_type.id - sort_name VARCHAR NOT NULL, - begin_date_year SMALLINT, - begin_date_month SMALLINT, - begin_date_day SMALLINT, - end_date_year SMALLINT, - end_date_month SMALLINT, - end_date_day SMALLINT, - primary_for_locale BOOLEAN NOT NULL DEFAULT false, - ended BOOLEAN NOT NULL DEFAULT FALSE - CHECK ( - ( - -- If any end date fields are not null, then ended must be true - (end_date_year IS NOT NULL OR - end_date_month IS NOT NULL OR - end_date_day IS NOT NULL) AND - ended = TRUE - ) OR ( - -- Otherwise, all end date fields must be null - (end_date_year IS NULL AND - end_date_month IS NULL AND - end_date_day IS NULL) - ) - ), - CONSTRAINT primary_check CHECK ((locale IS NULL AND primary_for_locale IS FALSE) OR (locale IS NOT NULL)), - CONSTRAINT search_hints_are_empty - CHECK ( - (type <> 2) OR ( - type = 2 AND sort_name = name AND - begin_date_year IS NULL AND begin_date_month IS NULL AND begin_date_day IS NULL AND - end_date_year IS NULL AND end_date_month IS NULL AND end_date_day IS NULL AND - primary_for_locale IS FALSE AND locale IS NULL - ) - ) -); - -CREATE TABLE event_annotation ( -- replicate (verbose) - event INTEGER NOT NULL, -- PK, references event.id - annotation INTEGER NOT NULL -- PK, references annotation.id -); - -CREATE TABLE event_gid_redirect ( -- replicate (verbose) - gid UUID NOT NULL, -- PK - new_id INTEGER NOT NULL, -- references event.id - created TIMESTAMP WITH TIME ZONE DEFAULT NOW() -); - -CREATE TABLE event_tag ( -- replicate (verbose) - event INTEGER NOT NULL, -- PK, references event.id - tag INTEGER NOT NULL, -- PK, references tag.id - count INTEGER NOT NULL, - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW() -); - -CREATE TABLE event_type ( -- replicate - id SERIAL, - name VARCHAR(255) NOT NULL, - parent INTEGER, -- references event_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT -); - -CREATE TABLE l_area_event ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references area.id - entity1 INTEGER NOT NULL, -- references event.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_artist_event ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references artist.id - entity1 INTEGER NOT NULL, -- references event.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_event_event ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references event.id - entity1 INTEGER NOT NULL, -- references event.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_event_instrument ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references event.id - entity1 INTEGER NOT NULL, -- references instrument.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_event_label ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references event.id - entity1 INTEGER NOT NULL, -- references label.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_event_place ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references event.id - entity1 INTEGER NOT NULL, -- references place.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_event_recording ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references event.id - entity1 INTEGER NOT NULL, -- references recording.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_event_release ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references event.id - entity1 INTEGER NOT NULL, -- references release.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_event_release_group ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references event.id - entity1 INTEGER NOT NULL, -- references release_group.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_event_series ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references event.id - entity1 INTEGER NOT NULL, -- references series.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_event_url ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references event.id - entity1 INTEGER NOT NULL, -- references url.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE l_event_work ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references event.id - entity1 INTEGER NOT NULL, -- references work.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0) -); - -CREATE TABLE documentation.l_area_event_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_area_event.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_artist_event_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_artist_event.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_event_event_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_event_event.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_event_instrument_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_event_instrument.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_event_label_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_event_label.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_event_place_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_event_place.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_event_recording_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_event_recording.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_event_release_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_event_release.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_event_release_group_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_event_release_group.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_event_series_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_event_series.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_event_url_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_event_url.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_event_work_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_event_work.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - ------------------------ --- CREATE NEW VIEWS -- ------------------------ - -CREATE OR REPLACE VIEW event_series AS - SELECT entity0 AS event, - entity1 AS series, - lrs.id AS relationship, - link_order, - lrs.link, - COALESCE(text_value, '') AS text_value - FROM l_event_series lrs - JOIN series s ON s.id = lrs.entity1 - JOIN link l ON l.id = lrs.link - JOIN link_type lt ON (lt.id = l.link_type AND lt.gid = '707d947d-9563-328a-9a7d-0c5b9c3a9791') - LEFT OUTER JOIN link_attribute_text_value latv ON (latv.attribute_type = s.ordering_attribute AND latv.link = l.id) - ORDER BY series, link_order; - -------------------------- --- INSERT INITIAL DATA -- -------------------------- - -SELECT setval('link_type_id_seq', (SELECT MAX(id) FROM link_type)); -SELECT setval('link_attribute_type_id_seq', (SELECT MAX(id) FROM link_attribute_type)); - --- new relationship types --- URL rels -INSERT INTO link_type (gid, entity_type0, entity_type1, name, description, link_phrase, reverse_link_phrase, long_link_phrase, priority, entity0_cardinality, entity1_cardinality) VALUES - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/event/url/official_homepage'), 'event', 'url', 'official homepage', 'Indicates the official homepage for an event.', 'official homepages', 'official homepage for', 'has an official homepage at', 0, 0, 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/event/url/social_network'), 'event', 'url', 'social network', 'This link is used to associate an event with its page on a social networking site such as Facebook or Twitter.', 'social networking', 'social networking page for', 'has a social networking page at', 0, 0, 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/series/url/social_network'), 'series', 'url', 'social network', 'This link is used to associate a series with its page on a social networking site such as Facebook or Twitter.', 'social networking', 'social networking page for', 'has a social networking page at', 0, 0, 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/artist/url/songkick'), 'artist', 'url', 'songkick', 'This relationship type links an artist to its corresponding page at Songkick.', 'Songkick', 'Songkick page for', 'has a Songkick page at', 0, 0, 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/event/url/songkick'), 'event', 'url', 'songkick', 'This relationship type links an event to its corresponding page at Songkick.', 'Songkick', 'Songkick page for', 'has a Songkick page at', 0, 0, 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/place/url/songkick'), 'place', 'url', 'songkick', 'This relationship type links a place to its corresponding page at Songkick.', 'Songkick', 'Songkick page for', 'has a Songkick page at', 0, 0, 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/event/url/vgmdb'), 'event', 'url', 'vgmdb', 'This relationship type links an event to its corresponding page at VGMdb. VGMdb is a community project dedicated to cataloguing the music of video games and anime.', 'VGMdb', 'VGMdb page for', 'has a VGMdb page at', 0, 0, 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/event/url/wikipedia'), 'event', 'url', 'wikipedia', 'Points to the Wikipedia page for this event.', 'Wikipedia', 'Wikipedia page for', 'has a Wikipedia page at', 0, 0, 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/event/url/wikidata'), 'event', 'url', 'wikidata', 'Points to the Wikidata page for this event.', 'Wikidata', 'Wikidata page for', 'has a Wikidata page at', 0, 0, 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/event/url/youtube'), 'event', 'url', 'youtube', 'This relationship type can be used to link an event to the equivalent entry in YouTube. URLs should follow the format http://www.youtube.com/user/<username>', 'YouTube channels', 'YouTube channel for', 'has an official YouTube channel at', 0, 0, 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/series/url/youtube'), 'series', 'url', 'youtube', 'This relationship type can be used to link a series to the equivalent entry in YouTube. URLs should follow the format http://www.youtube.com/user/<username>', 'YouTube channels', 'YouTube channel for', 'has an official YouTube channel at', 0, 0, 0), - --- Entity rels - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/area/event/held_in'), 'area', 'event', 'held in', 'Links an event to the area where it was held. Use only if the exact place is unknown.', 'held events', 'held in', 'held the event', 0, 1, 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/event/place/held_at'), 'event', 'place', 'held at', 'Links an event to the place where it was held.', 'held at', 'held events', 'was held at', 0, 0, 1), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/event/release/available_at'), 'event', 'release', 'available at', 'Links a release with an event where it was available. This is intended for event-exclusive releases and/or releases available at events before the official launch date, not for every release in the merchandise stall.', 'available releases', 'available at', 'had available releases', 0, 0, 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/event/release/launch_event'), 'event', 'release', 'launch event', 'Links a release with a launch event for it.', 'launch event for', 'launch events', 'was a launch event for', 0, 0, 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/event/release_group/launch_event'), 'event', 'release_group', 'launch event', 'Links a release group with a launch event for it.', 'launch event for', 'launch events', 'was a launch event for', 0, 0, 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/artist/event/main_performer'), 'artist', 'event', 'main performer', 'Links an event to (one of) its main performer(s).', 'main performer at', 'main performers', 'was a main performer at', 0, 1, 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/artist/event/support_act'), 'artist', 'event', 'support act', 'Links an event to (one of) its support act(s).', 'support act at', 'support acts', 'was a support act at', 0, 1, 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/artist/event/guest_performer'), 'artist', 'event', 'guest performer', 'Links an event to a guest performer. Guest performers usually make short appearances during other artist''s set.', 'guest performer at', 'guest performers', 'guest performer at', 0, 1, 0), - (generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/artist/event/host'), 'artist', 'event', 'host', 'Links an event to its host/MC. Event hosts usually do introductions to the show or each song.', 'host at', 'hosts', 'host at', 0, 1, 0); - --- Part-of-series rel - -\set EVENT_PART_OF_SERIES_GID 'generate_uuid_v3(''6ba7b8119dad11d180b400c04fd430c8'', ''http://musicbrainz.org/linktype/event/series/part_of'')' - -INSERT INTO link_type (gid, entity_type0, entity_type1, entity0_cardinality, - entity1_cardinality, name, description, link_phrase, - reverse_link_phrase, long_link_phrase) VALUES - ( - :EVENT_PART_OF_SERIES_GID, - 'event', 'series', 0, 0, 'part of', - 'Indicates that the event is part of a series.', - 'part of', 'has parts', 'is a part of' - ) - RETURNING id, gid, entity_type0, entity_type1, name, long_link_phrase; - -INSERT INTO orderable_link_type (link_type, direction) VALUES - ((SELECT id FROM link_type WHERE gid = :EVENT_PART_OF_SERIES_GID), 2); - -ALTER TABLE series_type DROP CONSTRAINT IF EXISTS allowed_series_entity_type; - -INSERT INTO series_type (id, name, entity_type, parent, child_order, description) VALUES - (6, 'Event', 'event', NULL, 5, 'Indicates that the series is of events.'), - (7, 'Tour', 'event', 6, 0, 'Indicates a series of related concerts by an artist in different locations.'), - (8, 'Festival', 'event', 6, 1, 'Indicates a recurring festival, usually happening anually in the same location.'), - (9, 'Run', 'event', 6, 2, 'Indicates a series of performances of the same show at the same place.'); - -INSERT INTO event_alias_type (name) VALUES ('Event name'), ('Search hint'); - -INSERT INTO link_type_attribute_type (link_type, attribute_type, min, max) VALUES - ((SELECT id FROM link_type WHERE gid = :EVENT_PART_OF_SERIES_GID), - (SELECT id FROM link_attribute_type WHERE gid = 'a59c5830-5ec7-38fe-9a21-c7ea54f6650a'), - 0, 1 - ); - -\unset EVENT_PART_OF_SERIES_GID - --- Event types -INSERT INTO event_type (id, name, parent, child_order, description) VALUES - (1, 'Concert', NULL, 1, 'An individual concert by a single artist or collaboration, often with supporting artists who perform before the main act.'), - (2, 'Festival', NULL, 2, 'An event where a number of different acts perform across the course of the day. Larger festivals may be spread across multiple days.'), - (3, 'Launch event', NULL, 3, 'A party, reception or other event held specifically for the launch of a release'), - (4, 'Convention/Expo', NULL, 4, 'A convention, expo or trade fair is an event which is not typically orientated around music performances, but can include them as side activities'); - --------------------- --- CREATE INDEXES -- --------------------- - -ALTER TABLE documentation.l_area_event_example ADD CONSTRAINT l_area_event_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_artist_event_example ADD CONSTRAINT l_artist_event_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_event_event_example ADD CONSTRAINT l_event_event_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_event_instrument_example ADD CONSTRAINT l_event_instrument_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_event_label_example ADD CONSTRAINT l_event_label_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_event_place_example ADD CONSTRAINT l_event_place_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_event_recording_example ADD CONSTRAINT l_event_recording_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_event_release_group_example ADD CONSTRAINT l_event_release_group_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_event_release_example ADD CONSTRAINT l_event_release_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_event_series_example ADD CONSTRAINT l_event_series_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_event_url_example ADD CONSTRAINT l_event_url_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_event_work_example ADD CONSTRAINT l_event_work_example_pkey PRIMARY KEY (id); - -ALTER TABLE l_area_event ADD CONSTRAINT l_area_event_pkey PRIMARY KEY (id); -ALTER TABLE l_artist_event ADD CONSTRAINT l_artist_event_pkey PRIMARY KEY (id); -ALTER TABLE l_event_event ADD CONSTRAINT l_event_event_pkey PRIMARY KEY (id); -ALTER TABLE l_event_instrument ADD CONSTRAINT l_event_instrument_pkey PRIMARY KEY (id); -ALTER TABLE l_event_label ADD CONSTRAINT l_event_label_pkey PRIMARY KEY (id); -ALTER TABLE l_event_place ADD CONSTRAINT l_event_place_pkey PRIMARY KEY (id); -ALTER TABLE l_event_recording ADD CONSTRAINT l_event_recording_pkey PRIMARY KEY (id); -ALTER TABLE l_event_release_group ADD CONSTRAINT l_event_release_group_pkey PRIMARY KEY (id); -ALTER TABLE l_event_release ADD CONSTRAINT l_event_release_pkey PRIMARY KEY (id); -ALTER TABLE l_event_series ADD CONSTRAINT l_event_series_pkey PRIMARY KEY (id); -ALTER TABLE l_event_url ADD CONSTRAINT l_event_url_pkey PRIMARY KEY (id); -ALTER TABLE l_event_work ADD CONSTRAINT l_event_work_pkey PRIMARY KEY (id); - -ALTER TABLE edit_event ADD CONSTRAINT edit_event_pkey PRIMARY KEY (edit, event); - -ALTER TABLE event ADD CONSTRAINT event_pkey PRIMARY KEY (id); -ALTER TABLE event_alias ADD CONSTRAINT event_alias_pkey PRIMARY KEY (id); -ALTER TABLE event_alias_type ADD CONSTRAINT event_alias_type_pkey PRIMARY KEY (id); -ALTER TABLE event_annotation ADD CONSTRAINT event_annotation_pkey PRIMARY KEY (event, annotation); -ALTER TABLE event_gid_redirect ADD CONSTRAINT event_gid_redirect_pkey PRIMARY KEY (gid); -ALTER TABLE event_meta ADD CONSTRAINT event_meta_pkey PRIMARY KEY (id); -ALTER TABLE event_rating_raw ADD CONSTRAINT event_rating_raw_pkey PRIMARY KEY (event, editor); -ALTER TABLE event_tag ADD CONSTRAINT event_tag_pkey PRIMARY KEY (event, tag); -ALTER TABLE event_tag_raw ADD CONSTRAINT event_tag_raw_pkey PRIMARY KEY (event, editor, tag); -ALTER TABLE event_type ADD CONSTRAINT event_type_pkey PRIMARY KEY (id); - -CREATE UNIQUE INDEX l_area_event_idx_uniq ON l_area_event (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_artist_event_idx_uniq ON l_artist_event (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_event_event_idx_uniq ON l_event_event (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_event_instrument_idx_uniq ON l_event_instrument (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_event_label_idx_uniq ON l_event_label (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_event_place_idx_uniq ON l_event_place (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_event_recording_idx_uniq ON l_event_recording (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_event_release_idx_uniq ON l_event_release (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_event_release_group_idx_uniq ON l_event_release_group (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_event_series_idx_uniq ON l_event_series (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_event_url_idx_uniq ON l_event_url (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_event_work_idx_uniq ON l_event_work (entity0, entity1, link, link_order); - -CREATE INDEX l_area_event_idx_entity1 ON l_area_event (entity1); -CREATE INDEX l_artist_event_idx_entity1 ON l_artist_event (entity1); -CREATE INDEX l_event_event_idx_entity1 ON l_event_event (entity1); -CREATE INDEX l_event_instrument_idx_entity1 ON l_event_instrument (entity1); -CREATE INDEX l_event_label_idx_entity1 ON l_event_label (entity1); -CREATE INDEX l_event_place_idx_entity1 ON l_event_place (entity1); -CREATE INDEX l_event_recording_idx_entity1 ON l_event_recording (entity1); -CREATE INDEX l_event_release_idx_entity1 ON l_event_release (entity1); -CREATE INDEX l_event_release_group_idx_entity1 ON l_event_release_group (entity1); -CREATE INDEX l_event_series_idx_entity1 ON l_event_series (entity1); -CREATE INDEX l_event_url_idx_entity1 ON l_event_url (entity1); -CREATE INDEX l_event_work_idx_entity1 ON l_event_work (entity1); - -CREATE UNIQUE INDEX event_idx_gid ON event (gid); -CREATE INDEX event_idx_name ON event (name); - -CREATE INDEX event_alias_idx_event ON event_alias (event); -CREATE UNIQUE INDEX event_alias_idx_primary ON event_alias (event, locale) WHERE primary_for_locale = TRUE AND locale IS NOT NULL; - -CREATE INDEX event_rating_raw_idx_event ON event_rating_raw (event); -CREATE INDEX event_rating_raw_idx_editor ON event_rating_raw (editor); - -CREATE INDEX event_tag_idx_tag ON event_tag (tag); - -CREATE INDEX event_tag_raw_idx_tag ON event_tag_raw (tag); -CREATE INDEX event_tag_raw_idx_editor ON event_tag_raw (editor); - -CREATE INDEX edit_event_idx ON edit_event (event); - ---------------------- --- UPDATE FUNCTIONS-- ---------------------- - -CREATE OR REPLACE FUNCTION empty_artists() RETURNS SETOF int AS -$BODY$ - SELECT id FROM artist - WHERE - id > 2 AND - edits_pending = 0 AND - ( - last_updated < now() - '1 day'::interval OR last_updated is NULL - ) - EXCEPT - SELECT artist FROM edit_artist WHERE edit_artist.status = 1 - EXCEPT - SELECT artist FROM artist_credit_name - EXCEPT - SELECT entity1 FROM l_area_artist - EXCEPT - SELECT entity0 FROM l_artist_artist - EXCEPT - SELECT entity1 FROM l_artist_artist - EXCEPT - SELECT entity0 FROM l_artist_event - EXCEPT - SELECT entity0 FROM l_artist_instrument - EXCEPT - SELECT entity0 FROM l_artist_label - EXCEPT - SELECT entity0 FROM l_artist_place - EXCEPT - SELECT entity0 FROM l_artist_recording - EXCEPT - SELECT entity0 FROM l_artist_release - EXCEPT - SELECT entity0 FROM l_artist_release_group - EXCEPT - SELECT entity0 FROM l_artist_series - EXCEPT - SELECT entity0 FROM l_artist_url - EXCEPT - SELECT entity0 FROM l_artist_work; -$BODY$ -LANGUAGE 'sql'; - -CREATE OR REPLACE FUNCTION empty_labels() RETURNS SETOF int AS -$BODY$ - SELECT id FROM label - WHERE - id > 1 AND - edits_pending = 0 AND - ( - last_updated < now() - '1 day'::interval OR last_updated is NULL - ) - EXCEPT - SELECT label FROM edit_label WHERE edit_label.status = 1 - EXCEPT - SELECT label FROM release_label - EXCEPT - SELECT entity1 FROM l_area_label - EXCEPT - SELECT entity1 FROM l_artist_label - EXCEPT - SELECT entity1 FROM l_event_label - EXCEPT - SELECT entity1 FROM l_instrument_label - EXCEPT - SELECT entity1 FROM l_label_label - EXCEPT - SELECT entity0 FROM l_label_label - EXCEPT - SELECT entity0 FROM l_label_place - EXCEPT - SELECT entity0 FROM l_label_recording - EXCEPT - SELECT entity0 FROM l_label_release - EXCEPT - SELECT entity0 FROM l_label_release_group - EXCEPT - SELECT entity0 FROM l_label_series - EXCEPT - SELECT entity0 FROM l_label_url - EXCEPT - SELECT entity0 FROM l_label_work; -$BODY$ -LANGUAGE 'sql'; - -CREATE OR REPLACE FUNCTION empty_release_groups() RETURNS SETOF int AS -$BODY$ - SELECT id FROM release_group - WHERE - edits_pending = 0 AND - ( - last_updated < now() - '1 day'::interval OR last_updated is NULL - ) - EXCEPT - SELECT release_group - FROM edit_release_group - JOIN edit ON (edit.id = edit_release_group.edit) - WHERE edit.status = 1 - EXCEPT - SELECT release_group FROM release - EXCEPT - SELECT entity1 FROM l_area_release_group - EXCEPT - SELECT entity1 FROM l_artist_release_group - EXCEPT - SELECT entity1 FROM l_event_release_group - EXCEPT - SELECT entity1 FROM l_instrument_release_group - EXCEPT - SELECT entity1 FROM l_label_release_group - EXCEPT - SELECT entity1 FROM l_place_release_group - EXCEPT - SELECT entity1 FROM l_recording_release_group - EXCEPT - SELECT entity1 FROM l_release_release_group - EXCEPT - SELECT entity1 FROM l_release_group_release_group - EXCEPT - SELECT entity0 FROM l_release_group_release_group - EXCEPT - SELECT entity0 FROM l_release_group_series - EXCEPT - SELECT entity0 FROM l_release_group_url - EXCEPT - SELECT entity0 FROM l_release_group_work; -$BODY$ -LANGUAGE 'sql'; - -CREATE OR REPLACE FUNCTION empty_works() RETURNS SETOF int AS -$BODY$ - SELECT id FROM work - WHERE - edits_pending = 0 AND - ( - last_updated < now() - '1 day'::interval OR last_updated is NULL - ) - EXCEPT - SELECT work - FROM edit_work - JOIN edit ON (edit.id = edit_work.edit) - WHERE edit.status = 1 - EXCEPT - SELECT entity1 FROM l_area_work - EXCEPT - SELECT entity1 FROM l_artist_work - EXCEPT - SELECT entity1 FROM l_event_work - EXCEPT - SELECT entity1 FROM l_instrument_work - EXCEPT - SELECT entity1 FROM l_label_work - EXCEPT - SELECT entity1 FROM l_place_work - EXCEPT - SELECT entity1 FROM l_recording_work - EXCEPT - SELECT entity1 FROM l_release_work - EXCEPT - SELECT entity1 FROM l_release_group_work - EXCEPT - SELECT entity1 FROM l_series_work - EXCEPT - SELECT entity1 FROM l_url_work - EXCEPT - SELECT entity1 FROM l_work_work - EXCEPT - SELECT entity0 FROM l_work_work; -$BODY$ -LANGUAGE 'sql'; - -CREATE OR REPLACE FUNCTION empty_places() RETURNS SETOF int AS -$BODY$ - SELECT id FROM place - WHERE - edits_pending = 0 AND - ( - last_updated < now() - '1 day'::interval OR last_updated is NULL - ) - EXCEPT - SELECT place - FROM edit_place - JOIN edit ON (edit.id = edit_place.edit) - WHERE edit.status = 1 - EXCEPT - SELECT entity1 FROM l_area_place - EXCEPT - SELECT entity1 FROM l_artist_place - EXCEPT - SELECT entity1 FROM l_event_place - EXCEPT - SELECT entity1 FROM l_instrument_place - EXCEPT - SELECT entity1 FROM l_label_place - EXCEPT - SELECT entity1 FROM l_place_place - EXCEPT - SELECT entity0 FROM l_place_place - EXCEPT - SELECT entity0 FROM l_place_recording - EXCEPT - SELECT entity0 FROM l_place_release - EXCEPT - SELECT entity0 FROM l_place_release_group - EXCEPT - SELECT entity0 FROM l_place_series - EXCEPT - SELECT entity0 FROM l_place_url - EXCEPT - SELECT entity0 FROM l_place_work; -$BODY$ -LANGUAGE 'sql'; - -CREATE OR REPLACE FUNCTION empty_series() RETURNS SETOF int AS -$BODY$ - SELECT id FROM series - WHERE - edits_pending = 0 AND - ( - last_updated < now() - '1 day'::interval OR last_updated is NULL - ) - EXCEPT - SELECT series - FROM edit_series - JOIN edit ON (edit.id = edit_series.edit) - WHERE edit.status = 1 - EXCEPT - SELECT entity1 FROM l_area_series - EXCEPT - SELECT entity1 FROM l_artist_series - EXCEPT - SELECT entity1 FROM l_event_series - EXCEPT - SELECT entity1 FROM l_instrument_series - EXCEPT - SELECT entity1 FROM l_label_series - EXCEPT - SELECT entity1 FROM l_place_series - EXCEPT - SELECT entity1 FROM l_recording_series - EXCEPT - SELECT entity1 FROM l_release_series - EXCEPT - SELECT entity1 FROM l_release_group_series - EXCEPT - SELECT entity0 FROM l_series_series - EXCEPT - SELECT entity1 FROM l_series_series - EXCEPT - SELECT entity0 FROM l_series_url - EXCEPT - SELECT entity0 FROM l_series_work; -$BODY$ -LANGUAGE 'sql'; - -CREATE OR REPLACE FUNCTION empty_events() RETURNS SETOF int AS -$BODY$ - SELECT id FROM event - WHERE - edits_pending = 0 AND - ( - last_updated < now() - '1 day'::interval OR last_updated is NULL - ) - EXCEPT - SELECT event - FROM edit_event - JOIN edit ON (edit.id = edit_event.edit) - WHERE edit.status = 1 - EXCEPT - SELECT entity1 FROM l_area_event - EXCEPT - SELECT entity1 FROM l_artist_event - EXCEPT - SELECT entity1 FROM l_event_event - EXCEPT - SELECT entity0 FROM l_event_event - EXCEPT - SELECT entity0 FROM l_event_instrument - EXCEPT - SELECT entity0 FROM l_event_label - EXCEPT - SELECT entity0 FROM l_event_place - EXCEPT - SELECT entity0 FROM l_event_recording - EXCEPT - SELECT entity0 FROM l_event_release - EXCEPT - SELECT entity0 FROM l_event_release_group - EXCEPT - SELECT entity0 FROM l_event_series - EXCEPT - SELECT entity0 FROM l_event_url - EXCEPT - SELECT entity0 FROM l_event_work; -$BODY$ -LANGUAGE 'sql'; - -CREATE OR REPLACE FUNCTION delete_unused_url(ids INTEGER[]) -RETURNS VOID AS $$ -DECLARE - clear_up INTEGER[]; -BEGIN - SELECT ARRAY( - SELECT id FROM url url_row WHERE id = any(ids) - AND NOT ( - EXISTS ( - SELECT TRUE FROM l_area_url - WHERE entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_artist_url - WHERE entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_event_url - WHERE entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_instrument_url - WHERE entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_label_url - WHERE entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_place_url - WHERE entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_recording_url - WHERE entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_release_url - WHERE entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_release_group_url - WHERE entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_series_url - WHERE entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_url_url - WHERE entity0 = url_row.id OR entity1 = url_row.id - LIMIT 1 - ) OR - EXISTS ( - SELECT TRUE FROM l_url_work - WHERE entity0 = url_row.id - LIMIT 1 - ) - ) - ) INTO clear_up; - - DELETE FROM url_gid_redirect WHERE new_id = any(clear_up); - DELETE FROM url WHERE id = any(clear_up); -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION delete_orphaned_recordings() -RETURNS TRIGGER -AS $$ - BEGIN - PERFORM TRUE - FROM recording outer_r - WHERE id = OLD.recording - AND edits_pending = 0 - AND NOT EXISTS ( - SELECT TRUE - FROM edit JOIN edit_recording er ON edit.id = er.edit - WHERE er.recording = outer_r.id - AND type IN (71, 207, 218) - LIMIT 1 - ) AND NOT EXISTS ( - SELECT TRUE FROM track WHERE track.recording = outer_r.id LIMIT 1 - ) AND NOT EXISTS ( - SELECT TRUE FROM l_area_recording WHERE entity1 = outer_r.id - UNION ALL - SELECT TRUE FROM l_artist_recording WHERE entity1 = outer_r.id - UNION ALL - SELECT TRUE FROM l_event_recording WHERE entity1 = outer_r.id - UNION ALL - SELECT TRUE FROM l_instrument_recording WHERE entity1 = outer_r.id - UNION ALL - SELECT TRUE FROM l_label_recording WHERE entity1 = outer_r.id - UNION ALL - SELECT TRUE FROM l_place_recording WHERE entity1 = outer_r.id - UNION ALL - SELECT TRUE FROM l_recording_recording WHERE entity1 = outer_r.id OR entity0 = outer_r.id - UNION ALL - SELECT TRUE FROM l_recording_release WHERE entity0 = outer_r.id - UNION ALL - SELECT TRUE FROM l_recording_release_group WHERE entity0 = outer_r.id - UNION ALL - SELECT TRUE FROM l_recording_series WHERE entity0 = outer_r.id - UNION ALL - SELECT TRUE FROM l_recording_work WHERE entity0 = outer_r.id - UNION ALL - SELECT TRUE FROM l_recording_url WHERE entity0 = outer_r.id - ); - - IF FOUND THEN - -- Remove references from tables that don't change whether or not this recording - -- is orphaned. - DELETE FROM isrc WHERE recording = OLD.recording; - DELETE FROM recording_annotation WHERE recording = OLD.recording; - DELETE FROM recording_gid_redirect WHERE new_id = OLD.recording; - DELETE FROM recording_rating_raw WHERE recording = OLD.recording; - DELETE FROM recording_tag WHERE recording = OLD.recording; - DELETE FROM recording_tag_raw WHERE recording = OLD.recording; - - DELETE FROM recording WHERE id = OLD.recording; - END IF; - - RETURN NULL; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION unique_primary_event_alias() -RETURNS trigger AS $$ -BEGIN - IF NEW.primary_for_locale THEN - UPDATE event_alias SET primary_for_locale = FALSE - WHERE locale = NEW.locale AND id != NEW.id - AND event = NEW.event; - END IF; - RETURN NEW; -END; -$$ LANGUAGE 'plpgsql'; - --------------------------------------------------------------------------------- -SELECT '20141008-instrument-indexes.sql'; -DROP INDEX IF EXISTS edit_instrument_idx; -CREATE INDEX edit_instrument_idx ON edit_instrument (instrument); - -DROP INDEX IF EXISTS l_area_instrument_idx_uniq; -CREATE UNIQUE INDEX l_area_instrument_idx_uniq ON l_area_instrument (entity0, entity1, link, link_order); - -DROP INDEX IF EXISTS l_artist_instrument_idx_uniq; -CREATE UNIQUE INDEX l_artist_instrument_idx_uniq ON l_artist_instrument (entity0, entity1, link, link_order); - -DROP INDEX IF EXISTS l_area_instrument_idx_entity1; -CREATE INDEX l_area_instrument_idx_entity1 ON l_area_instrument (entity1); - -DROP INDEX IF EXISTS l_artist_instrument_idx_entity1; -CREATE INDEX l_artist_instrument_idx_entity1 ON l_artist_instrument (entity1); --------------------------------------------------------------------------------- -SELECT '20141014-mbs-7784-data-tracks.sql'; - -ALTER TABLE track ADD COLUMN is_data_track BOOLEAN NOT NULL DEFAULT FALSE; - -CREATE OR REPLACE FUNCTION track_count_matches_cdtoc(medium, int) RETURNS boolean AS $$ - SELECT $1.track_count = $2 + COALESCE( - (SELECT count(*) FROM track - WHERE medium = $1.id AND (position = 0 OR is_data_track = true) - ), 0); -$$ LANGUAGE SQL IMMUTABLE; - --------------------------------------------------------------------------------- -SELECT '20140806-collection-types.sql'; - -CREATE TABLE editor_collection_type ( -- replicate - id SERIAL, - name VARCHAR(255) NOT NULL, - entity_type VARCHAR(50) NOT NULL, - parent INTEGER, -- references editor_collection_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT -); - -ALTER TABLE editor_collection_type ADD CONSTRAINT editor_collection_type_pkey PRIMARY KEY (id); - -INSERT INTO editor_collection_type (id, name, entity_type, parent, child_order) VALUES - (1, 'Release', 'release', NULL, 1), - (2, 'Owned music', 'release', 1, 1), - (3, 'Wishlist', 'release', 1, 2); - -SELECT setval('editor_collection_type_id_seq', (SELECT MAX(id) FROM editor_collection_type)); - -ALTER TABLE editor_collection - ADD COLUMN type INTEGER; - -UPDATE editor_collection SET type = 1; - -ALTER TABLE editor_collection - ALTER COLUMN type SET NOT NULL; - --------------------------------------------------------------------------------- -SELECT '20140906-event-collections.sql'; - -CREATE TABLE editor_collection_event -( - collection INTEGER NOT NULL, -- PK, references editor_collection.id - event INTEGER NOT NULL -- PK, references event.id -); - -ALTER TABLE editor_collection_event ADD CONSTRAINT editor_collection_event_pkey PRIMARY KEY (collection, event); - -INSERT INTO editor_collection_type (id, name, entity_type, parent, child_order) VALUES - (4, 'Event', 'event', NULL, 2), - (5, 'Attending', 'event', 4, 1), - (6, 'Maybe attending', 'event', 4, 2); - --------------------------------------------------------------------------------- -SELECT '20141014-mbs-7551-tags.sql'; - -CREATE TABLE area_tag ( - area INTEGER NOT NULL, - tag INTEGER NOT NULL, - count INTEGER NOT NULL, - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW() -); - -CREATE TABLE area_tag_raw ( - area INTEGER NOT NULL, - editor INTEGER NOT NULL, - tag INTEGER NOT NULL -); - -CREATE TABLE instrument_tag ( - instrument INTEGER NOT NULL, - tag INTEGER NOT NULL, - count INTEGER NOT NULL, - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW() -); - -CREATE TABLE instrument_tag_raw ( - instrument INTEGER NOT NULL, - editor INTEGER NOT NULL, - tag INTEGER NOT NULL -); - -CREATE TABLE series_tag ( - series INTEGER NOT NULL, - tag INTEGER NOT NULL, - count INTEGER NOT NULL, - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW() -); - -CREATE TABLE series_tag_raw ( - series INTEGER NOT NULL, - editor INTEGER NOT NULL, - tag INTEGER NOT NULL -); - -ALTER TABLE area_tag ADD CONSTRAINT area_tag_pkey PRIMARY KEY (area, tag); -ALTER TABLE area_tag_raw ADD CONSTRAINT area_tag_raw_pkey PRIMARY KEY (area, editor, tag); - -ALTER TABLE instrument_tag ADD CONSTRAINT instrument_tag_pkey PRIMARY KEY (instrument, tag); -ALTER TABLE instrument_tag_raw ADD CONSTRAINT instrument_tag_raw_pkey PRIMARY KEY (instrument, editor, tag); - -ALTER TABLE series_tag ADD CONSTRAINT series_tag_pkey PRIMARY KEY (series, tag); -ALTER TABLE series_tag_raw ADD CONSTRAINT series_tag_raw_pkey PRIMARY KEY (series, editor, tag); - -CREATE INDEX area_tag_idx_tag ON area_tag (tag); - -CREATE INDEX area_tag_raw_idx_area ON area_tag_raw (area); -CREATE INDEX area_tag_raw_idx_tag ON area_tag_raw (tag); -CREATE INDEX area_tag_raw_idx_editor ON area_tag_raw (editor); - -CREATE INDEX instrument_tag_idx_tag ON instrument_tag (tag); - -CREATE INDEX instrument_tag_raw_idx_instrument ON instrument_tag_raw (instrument); -CREATE INDEX instrument_tag_raw_idx_tag ON instrument_tag_raw (tag); -CREATE INDEX instrument_tag_raw_idx_editor ON instrument_tag_raw (editor); - -CREATE INDEX series_tag_idx_tag ON series_tag (tag); - -CREATE INDEX series_tag_raw_idx_series ON series_tag_raw (series); -CREATE INDEX series_tag_raw_idx_tag ON series_tag_raw (tag); -CREATE INDEX series_tag_raw_idx_editor ON series_tag_raw (editor); - --------------------------------------------------------------------------------- -SELECT '20141031-unused-url.sql'; - -CREATE OR REPLACE FUNCTION delete_unused_url(ids INTEGER[]) -RETURNS VOID AS $$ -DECLARE - clear_up INTEGER[]; -BEGIN - SELECT ARRAY( - SELECT id FROM url url_row WHERE id = any(ids) - EXCEPT - SELECT url FROM edit_url JOIN edit ON (edit.id = edit_url.edit) WHERE edit.status = 1 - EXCEPT - SELECT entity1 FROM l_area_url - EXCEPT - SELECT entity1 FROM l_artist_url - EXCEPT - SELECT entity1 FROM l_event_url - EXCEPT - SELECT entity1 FROM l_instrument_url - EXCEPT - SELECT entity1 FROM l_label_url - EXCEPT - SELECT entity1 FROM l_place_url - EXCEPT - SELECT entity1 FROM l_recording_url - EXCEPT - SELECT entity1 FROM l_release_url - EXCEPT - SELECT entity1 FROM l_release_group_url - EXCEPT - SELECT entity1 FROM l_series_url - EXCEPT - SELECT entity1 FROM l_url_url - EXCEPT - SELECT entity0 FROM l_url_url - EXCEPT - SELECT entity0 FROM l_url_work - ) INTO clear_up; - - DELETE FROM url_gid_redirect WHERE new_id = any(clear_up); - DELETE FROM url WHERE id = any(clear_up); -END; -$$ LANGUAGE 'plpgsql'; - -COMMIT; diff --git a/mbdata/sql/updates/schema-change/21.standalone.sql b/mbdata/sql/updates/schema-change/21.standalone.sql deleted file mode 100644 index b75d752..0000000 --- a/mbdata/sql/updates/schema-change/21.standalone.sql +++ /dev/null @@ -1,228 +0,0 @@ --- Generated by CompileSchemaScripts.pl from: --- 20140606-events-fks.sql --- 20140906-event-collections-fks.sql --- 20141021-collection-types-fks.sql --- 20141014-mbs-7551-tags-fks.sql -\set ON_ERROR_STOP 1 -BEGIN; --------------------------------------------------------------------------------- -SELECT '20140606-events-fks.sql'; - ------------------- --- constraints -- ------------------- - -ALTER TABLE event ADD CHECK (controlled_for_whitespace(comment)); - -ALTER TABLE event - ADD CONSTRAINT control_for_whitespace CHECK (controlled_for_whitespace(name)), - ADD CONSTRAINT only_non_empty CHECK (name != ''); - -ALTER TABLE event_alias - ADD CONSTRAINT control_for_whitespace CHECK (controlled_for_whitespace(name)), - ADD CONSTRAINT only_non_empty CHECK (name != ''), - ADD CONSTRAINT control_for_whitespace_sort_name CHECK (controlled_for_whitespace(sort_name)), - ADD CONSTRAINT only_non_empty_sort_name CHECK (sort_name != ''); - -ALTER TABLE series_type ADD CONSTRAINT allowed_series_entity_type - CHECK ( - entity_type IN ( - 'event', - 'recording', - 'release', - 'release_group', - 'work' - ) - ); - ------------------- --- foreign keys -- ------------------- - -ALTER TABLE documentation.l_area_event_example ADD CONSTRAINT l_area_event_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_area_event(id); -ALTER TABLE documentation.l_artist_event_example ADD CONSTRAINT l_artist_event_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_artist_event(id); -ALTER TABLE documentation.l_event_event_example ADD CONSTRAINT l_event_event_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_event_event(id); -ALTER TABLE documentation.l_event_instrument_example ADD CONSTRAINT l_event_instrument_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_event_instrument(id); -ALTER TABLE documentation.l_event_label_example ADD CONSTRAINT l_event_label_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_event_label(id); -ALTER TABLE documentation.l_event_place_example ADD CONSTRAINT l_event_place_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_event_place(id); -ALTER TABLE documentation.l_event_recording_example ADD CONSTRAINT l_event_recording_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_event_recording(id); -ALTER TABLE documentation.l_event_release_group_example ADD CONSTRAINT l_event_release_group_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_event_release_group(id); -ALTER TABLE documentation.l_event_release_example ADD CONSTRAINT l_event_release_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_event_release(id); -ALTER TABLE documentation.l_event_series_example ADD CONSTRAINT l_event_series_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_event_series(id); -ALTER TABLE documentation.l_event_url_example ADD CONSTRAINT l_event_url_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_event_url(id); -ALTER TABLE documentation.l_event_work_example ADD CONSTRAINT l_event_work_example_fk_id FOREIGN KEY (id) REFERENCES musicbrainz.l_event_work(id); - -ALTER TABLE l_area_event ADD CONSTRAINT l_area_event_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_area_event ADD CONSTRAINT l_area_event_fk_entity0 FOREIGN KEY (entity0) REFERENCES area(id); -ALTER TABLE l_area_event ADD CONSTRAINT l_area_event_fk_entity1 FOREIGN KEY (entity1) REFERENCES event(id); - -ALTER TABLE l_artist_event ADD CONSTRAINT l_artist_event_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_artist_event ADD CONSTRAINT l_artist_event_fk_entity0 FOREIGN KEY (entity0) REFERENCES artist(id); -ALTER TABLE l_artist_event ADD CONSTRAINT l_artist_event_fk_entity1 FOREIGN KEY (entity1) REFERENCES event(id); - -ALTER TABLE l_event_event ADD CONSTRAINT l_event_event_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_event_event ADD CONSTRAINT l_event_event_fk_entity0 FOREIGN KEY (entity0) REFERENCES event(id); -ALTER TABLE l_event_event ADD CONSTRAINT l_event_event_fk_entity1 FOREIGN KEY (entity1) REFERENCES event(id); - -ALTER TABLE l_event_instrument ADD CONSTRAINT l_event_instrument_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_event_instrument ADD CONSTRAINT l_event_instrument_fk_entity0 FOREIGN KEY (entity0) REFERENCES event(id); -ALTER TABLE l_event_instrument ADD CONSTRAINT l_event_instrument_fk_entity1 FOREIGN KEY (entity1) REFERENCES instrument(id); - -ALTER TABLE l_event_label ADD CONSTRAINT l_event_label_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_event_label ADD CONSTRAINT l_event_label_fk_entity0 FOREIGN KEY (entity0) REFERENCES event(id); -ALTER TABLE l_event_label ADD CONSTRAINT l_event_label_fk_entity1 FOREIGN KEY (entity1) REFERENCES label(id); - -ALTER TABLE l_event_place ADD CONSTRAINT l_event_place_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_event_place ADD CONSTRAINT l_event_place_fk_entity0 FOREIGN KEY (entity0) REFERENCES event(id); -ALTER TABLE l_event_place ADD CONSTRAINT l_event_place_fk_entity1 FOREIGN KEY (entity1) REFERENCES place(id); - -ALTER TABLE l_event_recording ADD CONSTRAINT l_event_recording_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_event_recording ADD CONSTRAINT l_event_recording_fk_entity0 FOREIGN KEY (entity0) REFERENCES event(id); -ALTER TABLE l_event_recording ADD CONSTRAINT l_event_recording_fk_entity1 FOREIGN KEY (entity1) REFERENCES recording(id); - -ALTER TABLE l_event_release ADD CONSTRAINT l_event_release_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_event_release ADD CONSTRAINT l_event_release_fk_entity0 FOREIGN KEY (entity0) REFERENCES event(id); -ALTER TABLE l_event_release ADD CONSTRAINT l_event_release_fk_entity1 FOREIGN KEY (entity1) REFERENCES release(id); - -ALTER TABLE l_event_release_group ADD CONSTRAINT l_event_release_group_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_event_release_group ADD CONSTRAINT l_event_release_group_fk_entity0 FOREIGN KEY (entity0) REFERENCES event(id); -ALTER TABLE l_event_release_group ADD CONSTRAINT l_event_release_group_fk_entity1 FOREIGN KEY (entity1) REFERENCES release_group(id); - -ALTER TABLE l_event_series ADD CONSTRAINT l_event_series_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_event_series ADD CONSTRAINT l_event_series_fk_entity0 FOREIGN KEY (entity0) REFERENCES event(id); -ALTER TABLE l_event_series ADD CONSTRAINT l_event_series_fk_entity1 FOREIGN KEY (entity1) REFERENCES series(id); - -ALTER TABLE l_event_url ADD CONSTRAINT l_event_url_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_event_url ADD CONSTRAINT l_event_url_fk_entity0 FOREIGN KEY (entity0) REFERENCES event(id); -ALTER TABLE l_event_url ADD CONSTRAINT l_event_url_fk_entity1 FOREIGN KEY (entity1) REFERENCES url(id); - -ALTER TABLE l_event_work ADD CONSTRAINT l_event_work_fk_link FOREIGN KEY (link) REFERENCES link(id); -ALTER TABLE l_event_work ADD CONSTRAINT l_event_work_fk_entity0 FOREIGN KEY (entity0) REFERENCES event(id); -ALTER TABLE l_event_work ADD CONSTRAINT l_event_work_fk_entity1 FOREIGN KEY (entity1) REFERENCES work(id); - -ALTER TABLE edit_event ADD CONSTRAINT edit_event_fk_edit FOREIGN KEY (edit) REFERENCES edit(id); -ALTER TABLE edit_event ADD CONSTRAINT edit_event_fk_event FOREIGN KEY (event) REFERENCES event(id) ON DELETE CASCADE; - -ALTER TABLE event ADD CONSTRAINT event_fk_type FOREIGN KEY (type) REFERENCES event_type(id); - -ALTER TABLE event_alias ADD CONSTRAINT event_alias_fk_event FOREIGN KEY (event) REFERENCES event(id); -ALTER TABLE event_alias ADD CONSTRAINT event_alias_fk_type FOREIGN KEY (type) REFERENCES event_alias_type(id); - -ALTER TABLE event_alias_type ADD CONSTRAINT event_alias_type_fk_parent FOREIGN KEY (parent) REFERENCES event_alias_type(id); - -ALTER TABLE event_annotation ADD CONSTRAINT event_annotation_fk_event FOREIGN KEY (event) REFERENCES event(id); -ALTER TABLE event_annotation ADD CONSTRAINT event_annotation_fk_annotation FOREIGN KEY (annotation) REFERENCES annotation(id); - -ALTER TABLE event_gid_redirect ADD CONSTRAINT event_gid_redirect_fk_new_id FOREIGN KEY (new_id) REFERENCES event(id); - -ALTER TABLE event_tag ADD CONSTRAINT event_tag_fk_event FOREIGN KEY (event) REFERENCES event(id); -ALTER TABLE event_tag ADD CONSTRAINT event_tag_fk_tag FOREIGN KEY (tag) REFERENCES tag(id); - -ALTER TABLE event_tag_raw ADD CONSTRAINT event_tag_raw_fk_event FOREIGN KEY (event) REFERENCES event(id); -ALTER TABLE event_tag_raw ADD CONSTRAINT event_tag_raw_fk_editor FOREIGN KEY (editor) REFERENCES editor(id); -ALTER TABLE event_tag_raw ADD CONSTRAINT event_tag_raw_fk_tag FOREIGN KEY (tag) REFERENCES tag(id); - -ALTER TABLE event_type ADD CONSTRAINT event_type_fk_parent FOREIGN KEY (parent) REFERENCES event_type(id); - --------------- --- triggers -- --------------- - -CREATE TRIGGER b_upd_event BEFORE UPDATE ON event - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER end_date_implies_ended BEFORE UPDATE OR INSERT ON event - FOR EACH ROW EXECUTE PROCEDURE end_date_implies_ended(); - -CREATE TRIGGER b_upd_event_alias BEFORE UPDATE ON event_alias - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER end_date_implies_ended BEFORE UPDATE OR INSERT ON event_alias - FOR EACH ROW EXECUTE PROCEDURE end_date_implies_ended(); - -CREATE TRIGGER unique_primary_for_locale BEFORE UPDATE OR INSERT ON event_alias - FOR EACH ROW EXECUTE PROCEDURE unique_primary_event_alias(); - -CREATE TRIGGER search_hint BEFORE UPDATE OR INSERT ON event_alias - FOR EACH ROW EXECUTE PROCEDURE simplify_search_hints(2); - -CREATE TRIGGER b_upd_event_tag BEFORE UPDATE ON event_tag - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - --------------------------------------------------------------------------------- -SELECT '20140906-event-collections-fks.sql'; - -ALTER TABLE editor_collection_event - ADD CONSTRAINT editor_collection_event_fk_collection - FOREIGN KEY (collection) - REFERENCES editor_collection(id); - -ALTER TABLE editor_collection_event - ADD CONSTRAINT editor_collection_event_fk_event - FOREIGN KEY (event) - REFERENCES event(id); - -ALTER TABLE editor_collection_type ADD CONSTRAINT allowed_collection_entity_type - CHECK ( - entity_type IN ( - 'event', - 'release' - ) - ); - --------------------------------------------------------------------------------- -SELECT '20141021-collection-types-fks.sql'; - -ALTER TABLE editor_collection_type - ADD CONSTRAINT editor_collection_type_fk_parent - FOREIGN KEY (parent) - REFERENCES editor_collection_type(id); - -ALTER TABLE editor_collection - ADD CONSTRAINT editor_collection_fk_type - FOREIGN KEY (type) - REFERENCES editor_collection_type(id); - --------------------------------------------------------------------------------- -SELECT '20141014-mbs-7551-tags-fks.sql'; - -ALTER TABLE area_tag ADD CONSTRAINT area_tag_fk_area FOREIGN KEY (area) REFERENCES area(id); -ALTER TABLE area_tag ADD CONSTRAINT area_tag_fk_tag FOREIGN KEY (tag) REFERENCES tag(id); - -ALTER TABLE area_tag_raw ADD CONSTRAINT area_tag_raw_fk_area FOREIGN KEY (area) REFERENCES area(id); -ALTER TABLE area_tag_raw ADD CONSTRAINT area_tag_raw_fk_editor FOREIGN KEY (editor) REFERENCES editor(id); -ALTER TABLE area_tag_raw ADD CONSTRAINT area_tag_raw_fk_tag FOREIGN KEY (tag) REFERENCES tag(id); - -ALTER TABLE instrument_tag ADD CONSTRAINT instrument_tag_fk_instrument FOREIGN KEY (instrument) REFERENCES instrument(id); -ALTER TABLE instrument_tag ADD CONSTRAINT instrument_tag_fk_tag FOREIGN KEY (tag) REFERENCES tag(id); - -ALTER TABLE instrument_tag_raw ADD CONSTRAINT instrument_tag_raw_fk_instrument FOREIGN KEY (instrument) REFERENCES instrument(id); -ALTER TABLE instrument_tag_raw ADD CONSTRAINT instrument_tag_raw_fk_editor FOREIGN KEY (editor) REFERENCES editor(id); -ALTER TABLE instrument_tag_raw ADD CONSTRAINT instrument_tag_raw_fk_tag FOREIGN KEY (tag) REFERENCES tag(id); - -ALTER TABLE series_tag ADD CONSTRAINT series_tag_fk_series FOREIGN KEY (series) REFERENCES series(id); -ALTER TABLE series_tag ADD CONSTRAINT series_tag_fk_tag FOREIGN KEY (tag) REFERENCES tag(id); - -ALTER TABLE series_tag_raw ADD CONSTRAINT series_tag_raw_fk_series FOREIGN KEY (series) REFERENCES series(id); -ALTER TABLE series_tag_raw ADD CONSTRAINT series_tag_raw_fk_editor FOREIGN KEY (editor) REFERENCES editor(id); -ALTER TABLE series_tag_raw ADD CONSTRAINT series_tag_raw_fk_tag FOREIGN KEY (tag) REFERENCES tag(id); - -CREATE TRIGGER b_upd_area_tag BEFORE UPDATE ON area_tag FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_instrument_tag BEFORE UPDATE ON instrument_tag FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_series_tag BEFORE UPDATE ON series_tag FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE CONSTRAINT TRIGGER delete_unused_tag -AFTER DELETE ON area_tag DEFERRABLE INITIALLY DEFERRED -FOR EACH ROW EXECUTE PROCEDURE trg_delete_unused_tag_ref(); - -CREATE CONSTRAINT TRIGGER delete_unused_tag -AFTER DELETE ON instrument_tag DEFERRABLE INITIALLY DEFERRED -FOR EACH ROW EXECUTE PROCEDURE trg_delete_unused_tag_ref(); - -CREATE CONSTRAINT TRIGGER delete_unused_tag -AFTER DELETE ON series_tag DEFERRABLE INITIALLY DEFERRED -FOR EACH ROW EXECUTE PROCEDURE trg_delete_unused_tag_ref(); - -COMMIT; diff --git a/mbdata/sql/updates/schema-change/22.mirror.sql b/mbdata/sql/updates/schema-change/22.mirror.sql deleted file mode 100644 index 23a81bd..0000000 --- a/mbdata/sql/updates/schema-change/22.mirror.sql +++ /dev/null @@ -1,574 +0,0 @@ --- Generated by CompileSchemaScripts.pl from: --- 20150209-extend-aliases-to-more-entities.sql --- 20150307-other-entities-collections.sql --- 20150317-medium-name-not-null.sql --- 20150331-relationship-credits.sql --- 20150429-tag-upvote.sql --- 20150403-drop-empty-functions.sql -\set ON_ERROR_STOP 1 -BEGIN; -SET search_path = musicbrainz, public; -SET LOCAL statement_timeout = 0; --------------------------------------------------------------------------------- -SELECT '20150209-extend-aliases-to-more-entities.sql'; - -CREATE TABLE recording_alias_type ( -- replicate - id SERIAL, -- PK, - name TEXT NOT NULL, - parent INTEGER, -- references recording_alias_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT -); - -CREATE TABLE recording_alias ( -- replicate (verbose) - id SERIAL, --PK - recording INTEGER NOT NULL, -- references recording.id - name VARCHAR NOT NULL, - locale TEXT, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >=0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - type INTEGER, -- references recording_alias_type.id - sort_name VARCHAR NOT NULL, - begin_date_year SMALLINT, - begin_date_month SMALLINT, - begin_date_day SMALLINT, - end_date_year SMALLINT, - end_date_month SMALLINT, - end_date_day SMALLINT, - primary_for_locale BOOLEAN NOT NULL DEFAULT false, - ended BOOLEAN NOT NULL DEFAULT FALSE - CHECK ( - ( - -- If any end date fields are not null, then ended must be true - (end_date_year IS NOT NULL OR - end_date_month IS NOT NULL OR - end_date_day IS NOT NULL) AND - ended = TRUE - ) OR ( - -- Otherwise, all end date fields must be null - (end_date_year IS NULL AND - end_date_month IS NULL AND - end_date_day IS NULL) - ) - ), - CONSTRAINT primary_check - CHECK ((locale IS NULL AND primary_for_locale IS FALSE) OR (locale IS NOT NULL))); - -CREATE TABLE release_alias_type ( -- replicate - id SERIAL, -- PK, - name TEXT NOT NULL, - parent INTEGER, -- references release_alias_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT -); - -CREATE TABLE release_alias ( -- replicate (verbose) - id SERIAL, --PK - release INTEGER NOT NULL, -- references release.id - name VARCHAR NOT NULL, - locale TEXT, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >=0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - type INTEGER, -- references release_alias_type.id - sort_name VARCHAR NOT NULL, - begin_date_year SMALLINT, - begin_date_month SMALLINT, - begin_date_day SMALLINT, - end_date_year SMALLINT, - end_date_month SMALLINT, - end_date_day SMALLINT, - primary_for_locale BOOLEAN NOT NULL DEFAULT false, - ended BOOLEAN NOT NULL DEFAULT FALSE - CHECK ( - ( - -- If any end date fields are not null, then ended must be true - (end_date_year IS NOT NULL OR - end_date_month IS NOT NULL OR - end_date_day IS NOT NULL) AND - ended = TRUE - ) OR ( - -- Otherwise, all end date fields must be null - (end_date_year IS NULL AND - end_date_month IS NULL AND - end_date_day IS NULL) - ) - ), - CONSTRAINT primary_check - CHECK ((locale IS NULL AND primary_for_locale IS FALSE) OR (locale IS NOT NULL))); - -CREATE TABLE release_group_alias_type ( -- replicate - id SERIAL, -- PK, - name TEXT NOT NULL, - parent INTEGER, -- references release_group_alias_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT -); - -CREATE TABLE release_group_alias ( -- replicate (verbose) - id SERIAL, --PK - release_group INTEGER NOT NULL, -- references release_group.id - name VARCHAR NOT NULL, - locale TEXT, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >=0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - type INTEGER, -- references release_group_alias_type.id - sort_name VARCHAR NOT NULL, - begin_date_year SMALLINT, - begin_date_month SMALLINT, - begin_date_day SMALLINT, - end_date_year SMALLINT, - end_date_month SMALLINT, - end_date_day SMALLINT, - primary_for_locale BOOLEAN NOT NULL DEFAULT false, - ended BOOLEAN NOT NULL DEFAULT FALSE - CHECK ( - ( - -- If any end date fields are not null, then ended must be true - (end_date_year IS NOT NULL OR - end_date_month IS NOT NULL OR - end_date_day IS NOT NULL) AND - ended = TRUE - ) OR ( - -- Otherwise, all end date fields must be null - (end_date_year IS NULL AND - end_date_month IS NULL AND - end_date_day IS NULL) - ) - ), - CONSTRAINT primary_check - CHECK ((locale IS NULL AND primary_for_locale IS FALSE) OR (locale IS NOT NULL))); - - -CREATE OR REPLACE FUNCTION unique_primary_recording_alias() -RETURNS trigger AS $$ -BEGIN - IF NEW.primary_for_locale THEN - UPDATE recording_alias SET primary_for_locale = FALSE - WHERE locale = NEW.locale AND id != NEW.id - AND recording = NEW.recording; - END IF; - RETURN NEW; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION unique_primary_release_alias() -RETURNS trigger AS $$ -BEGIN - IF NEW.primary_for_locale THEN - UPDATE release_alias SET primary_for_locale = FALSE - WHERE locale = NEW.locale AND id != NEW.id - AND release = NEW.release; - END IF; - RETURN NEW; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION unique_primary_release_group_alias() -RETURNS trigger AS $$ -BEGIN - IF NEW.primary_for_locale THEN - UPDATE release_group_alias SET primary_for_locale = FALSE - WHERE locale = NEW.locale AND id != NEW.id - AND release_group = NEW.release_group; - END IF; - RETURN NEW; -END; -$$ LANGUAGE 'plpgsql'; - - -CREATE INDEX recording_alias_idx_recording ON recording_alias (recording); -CREATE UNIQUE INDEX recording_alias_idx_primary ON recording_alias (recording, locale) WHERE primary_for_locale = TRUE AND locale IS NOT NULL; - -CREATE INDEX release_alias_idx_release ON release_alias (release); -CREATE UNIQUE INDEX release_alias_idx_primary ON release_alias (release, locale) WHERE primary_for_locale = TRUE AND locale IS NOT NULL; - -CREATE INDEX release_group_alias_idx_release_group ON release_group_alias (release_group); -CREATE UNIQUE INDEX release_group_alias_idx_primary ON release_group_alias (release_group, locale) WHERE primary_for_locale = TRUE AND locale IS NOT NULL; - - -ALTER TABLE recording_alias ADD CONSTRAINT recording_alias_pkey PRIMARY KEY (id); -ALTER TABLE recording_alias_type ADD CONSTRAINT recording_alias_type_pkey PRIMARY KEY (id); -ALTER TABLE release_alias ADD CONSTRAINT release_alias_pkey PRIMARY KEY (id); -ALTER TABLE release_alias_type ADD CONSTRAINT release_alias_type_pkey PRIMARY KEY (id); -ALTER TABLE release_group_alias ADD CONSTRAINT release_group_alias_pkey PRIMARY KEY (id); -ALTER TABLE release_group_alias_type ADD CONSTRAINT release_group_alias_type_pkey PRIMARY KEY (id); - - -CREATE INDEX release_alias_idx_txt ON release_alias USING gin(to_tsvector('mb_simple', name)); -CREATE INDEX release_alias_idx_txt_sort ON release_alias USING gin(to_tsvector('mb_simple', sort_name)); - -CREATE INDEX release_group_alias_idx_txt ON release_group_alias USING gin(to_tsvector('mb_simple', name)); -CREATE INDEX release_group_alias_idx_txt_sort ON release_group_alias USING gin(to_tsvector('mb_simple', sort_name)); - -CREATE INDEX recording_alias_idx_txt ON recording_alias USING gin(to_tsvector('mb_simple', name)); -CREATE INDEX recording_alias_idx_txt_sort ON recording_alias USING gin(to_tsvector('mb_simple', sort_name)); - -INSERT INTO recording_alias_type (name) VALUES ('Recording name'), ('Search hint'); -INSERT INTO release_alias_type (name) VALUES ('Release name'), ('Search hint'); -INSERT INTO release_group_alias_type (name) VALUES ('Release group name'), ('Search hint'); - -SELECT setval('recording_alias_type_id_seq', (SELECT MAX(id) FROM recording_alias_type)); -SELECT setval('release_alias_type_id_seq', (SELECT MAX(id) FROM release_alias_type)); -SELECT setval('release_group_alias_type_id_seq', (SELECT MAX(id) FROM release_group_alias_type)); - --------------------------------------------------------------------------------- -SELECT '20150307-other-entities-collections.sql'; - -ALTER TABLE editor_collection_type - DROP CONSTRAINT IF EXISTS allowed_collection_entity_type; - --- Commented-out because code was not ready for this yet. ---INSERT INTO editor_collection_type (id, name, entity_type, parent, child_order) VALUES --- (7, 'Area', 'area', NULL, 2), --- (8, 'Artist', 'artist', NULL, 2), --- (9, 'Instrument', 'instrument', NULL, 2), --- (10, 'Label', 'label', NULL, 2), --- (11, 'Place', 'place', NULL, 2), --- (12, 'Recording', 'recording', NULL, 2), --- (13, 'Release group', 'release_group', NULL, 2), --- (14, 'Series', 'series', NULL, 2), --- (15, 'Work', 'work', NULL, 2); - -CREATE TABLE editor_collection_area ( - collection INTEGER NOT NULL, - area INTEGER NOT NULL -); - -ALTER TABLE editor_collection_area ADD CONSTRAINT editor_collection_area_pkey PRIMARY KEY (collection, area); - - -CREATE TABLE editor_collection_artist ( - collection INTEGER NOT NULL, - artist INTEGER NOT NULL -); - -ALTER TABLE editor_collection_artist ADD CONSTRAINT editor_collection_artist_pkey PRIMARY KEY (collection, artist); - - -CREATE TABLE editor_collection_instrument ( - collection INTEGER NOT NULL, - instrument INTEGER NOT NULL -); - -ALTER TABLE editor_collection_instrument ADD CONSTRAINT editor_collection_instrument_pkey PRIMARY KEY (collection, instrument); - - -CREATE TABLE editor_collection_label ( - collection INTEGER NOT NULL, - label INTEGER NOT NULL -); - -ALTER TABLE editor_collection_label ADD CONSTRAINT editor_collection_label_pkey PRIMARY KEY (collection, label); - - -CREATE TABLE editor_collection_place ( - collection INTEGER NOT NULL, - place INTEGER NOT NULL -); - -ALTER TABLE editor_collection_place ADD CONSTRAINT editor_collection_place_pkey PRIMARY KEY (collection, place); - - -CREATE TABLE editor_collection_recording ( - collection INTEGER NOT NULL, - recording INTEGER NOT NULL -); - -ALTER TABLE editor_collection_recording ADD CONSTRAINT editor_collection_recording_pkey PRIMARY KEY (collection, recording); - - -CREATE TABLE editor_collection_release_group ( - collection INTEGER NOT NULL, - release_group INTEGER NOT NULL -); - -ALTER TABLE editor_collection_release_group ADD CONSTRAINT editor_collection_release_group_pkey PRIMARY KEY (collection, release_group); - - -CREATE TABLE editor_collection_series ( - collection INTEGER NOT NULL, - series INTEGER NOT NULL -); - -ALTER TABLE editor_collection_series ADD CONSTRAINT editor_collection_series_pkey PRIMARY KEY (collection, series); - - -CREATE TABLE editor_collection_work ( - collection INTEGER NOT NULL, - work INTEGER NOT NULL -); - -ALTER TABLE editor_collection_work ADD CONSTRAINT editor_collection_work_pkey PRIMARY KEY (collection, work); - --------------------------------------------------------------------------------- -SELECT '20150317-medium-name-not-null.sql'; - -ALTER TABLE medium - ALTER COLUMN name SET DATA TYPE VARCHAR USING COALESCE(name, ''), - ALTER COLUMN name SET NOT NULL, - ALTER COLUMN name SET DEFAULT ''; - --------------------------------------------------------------------------------- -SELECT '20150331-relationship-credits.sql'; - -ALTER TABLE l_area_area ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_area_area ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_area_artist ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_area_artist ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_area_event ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_area_event ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_area_instrument ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_area_instrument ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_area_label ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_area_label ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_area_place ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_area_place ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_area_recording ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_area_recording ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_area_release ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_area_release ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_area_release_group ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_area_release_group ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_area_series ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_area_series ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_area_url ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_area_url ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_area_work ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_area_work ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_artist_artist ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_artist_artist ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_artist_event ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_artist_event ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_artist_instrument ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_artist_instrument ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_artist_label ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_artist_label ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_artist_place ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_artist_place ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_artist_recording ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_artist_recording ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_artist_release ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_artist_release ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_artist_release_group ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_artist_release_group ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_artist_series ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_artist_series ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_artist_url ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_artist_url ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_artist_work ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_artist_work ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_event_event ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_event_event ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_event_instrument ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_event_instrument ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_event_label ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_event_label ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_event_place ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_event_place ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_event_recording ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_event_recording ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_event_release ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_event_release ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_event_release_group ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_event_release_group ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_event_series ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_event_series ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_event_url ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_event_url ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_event_work ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_event_work ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_label_label ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_label_label ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_instrument_instrument ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_instrument_instrument ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_instrument_label ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_instrument_label ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_instrument_place ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_instrument_place ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_instrument_recording ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_instrument_recording ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_instrument_release ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_instrument_release ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_instrument_release_group ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_instrument_release_group ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_instrument_series ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_instrument_series ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_instrument_url ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_instrument_url ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_instrument_work ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_instrument_work ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_label_place ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_label_place ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_label_recording ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_label_recording ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_label_release ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_label_release ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_label_release_group ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_label_release_group ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_label_series ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_label_series ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_label_url ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_label_url ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_label_work ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_label_work ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_place_place ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_place_place ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_place_recording ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_place_recording ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_place_release ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_place_release ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_place_release_group ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_place_release_group ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_place_series ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_place_series ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_place_url ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_place_url ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_place_work ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_place_work ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_recording_recording ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_recording_recording ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_recording_release ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_recording_release ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_recording_release_group ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_recording_release_group ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_recording_series ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_recording_series ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_recording_url ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_recording_url ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_recording_work ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_recording_work ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_release_release ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_release_release ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_release_release_group ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_release_release_group ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_release_series ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_release_series ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_release_url ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_release_url ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_release_work ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_release_work ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_release_group_release_group ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_release_group_release_group ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_release_group_series ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_release_group_series ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_release_group_url ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_release_group_url ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_release_group_work ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_release_group_work ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_series_series ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_series_series ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_series_url ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_series_url ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_series_work ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_series_work ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_url_url ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_url_url ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_url_work ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_url_work ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - -ALTER TABLE l_work_work ADD COLUMN entity0_credit TEXT NOT NULL DEFAULT ''; -ALTER TABLE l_work_work ADD COLUMN entity1_credit TEXT NOT NULL DEFAULT ''; - --------------------------------------------------------------------------------- -SELECT '20150429-tag-upvote.sql'; - -ALTER TABLE area_tag_raw ADD COLUMN is_upvote BOOLEAN NOT NULL DEFAULT TRUE; -ALTER TABLE artist_tag_raw ADD COLUMN is_upvote BOOLEAN NOT NULL DEFAULT TRUE; -ALTER TABLE event_tag_raw ADD COLUMN is_upvote BOOLEAN NOT NULL DEFAULT TRUE; -ALTER TABLE instrument_tag_raw ADD COLUMN is_upvote BOOLEAN NOT NULL DEFAULT TRUE; -ALTER TABLE label_tag_raw ADD COLUMN is_upvote BOOLEAN NOT NULL DEFAULT TRUE; -ALTER TABLE place_tag_raw ADD COLUMN is_upvote BOOLEAN NOT NULL DEFAULT TRUE; -ALTER TABLE recording_tag_raw ADD COLUMN is_upvote BOOLEAN NOT NULL DEFAULT TRUE; -ALTER TABLE release_tag_raw ADD COLUMN is_upvote BOOLEAN NOT NULL DEFAULT TRUE; -ALTER TABLE release_group_tag_raw ADD COLUMN is_upvote BOOLEAN NOT NULL DEFAULT TRUE; -ALTER TABLE series_tag_raw ADD COLUMN is_upvote BOOLEAN NOT NULL DEFAULT TRUE; -ALTER TABLE work_tag_raw ADD COLUMN is_upvote BOOLEAN NOT NULL DEFAULT TRUE; - --------------------------------------------------------------------------------- -SELECT '20150403-drop-empty-functions.sql'; - -DROP FUNCTION IF EXISTS empty_artists(); -DROP FUNCTION IF EXISTS empty_events(); -DROP FUNCTION IF EXISTS empty_labels(); -DROP FUNCTION IF EXISTS empty_places(); -DROP FUNCTION IF EXISTS empty_release_groups(); -DROP FUNCTION IF EXISTS empty_series(); -DROP FUNCTION IF EXISTS empty_works(); - -COMMIT; diff --git a/mbdata/sql/updates/schema-change/22.standalone.sql b/mbdata/sql/updates/schema-change/22.standalone.sql deleted file mode 100644 index a76ade0..0000000 --- a/mbdata/sql/updates/schema-change/22.standalone.sql +++ /dev/null @@ -1,435 +0,0 @@ --- Generated by CompileSchemaScripts.pl from: --- 20150209-extend-aliases-to-more-entities-standalone.sql --- 20150307-other-entities-collections-fks.sql --- 20150317-drop-event-name-constraint.sql --- 20150331-relationship-credits-standalone.sql -\set ON_ERROR_STOP 1 -BEGIN; --------------------------------------------------------------------------------- -SELECT '20150209-extend-aliases-to-more-entities-standalone.sql'; - -CREATE TRIGGER end_date_implies_ended BEFORE UPDATE OR INSERT ON recording_alias - FOR EACH ROW EXECUTE PROCEDURE end_date_implies_ended(); - -CREATE TRIGGER b_upd_recording_alias BEFORE UPDATE ON recording_alias - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER unique_primary_for_locale BEFORE UPDATE OR INSERT ON recording_alias - FOR EACH ROW EXECUTE PROCEDURE unique_primary_recording_alias(); - -CREATE TRIGGER search_hint BEFORE UPDATE OR INSERT ON recording_alias - FOR EACH ROW EXECUTE PROCEDURE simplify_search_hints(2); - -CREATE TRIGGER end_date_implies_ended BEFORE UPDATE OR INSERT ON release_alias - FOR EACH ROW EXECUTE PROCEDURE end_date_implies_ended(); - -CREATE TRIGGER b_upd_release_alias BEFORE UPDATE ON release_alias - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER unique_primary_for_locale BEFORE UPDATE OR INSERT ON release_alias - FOR EACH ROW EXECUTE PROCEDURE unique_primary_release_alias(); - -CREATE TRIGGER search_hint BEFORE UPDATE OR INSERT ON release_alias - FOR EACH ROW EXECUTE PROCEDURE simplify_search_hints(2); - -CREATE TRIGGER end_date_implies_ended BEFORE UPDATE OR INSERT ON release_group_alias - FOR EACH ROW EXECUTE PROCEDURE end_date_implies_ended(); - -CREATE TRIGGER b_upd_release_group_alias BEFORE UPDATE ON release_group_alias - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER unique_primary_for_locale BEFORE UPDATE OR INSERT ON release_group_alias - FOR EACH ROW EXECUTE PROCEDURE unique_primary_release_group_alias(); - -CREATE TRIGGER search_hint BEFORE UPDATE OR INSERT ON release_group_alias - FOR EACH ROW EXECUTE PROCEDURE simplify_search_hints(2); - - -ALTER TABLE release_alias - ADD CONSTRAINT control_for_whitespace CHECK (controlled_for_whitespace(name)), - ADD CONSTRAINT only_non_empty CHECK (name != ''), - ADD CONSTRAINT control_for_whitespace_sort_name CHECK (controlled_for_whitespace(sort_name)), - ADD CONSTRAINT only_non_empty_sort_name CHECK (sort_name != ''); - -ALTER TABLE release_group_alias - ADD CONSTRAINT control_for_whitespace CHECK (controlled_for_whitespace(name)), - ADD CONSTRAINT only_non_empty CHECK (name != ''), - ADD CONSTRAINT control_for_whitespace_sort_name CHECK (controlled_for_whitespace(sort_name)), - ADD CONSTRAINT only_non_empty_sort_name CHECK (sort_name != ''); - -ALTER TABLE recording_alias - ADD CONSTRAINT control_for_whitespace CHECK (controlled_for_whitespace(name)), - ADD CONSTRAINT only_non_empty CHECK (name != ''), - ADD CONSTRAINT control_for_whitespace_sort_name CHECK (controlled_for_whitespace(sort_name)), - ADD CONSTRAINT only_non_empty_sort_name CHECK (sort_name != ''); - - -ALTER TABLE recording_alias - ADD CONSTRAINT recording_alias_fk_recording - FOREIGN KEY (recording) - REFERENCES recording(id); - -ALTER TABLE recording_alias - ADD CONSTRAINT recording_alias_fk_type - FOREIGN KEY (type) - REFERENCES recording_alias_type(id); - -ALTER TABLE recording_alias_type - ADD CONSTRAINT recording_alias_type_fk_parent - FOREIGN KEY (parent) - REFERENCES recording_alias_type(id); - -ALTER TABLE release_alias - ADD CONSTRAINT release_alias_fk_release - FOREIGN KEY (release) - REFERENCES release(id); - -ALTER TABLE release_alias - ADD CONSTRAINT release_alias_fk_type - FOREIGN KEY (type) - REFERENCES release_alias_type(id); - -ALTER TABLE release_alias_type - ADD CONSTRAINT release_alias_type_fk_parent - FOREIGN KEY (parent) - REFERENCES release_alias_type(id); - -ALTER TABLE release_group_alias - ADD CONSTRAINT release_group_alias_fk_release_group - FOREIGN KEY (release_group) - REFERENCES release_group(id); - -ALTER TABLE release_group_alias - ADD CONSTRAINT release_group_alias_fk_type - FOREIGN KEY (type) - REFERENCES release_group_alias_type(id); - -ALTER TABLE release_group_alias_type - ADD CONSTRAINT release_group_alias_type_fk_parent - FOREIGN KEY (parent) - REFERENCES release_group_alias_type(id); - --------------------------------------------------------------------------------- -SELECT '20150307-other-entities-collections-fks.sql'; - -ALTER TABLE editor_collection_type -- Already dropped in slave update script - ADD CONSTRAINT allowed_collection_entity_type CHECK ( - entity_type IN ('area', 'artist', 'event', 'instrument', 'label', 'place', 'recording', 'release', 'release_group', 'series', 'work') - ); - -ALTER TABLE editor_collection_area - ADD CONSTRAINT editor_collection_area_fk_collection - FOREIGN KEY (collection) - REFERENCES editor_collection(id), - ADD CONSTRAINT editor_collection_area_fk_area - FOREIGN KEY (area) - REFERENCES area(id); - -ALTER TABLE editor_collection_artist - ADD CONSTRAINT editor_collection_artist_fk_collection - FOREIGN KEY (collection) - REFERENCES editor_collection(id), - ADD CONSTRAINT editor_collection_artist_fk_artist - FOREIGN KEY (artist) - REFERENCES artist(id); - -ALTER TABLE editor_collection_instrument - ADD CONSTRAINT editor_collection_instrument_fk_collection - FOREIGN KEY (collection) - REFERENCES editor_collection(id), - ADD CONSTRAINT editor_collection_instrument_fk_instrument - FOREIGN KEY (instrument) - REFERENCES instrument(id); - -ALTER TABLE editor_collection_label - ADD CONSTRAINT editor_collection_label_fk_collection - FOREIGN KEY (collection) - REFERENCES editor_collection(id), - ADD CONSTRAINT editor_collection_label_fk_label - FOREIGN KEY (label) - REFERENCES label(id); - -ALTER TABLE editor_collection_place - ADD CONSTRAINT editor_collection_place_fk_collection - FOREIGN KEY (collection) - REFERENCES editor_collection(id), - ADD CONSTRAINT editor_collection_place_fk_place - FOREIGN KEY (place) - REFERENCES place(id); - -ALTER TABLE editor_collection_recording - ADD CONSTRAINT editor_collection_recording_fk_collection - FOREIGN KEY (collection) - REFERENCES editor_collection(id), - ADD CONSTRAINT editor_collection_recording_fk_recording - FOREIGN KEY (recording) - REFERENCES recording(id); - -ALTER TABLE editor_collection_release_group - ADD CONSTRAINT editor_collection_release_group_fk_collection - FOREIGN KEY (collection) - REFERENCES editor_collection(id), - ADD CONSTRAINT editor_collection_release_group_fk_release_group - FOREIGN KEY (release_group) - REFERENCES release_group(id); - -ALTER TABLE editor_collection_series - ADD CONSTRAINT editor_collection_series_fk_collection - FOREIGN KEY (collection) - REFERENCES editor_collection(id), - ADD CONSTRAINT editor_collection_series_fk_series - FOREIGN KEY (series) - REFERENCES series(id); - -ALTER TABLE editor_collection_work - ADD CONSTRAINT editor_collection_work_fk_collection - FOREIGN KEY (collection) - REFERENCES editor_collection(id), - ADD CONSTRAINT editor_collection_work_fk_work - FOREIGN KEY (work) - REFERENCES work(id); - --------------------------------------------------------------------------------- -SELECT '20150317-drop-event-name-constraint.sql'; - -ALTER TABLE event - DROP CONSTRAINT IF EXISTS only_non_empty; - --------------------------------------------------------------------------------- -SELECT '20150331-relationship-credits-standalone.sql'; - -ALTER TABLE l_area_area ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_area_area ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_area_artist ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_area_artist ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_area_event ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_area_event ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_area_instrument ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_area_instrument ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_area_label ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_area_label ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_area_place ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_area_place ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_area_recording ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_area_recording ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_area_release ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_area_release ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_area_release_group ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_area_release_group ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_area_series ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_area_series ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_area_url ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_area_url ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_area_work ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_area_work ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_artist_artist ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_artist_artist ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_artist_event ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_artist_event ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_artist_instrument ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_artist_instrument ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_artist_label ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_artist_label ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_artist_place ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_artist_place ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_artist_recording ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_artist_recording ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_artist_release ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_artist_release ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_artist_release_group ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_artist_release_group ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_artist_series ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_artist_series ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_artist_url ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_artist_url ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_artist_work ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_artist_work ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_event_event ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_event_event ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_event_instrument ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_event_instrument ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_event_label ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_event_label ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_event_place ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_event_place ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_event_recording ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_event_recording ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_event_release ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_event_release ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_event_release_group ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_event_release_group ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_event_series ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_event_series ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_event_url ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_event_url ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_event_work ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_event_work ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_label_label ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_label_label ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_instrument_instrument ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_instrument_instrument ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_instrument_label ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_instrument_label ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_instrument_place ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_instrument_place ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_instrument_recording ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_instrument_recording ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_instrument_release ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_instrument_release ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_instrument_release_group ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_instrument_release_group ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_instrument_series ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_instrument_series ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_instrument_url ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_instrument_url ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_instrument_work ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_instrument_work ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_label_place ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_label_place ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_label_recording ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_label_recording ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_label_release ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_label_release ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_label_release_group ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_label_release_group ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_label_series ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_label_series ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_label_url ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_label_url ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_label_work ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_label_work ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_place_place ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_place_place ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_place_recording ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_place_recording ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_place_release ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_place_release ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_place_release_group ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_place_release_group ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_place_series ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_place_series ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_place_url ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_place_url ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_place_work ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_place_work ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_recording_recording ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_recording_recording ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_recording_release ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_recording_release ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_recording_release_group ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_recording_release_group ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_recording_series ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_recording_series ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_recording_url ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_recording_url ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_recording_work ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_recording_work ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_release_release ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_release_release ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_release_release_group ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_release_release_group ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_release_series ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_release_series ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_release_url ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_release_url ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_release_work ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_release_work ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_release_group_release_group ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_release_group_release_group ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_release_group_series ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_release_group_series ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_release_group_url ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_release_group_url ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_release_group_work ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_release_group_work ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_series_series ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_series_series ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_series_url ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_series_url ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_series_work ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_series_work ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_url_url ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_url_url ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_url_work ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_url_work ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_work_work ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_work_work ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -COMMIT; diff --git a/mbdata/sql/updates/schema-change/23.extensions.sql b/mbdata/sql/updates/schema-change/23.extensions.sql deleted file mode 100644 index 87d036f..0000000 --- a/mbdata/sql/updates/schema-change/23.extensions.sql +++ /dev/null @@ -1,10 +0,0 @@ --- Generated by CompileSchemaScripts.pl from: --- 20141226-geodesic-extension.sql -\set ON_ERROR_STOP 1 -BEGIN; -SET search_path = musicbrainz, public; --------------------------------------------------------------------------------- -SELECT '20141226-geodesic-extension.sql'; - -CREATE EXTENSION IF NOT EXISTS earthdistance WITH SCHEMA public; -COMMIT; diff --git a/mbdata/sql/updates/schema-change/23.mirror.sql b/mbdata/sql/updates/schema-change/23.mirror.sql deleted file mode 100644 index a875326..0000000 --- a/mbdata/sql/updates/schema-change/23.mirror.sql +++ /dev/null @@ -1,549 +0,0 @@ --- Generated by CompileSchemaScripts.pl from: --- 20160516-mbs-8838.sql --- 20160516-mbs-8720.sql --- 20141226-geodesic-index.sql --- 20160429-mbs-8656.sql --- 20151223-edit-note-index.sql --- 20160310-mbs-4501-alternative-tracklists.sql --- 20160516-mbs-8656.sql --- 20160507-mbs-8727.sql --- 20160512-mbs-8719.sql --- 20160512-edit-data.sql --- 20160514-mbs-8287-a.sql --- 20160514-mbs-8287-b.sql --- 20160515-recluster.sql --- 20160516-mbs-8804.sql -\set ON_ERROR_STOP 1 -BEGIN; -SET search_path = musicbrainz, public; -SET LOCAL statement_timeout = 0; --------------------------------------------------------------------------------- -SELECT '20160516-mbs-8838.sql'; - --- Creating columns -ALTER TABLE area_type ADD COLUMN gid uuid; -ALTER TABLE area_alias_type ADD COLUMN gid uuid; -ALTER TABLE artist_alias_type ADD COLUMN gid uuid; -ALTER TABLE artist_type ADD COLUMN gid uuid; -ALTER TABLE editor_collection_type ADD COLUMN gid uuid; -ALTER TABLE event_alias_type ADD COLUMN gid uuid; -ALTER TABLE event_type ADD COLUMN gid uuid; -ALTER TABLE gender ADD COLUMN gid uuid; -ALTER TABLE instrument_alias_type ADD COLUMN gid uuid; -ALTER TABLE instrument_type ADD COLUMN gid uuid; -ALTER TABLE label_alias_type ADD COLUMN gid uuid; -ALTER TABLE label_type ADD COLUMN gid uuid; -ALTER TABLE medium_format ADD COLUMN gid uuid; -ALTER TABLE place_alias_type ADD COLUMN gid uuid; -ALTER TABLE place_type ADD COLUMN gid uuid; -ALTER TABLE recording_alias_type ADD COLUMN gid uuid; -ALTER TABLE release_alias_type ADD COLUMN gid uuid; -ALTER TABLE release_group_alias_type ADD COLUMN gid uuid; -ALTER TABLE release_group_secondary_type ADD COLUMN gid uuid; -ALTER TABLE release_group_primary_type ADD COLUMN gid uuid; -ALTER TABLE release_packaging ADD COLUMN gid uuid; -ALTER TABLE release_status ADD COLUMN gid uuid; -ALTER TABLE series_alias_type ADD COLUMN gid uuid; -ALTER TABLE series_ordering_type ADD COLUMN gid uuid; -ALTER TABLE series_type ADD COLUMN gid uuid; -ALTER TABLE work_alias_type ADD COLUMN gid uuid; -ALTER TABLE work_attribute_type ADD COLUMN gid uuid; -ALTER TABLE work_attribute_type_allowed_value ADD COLUMN gid uuid; -ALTER TABLE work_type ADD COLUMN gid uuid; -ALTER TABLE cover_art_archive.art_type ADD COLUMN gid uuid; - --- Generating GIDs -UPDATE area_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'area_type' || id); -UPDATE area_alias_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'area_alias_type' || id); -UPDATE artist_alias_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'artist_alias_type' || id); -UPDATE artist_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'artist_type' || id); -UPDATE editor_collection_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'editor_collection_type' || id); -UPDATE event_alias_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'event_alias_type' || id); -UPDATE event_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'event_type' || id); -UPDATE gender SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'gender' || id); -UPDATE instrument_alias_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'instrument_alias_type' || id); -UPDATE instrument_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'instrument_type' || id); -UPDATE label_alias_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'label_alias_type' || id); -UPDATE label_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'label_type' || id); -UPDATE medium_format SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'medium_format' || id); -UPDATE place_alias_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'place_alias_type' || id); -UPDATE place_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'place_type' || id); -UPDATE recording_alias_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'recording_alias_type' || id); -UPDATE release_alias_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'release_alias_type' || id); -UPDATE release_group_alias_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'release_group_alias_type' || id); -UPDATE release_group_secondary_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'release_group_secondary_type' || id); -UPDATE release_group_primary_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'release_group_primary_type' || id); -UPDATE release_packaging SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'release_packaging' || id); -UPDATE release_status SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'release_status' || id); -UPDATE series_alias_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'series_alias_type' || id); -UPDATE series_ordering_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'series_ordering_type' || id); -UPDATE series_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'series_type' || id); -UPDATE work_alias_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'work_alias_type' || id); -UPDATE work_attribute_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'work_attribute_type' || id); -UPDATE work_attribute_type_allowed_value SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'work_attribute_type_allowed_value' || id); -UPDATE work_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'work_type' || id); -UPDATE cover_art_archive.art_type SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'cover_art_archive.art_type' || id); - --- Adding NOT NULL constraint -ALTER TABLE area_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE area_alias_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE artist_alias_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE artist_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE editor_collection_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE event_alias_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE event_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE gender ALTER COLUMN gid SET NOT NULL; -ALTER TABLE instrument_alias_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE instrument_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE label_alias_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE label_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE medium_format ALTER COLUMN gid SET NOT NULL; -ALTER TABLE place_alias_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE place_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE recording_alias_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE release_alias_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE release_group_alias_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE release_group_secondary_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE release_group_primary_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE release_packaging ALTER COLUMN gid SET NOT NULL; -ALTER TABLE release_status ALTER COLUMN gid SET NOT NULL; -ALTER TABLE series_alias_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE series_ordering_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE series_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE work_alias_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE work_attribute_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE work_attribute_type_allowed_value ALTER COLUMN gid SET NOT NULL; -ALTER TABLE work_type ALTER COLUMN gid SET NOT NULL; -ALTER TABLE cover_art_archive.art_type ALTER COLUMN gid SET NOT NULL; - --- Indexes -CREATE UNIQUE INDEX area_type_idx_gid ON area_type (gid); -CREATE UNIQUE INDEX area_alias_type_idx_gid ON area_alias_type (gid); -CREATE UNIQUE INDEX artist_alias_type_idx_gid ON artist_alias_type (gid); -CREATE UNIQUE INDEX artist_type_idx_gid ON artist_type (gid); -CREATE UNIQUE INDEX editor_collection_type_idx_gid ON editor_collection_type (gid); -CREATE UNIQUE INDEX event_alias_type_idx_gid ON event_alias_type (gid); -CREATE UNIQUE INDEX event_type_idx_gid ON event_type (gid); -CREATE UNIQUE INDEX gender_idx_gid ON gender (gid); -CREATE UNIQUE INDEX instrument_alias_type_idx_gid ON instrument_alias_type (gid); -CREATE UNIQUE INDEX instrument_type_idx_gid ON instrument_type (gid); -CREATE UNIQUE INDEX label_alias_type_idx_gid ON label_alias_type (gid); -CREATE UNIQUE INDEX label_type_idx_gid ON label_type (gid); -CREATE UNIQUE INDEX medium_format_idx_gid ON medium_format (gid); -CREATE UNIQUE INDEX place_alias_type_idx_gid ON place_alias_type (gid); -CREATE UNIQUE INDEX place_type_idx_gid ON place_type (gid); -CREATE UNIQUE INDEX recording_alias_type_idx_gid ON recording_alias_type (gid); -CREATE UNIQUE INDEX release_alias_type_idx_gid ON release_alias_type (gid); -CREATE UNIQUE INDEX release_group_alias_type_idx_gid ON release_group_alias_type (gid); -CREATE UNIQUE INDEX release_group_secondary_type_idx_gid ON release_group_secondary_type (gid); -CREATE UNIQUE INDEX release_group_primary_type_idx_gid ON release_group_primary_type (gid); -CREATE UNIQUE INDEX release_packaging_idx_gid ON release_packaging (gid); -CREATE UNIQUE INDEX release_status_idx_gid ON release_status (gid); -CREATE UNIQUE INDEX series_alias_type_idx_gid ON series_alias_type (gid); -CREATE UNIQUE INDEX series_ordering_type_idx_gid ON series_ordering_type (gid); -CREATE UNIQUE INDEX series_type_idx_gid ON series_type (gid); -CREATE UNIQUE INDEX work_alias_type_idx_gid ON work_alias_type (gid); -CREATE UNIQUE INDEX work_attribute_type_idx_gid ON work_attribute_type (gid); -CREATE UNIQUE INDEX work_attribute_type_allowed_value_idx_gid ON work_attribute_type_allowed_value (gid); -CREATE UNIQUE INDEX work_type_idx_gid ON work_type (gid); -CREATE UNIQUE INDEX art_type_idx_gid ON cover_art_archive.art_type (gid); - --------------------------------------------------------------------------------- -SELECT '20160516-mbs-8720.sql'; - -CREATE TABLE edit_note_recipient ( - recipient INTEGER NOT NULL, -- PK, references editor.id - edit_note INTEGER NOT NULL -- PK, references edit_note.id -); - --- Copying old data -INSERT INTO edit_note_recipient (recipient, edit_note) ( - SELECT edit.editor, edit_note.id - FROM edit_note - JOIN edit ON edit_note.edit = edit.id -); - -ALTER TABLE edit_note_recipient ADD CONSTRAINT edit_note_recipient_pkey PRIMARY KEY (recipient, edit_note); - -CREATE OR REPLACE FUNCTION a_ins_edit_note() RETURNS trigger AS $$ -BEGIN - INSERT INTO edit_note_recipient (recipient, edit_note) ( - SELECT edit.editor, NEW.id - FROM edit - WHERE edit.id = NEW.edit - ); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - --------------------------------------------------------------------------------- -SELECT '20141226-geodesic-index.sql'; - -CREATE INDEX IF NOT EXISTS place_idx_geo ON place USING gist (ll_to_earth(coordinates[0], coordinates[1])) WHERE coordinates IS NOT NULL; --------------------------------------------------------------------------------- -SELECT '20160429-mbs-8656.sql'; - --- MBS-8656: Bring edit table indexes back into sync -DROP INDEX IF EXISTS edit_close_time_idx; -DROP INDEX IF EXISTS edit_date_trunc_idx; -DROP INDEX IF EXISTS edit_date_trunc_idx1; -DROP INDEX IF EXISTS edit_date_trunc_idx2; -DROP INDEX IF EXISTS edit_id_idx; -DROP INDEX IF EXISTS edit_open_time_idx1; -DROP INDEX IF EXISTS edit_status_idx; -ALTER INDEX IF EXISTS edit_open_time_idx RENAME TO edit_idx_open_time; - --------------------------------------------------------------------------------- -SELECT '20151223-edit-note-index.sql'; - --- Broken index exists on totoro, drop it first. -DROP INDEX IF EXISTS edit_note_idx_post_time_edit; - --- For Data::EditNote::find_by_recipient -CREATE INDEX edit_note_idx_post_time_edit ON edit_note (post_time DESC, edit DESC); - --------------------------------------------------------------------------------- -SELECT '20160310-mbs-4501-alternative-tracklists.sql'; - -CREATE TABLE alternative_release ( - id SERIAL, - gid UUID NOT NULL, - release INTEGER NOT NULL, - name VARCHAR, - artist_credit INTEGER, - type INTEGER NOT NULL, - language INTEGER NOT NULL, - script INTEGER NOT NULL, - comment VARCHAR(255) NOT NULL DEFAULT '' - CHECK (name != '') -); - -CREATE TABLE alternative_release_type ( - id SERIAL, - name TEXT NOT NULL, - parent INTEGER, - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid UUID NOT NULL -); - -CREATE TABLE alternative_medium ( - id SERIAL, - medium INTEGER NOT NULL, - alternative_release INTEGER NOT NULL, - name VARCHAR - CHECK (name != '') -); - -CREATE TABLE alternative_track ( - id SERIAL, - name VARCHAR, - artist_credit INTEGER, - ref_count INTEGER NOT NULL DEFAULT 0 - CHECK (name != '' AND (name IS NOT NULL OR artist_credit IS NOT NULL)) -); - -CREATE TABLE alternative_medium_track ( - alternative_medium INTEGER NOT NULL, - track INTEGER NOT NULL, - alternative_track INTEGER NOT NULL -); - -ALTER TABLE alternative_medium ADD CONSTRAINT alternative_medium_pkey PRIMARY KEY (id); -ALTER TABLE alternative_medium_track ADD CONSTRAINT alternative_medium_track_pkey PRIMARY KEY (alternative_medium, track); -ALTER TABLE alternative_release ADD CONSTRAINT alternative_release_pkey PRIMARY KEY (id); -ALTER TABLE alternative_release_type ADD CONSTRAINT alternative_release_type_pkey PRIMARY KEY (id); -ALTER TABLE alternative_track ADD CONSTRAINT alternative_track_pkey PRIMARY KEY (id); - -CREATE INDEX alternative_release_idx_release ON alternative_release (release); -CREATE INDEX alternative_release_idx_name ON alternative_release (name); -CREATE INDEX alternative_release_idx_artist_credit ON alternative_release (artist_credit); -CREATE INDEX alternative_release_idx_language_script ON alternative_release (language, script); -CREATE UNIQUE INDEX alternative_release_idx_gid ON alternative_release (gid); -CREATE INDEX alternative_medium_idx_alternative_release ON alternative_medium (alternative_release); -CREATE INDEX alternative_track_idx_name ON alternative_track (name); -CREATE INDEX alternative_track_idx_artist_credit ON alternative_track (artist_credit); - -CREATE OR REPLACE FUNCTION inc_nullable_artist_credit(row_id integer) RETURNS void AS $$ -BEGIN - IF row_id IS NOT NULL THEN - PERFORM inc_ref_count('artist_credit', row_id, 1); - END IF; - RETURN; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION dec_nullable_artist_credit(row_id integer) RETURNS void AS $$ -BEGIN - IF row_id IS NOT NULL THEN - PERFORM dec_ref_count('artist_credit', row_id, 1); - END IF; - RETURN; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_ins_alternative_release_or_track() RETURNS trigger AS $$ -BEGIN - PERFORM inc_nullable_artist_credit(NEW.artist_credit); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_upd_alternative_release_or_track() RETURNS trigger AS $$ -BEGIN - IF NEW.artist_credit IS DISTINCT FROM OLD.artist_credit THEN - PERFORM inc_nullable_artist_credit(NEW.artist_credit); - PERFORM dec_nullable_artist_credit(OLD.artist_credit); - END IF; - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_del_alternative_release_or_track() RETURNS trigger AS $$ -BEGIN - PERFORM dec_nullable_artist_credit(OLD.artist_credit); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_ins_alternative_medium_track() RETURNS trigger AS $$ -BEGIN - PERFORM inc_ref_count('alternative_track', NEW.alternative_track, 1); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_upd_alternative_medium_track() RETURNS trigger AS $$ -BEGIN - IF NEW.alternative_track IS DISTINCT FROM OLD.alternative_track THEN - PERFORM inc_ref_count('alternative_track', NEW.alternative_track, 1); - PERFORM dec_ref_count('alternative_track', OLD.alternative_track, 1); - END IF; - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_del_alternative_medium_track() RETURNS trigger AS $$ -BEGIN - PERFORM dec_ref_count('alternative_track', OLD.alternative_track, 1); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -INSERT INTO alternative_release_type (id, name, parent, child_order, description, gid) VALUES - (1, 'Translation', NULL, 0, '', generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/alternative_release_type/translation')), - (2, 'Official translation', 1, 0, '', generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/alternative_release_type/official_translation')), - (3, 'Exactly as on cover', NULL, 1, '', generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/alternative_release_type/exactly_as_on_cover')); - --------------------------------------------------------------------------------- -SELECT '20160516-mbs-8656.sql'; - -DROP INDEX IF EXISTS artist_gid_redirect_idx_gid; -DROP INDEX IF EXISTS recording_gid_redirect_idx_gid; -DROP INDEX IF EXISTS track_gid_redirect_idx_gid; -DROP INDEX IF EXISTS url_gid_redirect_idx_gid; -DROP INDEX IF EXISTS work_gid_redirect_idx_gid; - -DROP INDEX IF EXISTS area_gid_redirect_idx_new_id; -DROP INDEX IF EXISTS artist_gid_redirect_idx_new_id; -DROP INDEX IF EXISTS event_gid_redirect_idx_new_id; -DROP INDEX IF EXISTS instrument_gid_redirect_idx_new_id; -DROP INDEX IF EXISTS label_gid_redirect_idx_new_id; -DROP INDEX IF EXISTS place_gid_redirect_idx_new_id; -DROP INDEX IF EXISTS recording_gid_redirect_idx_new_id; -DROP INDEX IF EXISTS release_gid_redirect_idx_new_id; -DROP INDEX IF EXISTS release_group_gid_redirect_idx_new_id; -DROP INDEX IF EXISTS series_gid_redirect_idx_new_id; -DROP INDEX IF EXISTS track_gid_redirect_idx_new_id; -DROP INDEX IF EXISTS url_gid_redirect_idx_new_id; -DROP INDEX IF EXISTS work_gid_redirect_idx_new_id; - -CREATE INDEX area_gid_redirect_idx_new_id ON area_gid_redirect (new_id); -CREATE INDEX artist_gid_redirect_idx_new_id ON artist_gid_redirect (new_id); -CREATE INDEX event_gid_redirect_idx_new_id ON event_gid_redirect (new_id); -CREATE INDEX instrument_gid_redirect_idx_new_id ON instrument_gid_redirect (new_id); -CREATE INDEX label_gid_redirect_idx_new_id ON label_gid_redirect (new_id); -CREATE INDEX place_gid_redirect_idx_new_id ON place_gid_redirect (new_id); -CREATE INDEX recording_gid_redirect_idx_new_id ON recording_gid_redirect (new_id); -CREATE INDEX release_gid_redirect_idx_new_id ON release_gid_redirect (new_id); -CREATE INDEX release_group_gid_redirect_idx_new_id ON release_group_gid_redirect (new_id); -CREATE INDEX series_gid_redirect_idx_new_id ON series_gid_redirect (new_id); -CREATE INDEX track_gid_redirect_idx_new_id ON track_gid_redirect (new_id); -CREATE INDEX url_gid_redirect_idx_new_id ON url_gid_redirect (new_id); -CREATE INDEX work_gid_redirect_idx_new_id ON work_gid_redirect (new_id); - --------------------------------------------------------------------------------- -SELECT '20160507-mbs-8727.sql'; - - -UPDATE vote SET superseded = 't' WHERE id IN ( - 1310304, -- edit #752619 - 1381783, -- edit #835828 - 1389065, -- edit #854892 (vote_time is before id=1389064) - 1429402, -- edit #916266 - 1572699, -- edit #1136298 (vote_time is before id=1572698) - 1611602 -- edit #1194378 -); - -DROP INDEX IF EXISTS vote_idx_editor_edit; -CREATE UNIQUE INDEX vote_idx_editor_edit ON vote (editor, edit) WHERE superseded = FALSE; - --------------------------------------------------------------------------------- -SELECT '20160512-mbs-8719.sql'; - -ALTER TABLE edit - DROP COLUMN yes_votes, - DROP COLUMN no_votes; - -ALTER TABLE editor - DROP COLUMN edits_accepted, - DROP COLUMN edits_rejected, - DROP COLUMN auto_edits_accepted, - DROP COLUMN edits_failed; - --------------------------------------------------------------------------------- -SELECT '20160512-edit-data.sql'; - -DROP INDEX IF EXISTS edit_add_relationship_link_type; -DROP INDEX IF EXISTS edit_edit_relationship_link_type_link; -DROP INDEX IF EXISTS edit_edit_relationship_link_type_new; -DROP INDEX IF EXISTS edit_edit_relationship_link_type_old; -DROP INDEX IF EXISTS edit_remove_relationship_link_type; - -DROP FUNCTION IF EXISTS extract_path_value(text, text); - -CREATE TABLE edit_data ( - edit INTEGER NOT NULL, - data JSONB NOT NULL -); - -INSERT INTO edit_data - SELECT id, data::jsonb - FROM edit - ORDER BY id; - -ALTER TABLE edit_data - ADD CONSTRAINT edit_data_pkey PRIMARY KEY (edit); - -ALTER TABLE edit - DROP COLUMN data; - -CREATE INDEX edit_data_idx_link_type ON edit_data USING GIN ( - array_remove(ARRAY[ - (data#>>'{link_type,id}')::int, - (data#>>'{link,link_type,id}')::int, - (data#>>'{old,link_type,id}')::int, - (data#>>'{new,link_type,id}')::int, - (data#>>'{relationship,link_type,id}')::int - ], NULL) -); - --------------------------------------------------------------------------------- -SELECT '20160514-mbs-8287-a.sql'; - -CREATE TABLE deleted_entity ( - gid UUID NOT NULL, - data JSONB NOT NULL, - deleted_at timestamptz NOT NULL DEFAULT now() -); - - -INSERT INTO deleted_entity (gid, deleted_at, data) -SELECT gid, deleted_at, - jsonb_object('{last_known_name, last_known_comment, entity_gid, entity_type}', - ARRAY[last_known_name, last_known_comment, gid::text, 'artist']) AS data - FROM artist_deletion; - -ALTER TABLE editor_subscribe_artist_deleted DROP CONSTRAINT IF EXISTS editor_subscribe_artist_deleted_fk_gid; - -DROP TABLE artist_deletion; - - -INSERT INTO deleted_entity (gid, deleted_at, data) -SELECT gid, deleted_at, - jsonb_object('{last_known_name, last_known_comment, entity_gid, entity_type}', - ARRAY[last_known_name, last_known_comment, gid::text, 'label']) AS data - FROM label_deletion; - -ALTER TABLE editor_subscribe_label_deleted DROP CONSTRAINT IF EXISTS editor_subscribe_label_deleted_fk_gid; - -DROP TABLE label_deletion; - - -INSERT INTO deleted_entity (gid, deleted_at, data) -SELECT gid, deleted_at, - jsonb_object('{last_known_name, last_known_comment, entity_gid, entity_type}', - ARRAY[last_known_name, last_known_comment, gid::text, 'series']) AS data - FROM series_deletion; - -ALTER TABLE editor_subscribe_series_deleted DROP CONSTRAINT IF EXISTS editor_subscribe_series_deleted_fk_gid; - -DROP TABLE series_deletion; - - -ALTER TABLE deleted_entity ADD CONSTRAINT deleted_entity_pkey PRIMARY KEY (gid); - --------------------------------------------------------------------------------- -SELECT '20160514-mbs-8287-b.sql'; - -CREATE TABLE editor_collection_deleted_entity ( - collection INTEGER NOT NULL, - gid UUID NOT NULL -); - -ALTER TABLE editor_collection_deleted_entity ADD CONSTRAINT editor_collection_deleted_entity_pkey PRIMARY KEY (collection, gid); - --------------------------------------------------------------------------------- -SELECT '20160515-recluster.sql'; - -CLUSTER edit USING edit_pkey; - -ANALYZE edit; - --------------------------------------------------------------------------------- -SELECT '20160516-mbs-8804.sql'; - -DROP INDEX IF EXISTS edit_idx_open_time; -DROP INDEX IF EXISTS edit_idx_close_time; -DROP INDEX IF EXISTS edit_idx_expire_time; -CREATE INDEX edit_idx_open_time ON edit USING BRIN (open_time); -CREATE INDEX edit_idx_close_time ON edit USING BRIN (close_time); -CREATE INDEX edit_idx_expire_time ON edit USING BRIN (expire_time); - -DROP INDEX IF EXISTS edit_note_idx_post_time; -CREATE INDEX edit_note_idx_post_time ON edit_note USING BRIN (post_time); - -DROP INDEX IF EXISTS vote_idx_vote_time; -CREATE INDEX vote_idx_vote_time ON vote USING BRIN (vote_time); - -COMMIT; diff --git a/mbdata/sql/updates/schema-change/23.standalone.sql b/mbdata/sql/updates/schema-change/23.standalone.sql deleted file mode 100644 index aa3a141..0000000 --- a/mbdata/sql/updates/schema-change/23.standalone.sql +++ /dev/null @@ -1,155 +0,0 @@ --- Generated by CompileSchemaScripts.pl from: --- 20160516-mbs-8720-standalone.sql --- 20160310-mbs-4501-alternative-tracklists-fks.sql --- 20160512-edit-data-fk.sql --- 20160514-mbs-8287-a-fks.sql --- 20160514-mbs-8287-b-fks.sql -\set ON_ERROR_STOP 1 -BEGIN; -SET search_path = musicbrainz, public; --------------------------------------------------------------------------------- -SELECT '20160516-mbs-8720-standalone.sql'; - -ALTER TABLE edit_note_recipient - ADD CONSTRAINT edit_note_recipient_fk_recipient - FOREIGN KEY (recipient) - REFERENCES editor(id); - -ALTER TABLE edit_note_recipient - ADD CONSTRAINT edit_note_recipient_fk_edit_note - FOREIGN KEY (edit_note) - REFERENCES edit_note(id); - -CREATE TRIGGER a_ins_edit_note AFTER INSERT ON edit_note - FOR EACH ROW EXECUTE PROCEDURE a_ins_edit_note(); - --------------------------------------------------------------------------------- -SELECT '20160310-mbs-4501-alternative-tracklists-fks.sql'; - -ALTER TABLE alternative_medium - ADD CONSTRAINT alternative_medium_fk_medium - FOREIGN KEY (medium) - REFERENCES medium(id); - -ALTER TABLE alternative_medium - ADD CONSTRAINT alternative_medium_fk_alternative_release - FOREIGN KEY (alternative_release) - REFERENCES alternative_release(id); - -ALTER TABLE alternative_medium_track - ADD CONSTRAINT alternative_medium_track_fk_alternative_medium - FOREIGN KEY (alternative_medium) - REFERENCES alternative_medium(id); - -ALTER TABLE alternative_medium_track - ADD CONSTRAINT alternative_medium_track_fk_track - FOREIGN KEY (track) - REFERENCES track(id); - -ALTER TABLE alternative_medium_track - ADD CONSTRAINT alternative_medium_track_fk_alternative_track - FOREIGN KEY (alternative_track) - REFERENCES alternative_track(id); - -ALTER TABLE alternative_release - ADD CONSTRAINT alternative_release_fk_release - FOREIGN KEY (release) - REFERENCES release(id); - -ALTER TABLE alternative_release - ADD CONSTRAINT alternative_release_fk_artist_credit - FOREIGN KEY (artist_credit) - REFERENCES artist_credit(id); - -ALTER TABLE alternative_release - ADD CONSTRAINT alternative_release_fk_type - FOREIGN KEY (type) - REFERENCES alternative_release_type(id); - -ALTER TABLE alternative_release - ADD CONSTRAINT alternative_release_fk_language - FOREIGN KEY (language) - REFERENCES language(id); - -ALTER TABLE alternative_release - ADD CONSTRAINT alternative_release_fk_script - FOREIGN KEY (script) - REFERENCES script(id); - -ALTER TABLE alternative_release_type - ADD CONSTRAINT alternative_release_type_fk_parent - FOREIGN KEY (parent) - REFERENCES alternative_release_type(id); - -ALTER TABLE alternative_track - ADD CONSTRAINT alternative_track_fk_artist_credit - FOREIGN KEY (artist_credit) - REFERENCES artist_credit(id); - -CREATE TRIGGER a_ins_alternative_release AFTER INSERT ON alternative_release - FOR EACH ROW EXECUTE PROCEDURE a_ins_alternative_release_or_track(); - -CREATE TRIGGER a_ins_alternative_track AFTER INSERT ON alternative_track - FOR EACH ROW EXECUTE PROCEDURE a_ins_alternative_release_or_track(); - -CREATE TRIGGER a_upd_alternative_release AFTER UPDATE ON alternative_release - FOR EACH ROW EXECUTE PROCEDURE a_upd_alternative_release_or_track(); - -CREATE TRIGGER a_upd_alternative_track AFTER UPDATE ON alternative_track - FOR EACH ROW EXECUTE PROCEDURE a_upd_alternative_release_or_track(); - -CREATE TRIGGER a_del_alternative_release AFTER DELETE ON alternative_release - FOR EACH ROW EXECUTE PROCEDURE a_del_alternative_release_or_track(); - -CREATE TRIGGER a_del_alternative_track AFTER DELETE ON alternative_track - FOR EACH ROW EXECUTE PROCEDURE a_del_alternative_release_or_track(); - -CREATE TRIGGER a_ins_alternative_medium_track AFTER INSERT ON alternative_medium_track - FOR EACH ROW EXECUTE PROCEDURE a_ins_alternative_medium_track(); - -CREATE TRIGGER a_upd_alternative_medium_track AFTER UPDATE ON alternative_medium_track - FOR EACH ROW EXECUTE PROCEDURE a_upd_alternative_medium_track(); - -CREATE TRIGGER a_del_alternative_medium_track AFTER DELETE ON alternative_medium_track - FOR EACH ROW EXECUTE PROCEDURE a_del_alternative_medium_track(); - --------------------------------------------------------------------------------- -SELECT '20160512-edit-data-fk.sql'; - -ALTER TABLE edit_data - ADD CONSTRAINT edit_data_fk_edit - FOREIGN KEY (edit) - REFERENCES edit(id); - --------------------------------------------------------------------------------- -SELECT '20160514-mbs-8287-a-fks.sql'; - -ALTER TABLE editor_subscribe_artist_deleted - ADD CONSTRAINT editor_subscribe_artist_deleted_fk_gid - FOREIGN KEY (gid) - REFERENCES deleted_entity(gid); - -ALTER TABLE editor_subscribe_label_deleted - ADD CONSTRAINT editor_subscribe_label_deleted_fk_gid - FOREIGN KEY (gid) - REFERENCES deleted_entity(gid); - -ALTER TABLE editor_subscribe_series_deleted - ADD CONSTRAINT editor_subscribe_series_deleted_fk_gid - FOREIGN KEY (gid) - REFERENCES deleted_entity(gid); - --------------------------------------------------------------------------------- -SELECT '20160514-mbs-8287-b-fks.sql'; - -ALTER TABLE editor_collection_deleted_entity - ADD CONSTRAINT editor_collection_deleted_entity_fk_collection - FOREIGN KEY (collection) - REFERENCES editor_collection(id); - -ALTER TABLE editor_collection_deleted_entity - ADD CONSTRAINT editor_collection_deleted_entity_fk_gid - FOREIGN KEY (gid) - REFERENCES deleted_entity(gid); - -COMMIT; diff --git a/mbdata/sql/updates/schema-change/24.mirror.sql b/mbdata/sql/updates/schema-change/24.mirror.sql deleted file mode 100644 index bd3407e..0000000 --- a/mbdata/sql/updates/schema-change/24.mirror.sql +++ /dev/null @@ -1,816 +0,0 @@ --- Generated by CompileSchemaScripts.pl from: --- 20160602-mbs-8963.sql --- 20170507-mbs-8951.sql --- 20170327-mbs-9271.sql --- 20170401-mbs-8393-entity-attributes.sql --- 20170329-mbs-5452.sql --- 20170503-mbs-9329-event-meta.sql -\set ON_ERROR_STOP 1 -BEGIN; -SET search_path = musicbrainz, public; -SET LOCAL statement_timeout = 0; --------------------------------------------------------------------------------- -SELECT '20160602-mbs-8963.sql'; - -CREATE OR REPLACE FUNCTION a_ins_edit_note() RETURNS trigger AS $$ -BEGIN - INSERT INTO edit_note_recipient (recipient, edit_note) ( - SELECT edit.editor, NEW.id - FROM edit - WHERE edit.id = NEW.edit - AND edit.editor != NEW.editor - ); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -DELETE FROM edit_note_recipient - USING edit_note, edit - WHERE edit_note_recipient.edit_note = edit_note.id - AND edit_note.edit = edit.id - AND edit_note.editor = edit.editor - AND edit.editor = edit_note_recipient.recipient; - --------------------------------------------------------------------------------- -SELECT '20170507-mbs-8951.sql'; - --- Copy of 20160604-mbs-8951.sql for upgrade.sh (minus CONCURRENTLY, since it --- runs inside a transaction). - -DROP INDEX IF EXISTS edit_note_idx_post_time_edit; -CREATE INDEX edit_note_idx_post_time_edit ON edit_note (post_time DESC NULLS LAST, edit DESC); - --------------------------------------------------------------------------------- -SELECT '20170327-mbs-9271.sql'; - -CREATE TABLE old_editor_name ( - name VARCHAR(64) NOT NULL -); - -CREATE UNIQUE INDEX old_editor_name_idx_name ON old_editor_name (LOWER(name)); - -CREATE OR REPLACE FUNCTION check_editor_name() RETURNS trigger AS $$ -BEGIN - IF (SELECT 1 FROM old_editor_name WHERE lower(name) = lower(NEW.name)) - THEN - RAISE EXCEPTION 'Attempt to use a previously-used editor name.'; - END IF; - RETURN NEW; -END; -$$ LANGUAGE 'plpgsql'; - --------------------------------------------------------------------------------- -SELECT '20170401-mbs-8393-entity-attributes.sql'; - ------------------------------------------------------------------------ --- create tables ------------------------------------------------------------------------ - -CREATE TABLE area_attribute_type ( -- replicate (verbose) - id SERIAL, -- PK - name VARCHAR(255) NOT NULL, - comment VARCHAR(255) NOT NULL DEFAULT '', - free_text BOOLEAN NOT NULL, - parent INTEGER, -- references area_attribute_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE area_attribute_type_allowed_value ( -- replicate (verbose) - id SERIAL, -- PK - area_attribute_type INTEGER NOT NULL, -- references area_attribute_type.id - value TEXT, - parent INTEGER, -- references area_attribute_type_allowed_value.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE area_attribute ( -- replicate (verbose) - id SERIAL, -- PK - area INTEGER NOT NULL, -- references area.id - area_attribute_type INTEGER NOT NULL, -- references area_attribute_type.id - area_attribute_type_allowed_value INTEGER, -- references area_attribute_type_allowed_value.id - area_attribute_text TEXT - CHECK ( - (area_attribute_type_allowed_value IS NULL AND area_attribute_text IS NOT NULL) - OR - (area_attribute_type_allowed_value IS NOT NULL AND area_attribute_text IS NULL) - ) -); - -CREATE TABLE artist_attribute_type ( -- replicate (verbose) - id SERIAL, -- PK - name VARCHAR(255) NOT NULL, - comment VARCHAR(255) NOT NULL DEFAULT '', - free_text BOOLEAN NOT NULL, - parent INTEGER, -- references artist_attribute_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE artist_attribute_type_allowed_value ( -- replicate (verbose) - id SERIAL, -- PK - artist_attribute_type INTEGER NOT NULL, -- references artist_attribute_type.id - value TEXT, - parent INTEGER, -- references artist_attribute_type_allowed_value.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE artist_attribute ( -- replicate (verbose) - id SERIAL, -- PK - artist INTEGER NOT NULL, -- references artist.id - artist_attribute_type INTEGER NOT NULL, -- references artist_attribute_type.id - artist_attribute_type_allowed_value INTEGER, -- references artist_attribute_type_allowed_value.id - artist_attribute_text TEXT - CHECK ( - (artist_attribute_type_allowed_value IS NULL AND artist_attribute_text IS NOT NULL) - OR - (artist_attribute_type_allowed_value IS NOT NULL AND artist_attribute_text IS NULL) - ) -); - -CREATE TABLE event_attribute_type ( -- replicate (verbose) - id SERIAL, -- PK - name VARCHAR(255) NOT NULL, - comment VARCHAR(255) NOT NULL DEFAULT '', - free_text BOOLEAN NOT NULL, - parent INTEGER, -- references event_attribute_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE event_attribute_type_allowed_value ( -- replicate (verbose) - id SERIAL, -- PK - event_attribute_type INTEGER NOT NULL, -- references event_attribute_type.id - value TEXT, - parent INTEGER, -- references event_attribute_type_allowed_value.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE event_attribute ( -- replicate (verbose) - id SERIAL, -- PK - event INTEGER NOT NULL, -- references event.id - event_attribute_type INTEGER NOT NULL, -- references event_attribute_type.id - event_attribute_type_allowed_value INTEGER, -- references event_attribute_type_allowed_value.id - event_attribute_text TEXT - CHECK ( - (event_attribute_type_allowed_value IS NULL AND event_attribute_text IS NOT NULL) - OR - (event_attribute_type_allowed_value IS NOT NULL AND event_attribute_text IS NULL) - ) -); - -CREATE TABLE instrument_attribute_type ( -- replicate (verbose) - id SERIAL, -- PK - name VARCHAR(255) NOT NULL, - comment VARCHAR(255) NOT NULL DEFAULT '', - free_text BOOLEAN NOT NULL, - parent INTEGER, -- references instrument_attribute_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE instrument_attribute_type_allowed_value ( -- replicate (verbose) - id SERIAL, -- PK - instrument_attribute_type INTEGER NOT NULL, -- references instrument_attribute_type.id - value TEXT, - parent INTEGER, -- references instrument_attribute_type_allowed_value.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE instrument_attribute ( -- replicate (verbose) - id SERIAL, -- PK - instrument INTEGER NOT NULL, -- references instrument.id - instrument_attribute_type INTEGER NOT NULL, -- references instrument_attribute_type.id - instrument_attribute_type_allowed_value INTEGER, -- references instrument_attribute_type_allowed_value.id - instrument_attribute_text TEXT - CHECK ( - (instrument_attribute_type_allowed_value IS NULL AND instrument_attribute_text IS NOT NULL) - OR - (instrument_attribute_type_allowed_value IS NOT NULL AND instrument_attribute_text IS NULL) - ) -); - -CREATE TABLE label_attribute_type ( -- replicate (verbose) - id SERIAL, -- PK - name VARCHAR(255) NOT NULL, - comment VARCHAR(255) NOT NULL DEFAULT '', - free_text BOOLEAN NOT NULL, - parent INTEGER, -- references label_attribute_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE label_attribute_type_allowed_value ( -- replicate (verbose) - id SERIAL, -- PK - label_attribute_type INTEGER NOT NULL, -- references label_attribute_type.id - value TEXT, - parent INTEGER, -- references label_attribute_type_allowed_value.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE label_attribute ( -- replicate (verbose) - id SERIAL, -- PK - label INTEGER NOT NULL, -- references label.id - label_attribute_type INTEGER NOT NULL, -- references label_attribute_type.id - label_attribute_type_allowed_value INTEGER, -- references label_attribute_type_allowed_value.id - label_attribute_text TEXT - CHECK ( - (label_attribute_type_allowed_value IS NULL AND label_attribute_text IS NOT NULL) - OR - (label_attribute_type_allowed_value IS NOT NULL AND label_attribute_text IS NULL) - ) -); - -CREATE TABLE medium_attribute_type ( -- replicate (verbose) - id SERIAL, -- PK - name VARCHAR(255) NOT NULL, - comment VARCHAR(255) NOT NULL DEFAULT '', - free_text BOOLEAN NOT NULL, - parent INTEGER, -- references medium_attribute_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE medium_attribute_type_allowed_format ( -- replicate (verbose) - medium_attribute_type INTEGER NOT NULL, -- references medium_attribute_type.id - medium_format INTEGER NOT NULL -- references medium_format.id -); - -CREATE TABLE medium_attribute_type_allowed_value ( -- replicate (verbose) - id SERIAL, -- PK - medium_attribute_type INTEGER NOT NULL, -- references medium_attribute_type.id - value TEXT, - parent INTEGER, -- references medium_attribute_type_allowed_value.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE medium_attribute_type_allowed_value_allowed_format ( -- replicate (verbose) - medium_attribute_type_allowed_value INTEGER NOT NULL, -- references medium_attribute_type_allowed_value.id - medium_format INTEGER NOT NULL -- references medium_format.id -); - -CREATE TABLE medium_attribute ( -- replicate (verbose) - id SERIAL, -- PK - medium INTEGER NOT NULL, -- references medium.id - medium_attribute_type INTEGER NOT NULL, -- references medium_attribute_type.id - medium_attribute_type_allowed_value INTEGER, -- references medium_attribute_type_allowed_value.id - medium_attribute_text TEXT - CHECK ( - (medium_attribute_type_allowed_value IS NULL AND medium_attribute_text IS NOT NULL) - OR - (medium_attribute_type_allowed_value IS NOT NULL AND medium_attribute_text IS NULL) - ) -); - -CREATE TABLE place_attribute_type ( -- replicate (verbose) - id SERIAL, -- PK - name VARCHAR(255) NOT NULL, - comment VARCHAR(255) NOT NULL DEFAULT '', - free_text BOOLEAN NOT NULL, - parent INTEGER, -- references place_attribute_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE place_attribute_type_allowed_value ( -- replicate (verbose) - id SERIAL, -- PK - place_attribute_type INTEGER NOT NULL, -- references place_attribute_type.id - value TEXT, - parent INTEGER, -- references place_attribute_type_allowed_value.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE place_attribute ( -- replicate (verbose) - id SERIAL, -- PK - place INTEGER NOT NULL, -- references place.id - place_attribute_type INTEGER NOT NULL, -- references place_attribute_type.id - place_attribute_type_allowed_value INTEGER, -- references place_attribute_type_allowed_value.id - place_attribute_text TEXT - CHECK ( - (place_attribute_type_allowed_value IS NULL AND place_attribute_text IS NOT NULL) - OR - (place_attribute_type_allowed_value IS NOT NULL AND place_attribute_text IS NULL) - ) -); - -CREATE TABLE recording_attribute_type ( -- replicate (verbose) - id SERIAL, -- PK - name VARCHAR(255) NOT NULL, - comment VARCHAR(255) NOT NULL DEFAULT '', - free_text BOOLEAN NOT NULL, - parent INTEGER, -- references recording_attribute_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE recording_attribute_type_allowed_value ( -- replicate (verbose) - id SERIAL, -- PK - recording_attribute_type INTEGER NOT NULL, -- references recording_attribute_type.id - value TEXT, - parent INTEGER, -- references recording_attribute_type_allowed_value.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE recording_attribute ( -- replicate (verbose) - id SERIAL, -- PK - recording INTEGER NOT NULL, -- references recording.id - recording_attribute_type INTEGER NOT NULL, -- references recording_attribute_type.id - recording_attribute_type_allowed_value INTEGER, -- references recording_attribute_type_allowed_value.id - recording_attribute_text TEXT - CHECK ( - (recording_attribute_type_allowed_value IS NULL AND recording_attribute_text IS NOT NULL) - OR - (recording_attribute_type_allowed_value IS NOT NULL AND recording_attribute_text IS NULL) - ) -); - -CREATE TABLE release_attribute_type ( -- replicate (verbose) - id SERIAL, -- PK - name VARCHAR(255) NOT NULL, - comment VARCHAR(255) NOT NULL DEFAULT '', - free_text BOOLEAN NOT NULL, - parent INTEGER, -- references release_attribute_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE release_attribute_type_allowed_value ( -- replicate (verbose) - id SERIAL, -- PK - release_attribute_type INTEGER NOT NULL, -- references release_attribute_type.id - value TEXT, - parent INTEGER, -- references release_attribute_type_allowed_value.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE release_attribute ( -- replicate (verbose) - id SERIAL, -- PK - release INTEGER NOT NULL, -- references release.id - release_attribute_type INTEGER NOT NULL, -- references release_attribute_type.id - release_attribute_type_allowed_value INTEGER, -- references release_attribute_type_allowed_value.id - release_attribute_text TEXT - CHECK ( - (release_attribute_type_allowed_value IS NULL AND release_attribute_text IS NOT NULL) - OR - (release_attribute_type_allowed_value IS NOT NULL AND release_attribute_text IS NULL) - ) -); - -CREATE TABLE release_group_attribute_type ( -- replicate (verbose) - id SERIAL, -- PK - name VARCHAR(255) NOT NULL, - comment VARCHAR(255) NOT NULL DEFAULT '', - free_text BOOLEAN NOT NULL, - parent INTEGER, -- references release_group_attribute_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE release_group_attribute_type_allowed_value ( -- replicate (verbose) - id SERIAL, -- PK - release_group_attribute_type INTEGER NOT NULL, -- references release_group_attribute_type.id - value TEXT, - parent INTEGER, -- references release_group_attribute_type_allowed_value.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE release_group_attribute ( -- replicate (verbose) - id SERIAL, -- PK - release_group INTEGER NOT NULL, -- references release_group.id - release_group_attribute_type INTEGER NOT NULL, -- references release_group_attribute_type.id - release_group_attribute_type_allowed_value INTEGER, -- references release_group_attribute_type_allowed_value.id - release_group_attribute_text TEXT - CHECK ( - (release_group_attribute_type_allowed_value IS NULL AND release_group_attribute_text IS NOT NULL) - OR - (release_group_attribute_type_allowed_value IS NOT NULL AND release_group_attribute_text IS NULL) - ) -); - -CREATE TABLE series_attribute_type ( -- replicate (verbose) - id SERIAL, -- PK - name VARCHAR(255) NOT NULL, - comment VARCHAR(255) NOT NULL DEFAULT '', - free_text BOOLEAN NOT NULL, - parent INTEGER, -- references series_attribute_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE series_attribute_type_allowed_value ( -- replicate (verbose) - id SERIAL, -- PK - series_attribute_type INTEGER NOT NULL, -- references series_attribute_type.id - value TEXT, - parent INTEGER, -- references series_attribute_type_allowed_value.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE series_attribute ( -- replicate (verbose) - id SERIAL, -- PK - series INTEGER NOT NULL, -- references series.id - series_attribute_type INTEGER NOT NULL, -- references series_attribute_type.id - series_attribute_type_allowed_value INTEGER, -- references series_attribute_type_allowed_value.id - series_attribute_text TEXT - CHECK ( - (series_attribute_type_allowed_value IS NULL AND series_attribute_text IS NOT NULL) - OR - (series_attribute_type_allowed_value IS NOT NULL AND series_attribute_text IS NULL) - ) -); - ------------------------------------------------------------------------ --- add primary key constraints ------------------------------------------------------------------------ - -ALTER TABLE area_attribute ADD CONSTRAINT area_attribute_pkey PRIMARY KEY (id); -ALTER TABLE area_attribute_type ADD CONSTRAINT area_attribute_type_pkey PRIMARY KEY (id); -ALTER TABLE area_attribute_type_allowed_value ADD CONSTRAINT area_attribute_type_allowed_value_pkey PRIMARY KEY (id); -ALTER TABLE artist_attribute ADD CONSTRAINT artist_attribute_pkey PRIMARY KEY (id); -ALTER TABLE artist_attribute_type ADD CONSTRAINT artist_attribute_type_pkey PRIMARY KEY (id); -ALTER TABLE artist_attribute_type_allowed_value ADD CONSTRAINT artist_attribute_type_allowed_value_pkey PRIMARY KEY (id); -ALTER TABLE event_attribute ADD CONSTRAINT event_attribute_pkey PRIMARY KEY (id); -ALTER TABLE event_attribute_type ADD CONSTRAINT event_attribute_type_pkey PRIMARY KEY (id); -ALTER TABLE event_attribute_type_allowed_value ADD CONSTRAINT event_attribute_type_allowed_value_pkey PRIMARY KEY (id); -ALTER TABLE instrument_attribute ADD CONSTRAINT instrument_attribute_pkey PRIMARY KEY (id); -ALTER TABLE instrument_attribute_type ADD CONSTRAINT instrument_attribute_type_pkey PRIMARY KEY (id); -ALTER TABLE instrument_attribute_type_allowed_value ADD CONSTRAINT instrument_attribute_type_allowed_value_pkey PRIMARY KEY (id); -ALTER TABLE label_attribute ADD CONSTRAINT label_attribute_pkey PRIMARY KEY (id); -ALTER TABLE label_attribute_type ADD CONSTRAINT label_attribute_type_pkey PRIMARY KEY (id); -ALTER TABLE label_attribute_type_allowed_value ADD CONSTRAINT label_attribute_type_allowed_value_pkey PRIMARY KEY (id); -ALTER TABLE medium_attribute ADD CONSTRAINT medium_attribute_pkey PRIMARY KEY (id); -ALTER TABLE medium_attribute_type ADD CONSTRAINT medium_attribute_type_pkey PRIMARY KEY (id); -ALTER TABLE medium_attribute_type_allowed_value ADD CONSTRAINT medium_attribute_type_allowed_value_pkey PRIMARY KEY (id); -ALTER TABLE place_attribute ADD CONSTRAINT place_attribute_pkey PRIMARY KEY (id); -ALTER TABLE place_attribute_type ADD CONSTRAINT place_attribute_type_pkey PRIMARY KEY (id); -ALTER TABLE place_attribute_type_allowed_value ADD CONSTRAINT place_attribute_type_allowed_value_pkey PRIMARY KEY (id); -ALTER TABLE recording_attribute ADD CONSTRAINT recording_attribute_pkey PRIMARY KEY (id); -ALTER TABLE recording_attribute_type ADD CONSTRAINT recording_attribute_type_pkey PRIMARY KEY (id); -ALTER TABLE recording_attribute_type_allowed_value ADD CONSTRAINT recording_attribute_type_allowed_value_pkey PRIMARY KEY (id); -ALTER TABLE release_attribute ADD CONSTRAINT release_attribute_pkey PRIMARY KEY (id); -ALTER TABLE release_attribute_type ADD CONSTRAINT release_attribute_type_pkey PRIMARY KEY (id); -ALTER TABLE release_attribute_type_allowed_value ADD CONSTRAINT release_attribute_type_allowed_value_pkey PRIMARY KEY (id); -ALTER TABLE release_group_attribute ADD CONSTRAINT release_group_attribute_pkey PRIMARY KEY (id); -ALTER TABLE release_group_attribute_type ADD CONSTRAINT release_group_attribute_type_pkey PRIMARY KEY (id); -ALTER TABLE release_group_attribute_type_allowed_value ADD CONSTRAINT release_group_attribute_type_allowed_value_pkey PRIMARY KEY (id); -ALTER TABLE series_attribute ADD CONSTRAINT series_attribute_pkey PRIMARY KEY (id); -ALTER TABLE series_attribute_type ADD CONSTRAINT series_attribute_type_pkey PRIMARY KEY (id); -ALTER TABLE series_attribute_type_allowed_value ADD CONSTRAINT series_attribute_type_allowed_value_pkey PRIMARY KEY (id); - ------------------------------------------------------------------------ --- create indexes ------------------------------------------------------------------------ - -CREATE INDEX area_attribute_idx_area ON area_attribute (area); - -CREATE UNIQUE INDEX area_attribute_type_idx_gid ON area_attribute_type (gid); - -CREATE INDEX area_attribute_type_allowed_value_idx_name ON area_attribute_type_allowed_value (area_attribute_type); -CREATE UNIQUE INDEX area_attribute_type_allowed_value_idx_gid ON area_attribute_type_allowed_value (gid); - -CREATE INDEX artist_attribute_idx_artist ON artist_attribute (artist); - -CREATE UNIQUE INDEX artist_attribute_type_idx_gid ON artist_attribute_type (gid); - -CREATE INDEX artist_attribute_type_allowed_value_idx_name ON artist_attribute_type_allowed_value (artist_attribute_type); -CREATE UNIQUE INDEX artist_attribute_type_allowed_value_idx_gid ON artist_attribute_type_allowed_value (gid); - -CREATE INDEX event_attribute_idx_event ON event_attribute (event); - -CREATE UNIQUE INDEX event_attribute_type_idx_gid ON event_attribute_type (gid); - -CREATE INDEX event_attribute_type_allowed_value_idx_name ON event_attribute_type_allowed_value (event_attribute_type); -CREATE UNIQUE INDEX event_attribute_type_allowed_value_idx_gid ON event_attribute_type_allowed_value (gid); - -CREATE INDEX instrument_attribute_idx_instrument ON instrument_attribute (instrument); - -CREATE UNIQUE INDEX instrument_attribute_type_idx_gid ON instrument_attribute_type (gid); - -CREATE INDEX instrument_attribute_type_allowed_value_idx_name ON instrument_attribute_type_allowed_value (instrument_attribute_type); -CREATE UNIQUE INDEX instrument_attribute_type_allowed_value_idx_gid ON instrument_attribute_type_allowed_value (gid); - -CREATE INDEX label_attribute_idx_label ON label_attribute (label); - -CREATE UNIQUE INDEX label_attribute_type_idx_gid ON label_attribute_type (gid); - -CREATE INDEX label_attribute_type_allowed_value_idx_name ON label_attribute_type_allowed_value (label_attribute_type); -CREATE UNIQUE INDEX label_attribute_type_allowed_value_idx_gid ON label_attribute_type_allowed_value (gid); - -CREATE INDEX medium_attribute_idx_medium ON medium_attribute (medium); - -CREATE UNIQUE INDEX medium_attribute_type_idx_gid ON medium_attribute_type (gid); - -CREATE INDEX medium_attribute_type_allowed_value_idx_name ON medium_attribute_type_allowed_value (medium_attribute_type); -CREATE UNIQUE INDEX medium_attribute_type_allowed_value_idx_gid ON medium_attribute_type_allowed_value (gid); - -CREATE INDEX place_attribute_idx_place ON place_attribute (place); - -CREATE UNIQUE INDEX place_attribute_type_idx_gid ON place_attribute_type (gid); - -CREATE INDEX place_attribute_type_allowed_value_idx_name ON place_attribute_type_allowed_value (place_attribute_type); -CREATE UNIQUE INDEX place_attribute_type_allowed_value_idx_gid ON place_attribute_type_allowed_value (gid); - -CREATE INDEX recording_attribute_idx_recording ON recording_attribute (recording); - -CREATE UNIQUE INDEX recording_attribute_type_idx_gid ON recording_attribute_type (gid); - -CREATE INDEX recording_attribute_type_allowed_value_idx_name ON recording_attribute_type_allowed_value (recording_attribute_type); -CREATE UNIQUE INDEX recording_attribute_type_allowed_value_idx_gid ON recording_attribute_type_allowed_value (gid); - -CREATE INDEX release_attribute_idx_release ON release_attribute (release); - -CREATE UNIQUE INDEX release_attribute_type_idx_gid ON release_attribute_type (gid); - -CREATE INDEX release_attribute_type_allowed_value_idx_name ON release_attribute_type_allowed_value (release_attribute_type); -CREATE UNIQUE INDEX release_attribute_type_allowed_value_idx_gid ON release_attribute_type_allowed_value (gid); - -CREATE INDEX release_group_attribute_idx_release_group ON release_group_attribute (release_group); - -CREATE UNIQUE INDEX release_group_attribute_type_idx_gid ON release_group_attribute_type (gid); - -CREATE INDEX release_group_attribute_type_allowed_value_idx_name ON release_group_attribute_type_allowed_value (release_group_attribute_type); -CREATE UNIQUE INDEX release_group_attribute_type_allowed_value_idx_gid ON release_group_attribute_type_allowed_value (gid); - -CREATE INDEX series_attribute_idx_series ON series_attribute (series); - -CREATE UNIQUE INDEX series_attribute_type_idx_gid ON series_attribute_type (gid); - -CREATE INDEX series_attribute_type_allowed_value_idx_name ON series_attribute_type_allowed_value (series_attribute_type); -CREATE UNIQUE INDEX series_attribute_type_allowed_value_idx_gid ON series_attribute_type_allowed_value (gid); - ------------------------------------------------------------------------ --- create functions --- ensure attribute type allows free text if free text is added ------------------------------------------------------------------------ - -CREATE OR REPLACE FUNCTION ensure_area_attribute_type_allows_text() -RETURNS trigger AS $$ -BEGIN - IF NEW.area_attribute_text IS NOT NULL - AND NOT EXISTS ( - SELECT TRUE - FROM area_attribute_type - WHERE area_attribute_type.id = NEW.area_attribute_type - AND free_text - ) - THEN - RAISE EXCEPTION 'This attribute type can not contain free text'; - ELSE - RETURN NEW; - END IF; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION ensure_artist_attribute_type_allows_text() -RETURNS trigger AS $$ -BEGIN - IF NEW.artist_attribute_text IS NOT NULL - AND NOT EXISTS ( - SELECT TRUE - FROM artist_attribute_type - WHERE artist_attribute_type.id = NEW.artist_attribute_type - AND free_text - ) - THEN - RAISE EXCEPTION 'This attribute type can not contain free text'; - ELSE - RETURN NEW; - END IF; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION ensure_event_attribute_type_allows_text() -RETURNS trigger AS $$ -BEGIN - IF NEW.event_attribute_text IS NOT NULL - AND NOT EXISTS ( - SELECT TRUE - FROM event_attribute_type - WHERE event_attribute_type.id = NEW.event_attribute_type - AND free_text - ) - THEN - RAISE EXCEPTION 'This attribute type can not contain free text'; - ELSE - RETURN NEW; - END IF; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION ensure_instrument_attribute_type_allows_text() -RETURNS trigger AS $$ -BEGIN - IF NEW.instrument_attribute_text IS NOT NULL - AND NOT EXISTS ( - SELECT TRUE - FROM instrument_attribute_type - WHERE instrument_attribute_type.id = NEW.instrument_attribute_type - AND free_text - ) - THEN - RAISE EXCEPTION 'This attribute type can not contain free text'; - ELSE - RETURN NEW; - END IF; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION ensure_label_attribute_type_allows_text() -RETURNS trigger AS $$ -BEGIN - IF NEW.label_attribute_text IS NOT NULL - AND NOT EXISTS ( - SELECT TRUE - FROM label_attribute_type - WHERE label_attribute_type.id = NEW.label_attribute_type - AND free_text - ) - THEN - RAISE EXCEPTION 'This attribute type can not contain free text'; - ELSE - RETURN NEW; - END IF; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION ensure_medium_attribute_type_allows_text() -RETURNS trigger AS $$ -BEGIN - IF NEW.medium_attribute_text IS NOT NULL - AND NOT EXISTS ( - SELECT TRUE - FROM medium_attribute_type - WHERE medium_attribute_type.id = NEW.medium_attribute_type - AND free_text - ) - THEN - RAISE EXCEPTION 'This attribute type can not contain free text'; - ELSE - RETURN NEW; - END IF; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION ensure_place_attribute_type_allows_text() -RETURNS trigger AS $$ -BEGIN - IF NEW.place_attribute_text IS NOT NULL - AND NOT EXISTS ( - SELECT TRUE - FROM place_attribute_type - WHERE place_attribute_type.id = NEW.place_attribute_type - AND free_text - ) - THEN - RAISE EXCEPTION 'This attribute type can not contain free text'; - ELSE - RETURN NEW; - END IF; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION ensure_recording_attribute_type_allows_text() -RETURNS trigger AS $$ -BEGIN - IF NEW.recording_attribute_text IS NOT NULL - AND NOT EXISTS ( - SELECT TRUE - FROM recording_attribute_type - WHERE recording_attribute_type.id = NEW.recording_attribute_type - AND free_text - ) - THEN - RAISE EXCEPTION 'This attribute type can not contain free text'; - ELSE - RETURN NEW; - END IF; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION ensure_release_attribute_type_allows_text() -RETURNS trigger AS $$ -BEGIN - IF NEW.release_attribute_text IS NOT NULL - AND NOT EXISTS ( - SELECT TRUE - FROM release_attribute_type - WHERE release_attribute_type.id = NEW.release_attribute_type - AND free_text - ) - THEN - RAISE EXCEPTION 'This attribute type can not contain free text'; - ELSE - RETURN NEW; - END IF; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION ensure_release_group_attribute_type_allows_text() -RETURNS trigger AS $$ - BEGIN - IF NEW.release_group_attribute_text IS NOT NULL - AND NOT EXISTS ( - SELECT TRUE FROM release_group_attribute_type - WHERE release_group_attribute_type.id = NEW.release_group_attribute_type - AND free_text - ) - THEN - RAISE EXCEPTION 'This attribute type can not contain free text'; - ELSE RETURN NEW; - END IF; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION ensure_series_attribute_type_allows_text() -RETURNS trigger AS $$ -BEGIN - IF NEW.series_attribute_text IS NOT NULL - AND NOT EXISTS ( - SELECT TRUE - FROM series_attribute_type - WHERE series_attribute_type.id = NEW.series_attribute_type - AND free_text - ) - THEN - RAISE EXCEPTION 'This attribute type can not contain free text'; - ELSE - RETURN NEW; - END IF; -END; -$$ LANGUAGE 'plpgsql'; - --------------------------------------------------------------------------------- -SELECT '20170329-mbs-5452.sql'; - -CREATE TABLE work_language ( - work INTEGER NOT NULL, - language INTEGER NOT NULL, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - created TIMESTAMP WITH TIME ZONE DEFAULT NOW() -); - -INSERT INTO work_language (work, language) - (SELECT id, language FROM work WHERE language IS NOT NULL); - -ALTER TABLE work_language - ADD CONSTRAINT work_language_pkey - PRIMARY KEY (work, language); - -ALTER TABLE work DROP COLUMN language; - --------------------------------------------------------------------------------- -SELECT '20170503-mbs-9329-event-meta.sql'; - -CREATE OR REPLACE FUNCTION a_ins_event() RETURNS trigger AS $$ -BEGIN - INSERT INTO event_meta (id) VALUES (NEW.id); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -TRUNCATE event_meta; - -INSERT INTO event_meta (id) (SELECT id FROM event); - -UPDATE event_meta - SET rating = ratings.rating, - rating_count = ratings.rating_count - FROM (SELECT event, - trunc((sum(rating) / count(rating)) + 0.5) AS rating, - count(rating) AS rating_count - FROM event_rating_raw - GROUP BY event) ratings - WHERE event_meta.id = ratings.event; - -COMMIT; diff --git a/mbdata/sql/updates/schema-change/24.standalone.sql b/mbdata/sql/updates/schema-change/24.standalone.sql deleted file mode 100644 index c8d90c7..0000000 --- a/mbdata/sql/updates/schema-change/24.standalone.sql +++ /dev/null @@ -1,432 +0,0 @@ --- Generated by CompileSchemaScripts.pl from: --- 20170327-mbs-9271-standalone.sql --- 20170401-mbs-8393-entity-attributes-fks.sql --- 20170329-mbs-5452-fks.sql --- 20170503-mbs-9329-event-meta-standalone.sql -\set ON_ERROR_STOP 1 -BEGIN; -SET search_path = musicbrainz, public; -SET LOCAL statement_timeout = 0; --------------------------------------------------------------------------------- -SELECT '20170327-mbs-9271-standalone.sql'; - -CREATE TRIGGER check_editor_name BEFORE UPDATE OR INSERT ON editor - FOR EACH ROW EXECUTE PROCEDURE check_editor_name(); - --------------------------------------------------------------------------------- -SELECT '20170401-mbs-8393-entity-attributes-fks.sql'; - ------------------------------------------------------------------------ --- add foreign key constraints ------------------------------------------------------------------------ - -ALTER TABLE area_attribute - ADD CONSTRAINT area_attribute_fk_area - FOREIGN KEY (area) - REFERENCES area(id); - -ALTER TABLE area_attribute - ADD CONSTRAINT area_attribute_fk_area_attribute_type - FOREIGN KEY (area_attribute_type) - REFERENCES area_attribute_type(id); - -ALTER TABLE area_attribute - ADD CONSTRAINT area_attribute_fk_area_attribute_type_allowed_value - FOREIGN KEY (area_attribute_type_allowed_value) - REFERENCES area_attribute_type_allowed_value(id); - -ALTER TABLE area_attribute_type - ADD CONSTRAINT area_attribute_type_fk_parent - FOREIGN KEY (parent) - REFERENCES area_attribute_type(id); - -ALTER TABLE area_attribute_type_allowed_value - ADD CONSTRAINT area_attribute_type_allowed_value_fk_area_attribute_type - FOREIGN KEY (area_attribute_type) - REFERENCES area_attribute_type(id); - -ALTER TABLE area_attribute_type_allowed_value - ADD CONSTRAINT area_attribute_type_allowed_value_fk_parent - FOREIGN KEY (parent) - REFERENCES area_attribute_type_allowed_value(id); - -ALTER TABLE artist_attribute - ADD CONSTRAINT artist_attribute_fk_artist - FOREIGN KEY (artist) - REFERENCES artist(id); - -ALTER TABLE artist_attribute - ADD CONSTRAINT artist_attribute_fk_artist_attribute_type - FOREIGN KEY (artist_attribute_type) - REFERENCES artist_attribute_type(id); - -ALTER TABLE artist_attribute - ADD CONSTRAINT artist_attribute_fk_artist_attribute_type_allowed_value - FOREIGN KEY (artist_attribute_type_allowed_value) - REFERENCES artist_attribute_type_allowed_value(id); - -ALTER TABLE artist_attribute_type - ADD CONSTRAINT artist_attribute_type_fk_parent - FOREIGN KEY (parent) - REFERENCES artist_attribute_type(id); - -ALTER TABLE artist_attribute_type_allowed_value - ADD CONSTRAINT artist_attribute_type_allowed_value_fk_artist_attribute_type - FOREIGN KEY (artist_attribute_type) - REFERENCES artist_attribute_type(id); - -ALTER TABLE artist_attribute_type_allowed_value - ADD CONSTRAINT artist_attribute_type_allowed_value_fk_parent - FOREIGN KEY (parent) - REFERENCES artist_attribute_type_allowed_value(id); - -ALTER TABLE event_attribute - ADD CONSTRAINT event_attribute_fk_event - FOREIGN KEY (event) - REFERENCES event(id); - -ALTER TABLE event_attribute - ADD CONSTRAINT event_attribute_fk_event_attribute_type - FOREIGN KEY (event_attribute_type) - REFERENCES event_attribute_type(id); - -ALTER TABLE event_attribute - ADD CONSTRAINT event_attribute_fk_event_attribute_type_allowed_value - FOREIGN KEY (event_attribute_type_allowed_value) - REFERENCES event_attribute_type_allowed_value(id); - -ALTER TABLE event_attribute_type - ADD CONSTRAINT event_attribute_type_fk_parent - FOREIGN KEY (parent) - REFERENCES event_attribute_type(id); - -ALTER TABLE event_attribute_type_allowed_value - ADD CONSTRAINT event_attribute_type_allowed_value_fk_event_attribute_type - FOREIGN KEY (event_attribute_type) - REFERENCES event_attribute_type(id); - -ALTER TABLE event_attribute_type_allowed_value - ADD CONSTRAINT event_attribute_type_allowed_value_fk_parent - FOREIGN KEY (parent) - REFERENCES event_attribute_type_allowed_value(id); - -ALTER TABLE instrument_attribute - ADD CONSTRAINT instrument_attribute_fk_instrument - FOREIGN KEY (instrument) - REFERENCES instrument(id); - -ALTER TABLE instrument_attribute - ADD CONSTRAINT instrument_attribute_fk_instrument_attribute_type - FOREIGN KEY (instrument_attribute_type) - REFERENCES instrument_attribute_type(id); - -ALTER TABLE instrument_attribute - ADD CONSTRAINT instrument_attribute_fk_instrument_attribute_type_allowed_value - FOREIGN KEY (instrument_attribute_type_allowed_value) - REFERENCES instrument_attribute_type_allowed_value(id); - -ALTER TABLE instrument_attribute_type - ADD CONSTRAINT instrument_attribute_type_fk_parent - FOREIGN KEY (parent) - REFERENCES instrument_attribute_type(id); - -ALTER TABLE instrument_attribute_type_allowed_value - ADD CONSTRAINT instrument_attribute_type_allowed_value_fk_instrument_attribute_type - FOREIGN KEY (instrument_attribute_type) - REFERENCES instrument_attribute_type(id); - -ALTER TABLE instrument_attribute_type_allowed_value - ADD CONSTRAINT instrument_attribute_type_allowed_value_fk_parent - FOREIGN KEY (parent) - REFERENCES instrument_attribute_type_allowed_value(id); - -ALTER TABLE label_attribute - ADD CONSTRAINT label_attribute_fk_label - FOREIGN KEY (label) - REFERENCES label(id); - -ALTER TABLE label_attribute - ADD CONSTRAINT label_attribute_fk_label_attribute_type - FOREIGN KEY (label_attribute_type) - REFERENCES label_attribute_type(id); - -ALTER TABLE label_attribute - ADD CONSTRAINT label_attribute_fk_label_attribute_type_allowed_value - FOREIGN KEY (label_attribute_type_allowed_value) - REFERENCES label_attribute_type_allowed_value(id); - -ALTER TABLE label_attribute_type - ADD CONSTRAINT label_attribute_type_fk_parent - FOREIGN KEY (parent) - REFERENCES label_attribute_type(id); - -ALTER TABLE label_attribute_type_allowed_value - ADD CONSTRAINT label_attribute_type_allowed_value_fk_label_attribute_type - FOREIGN KEY (label_attribute_type) - REFERENCES label_attribute_type(id); - -ALTER TABLE label_attribute_type_allowed_value - ADD CONSTRAINT label_attribute_type_allowed_value_fk_parent - FOREIGN KEY (parent) - REFERENCES label_attribute_type_allowed_value(id); - -ALTER TABLE medium_attribute - ADD CONSTRAINT medium_attribute_fk_medium - FOREIGN KEY (medium) - REFERENCES medium(id); - -ALTER TABLE medium_attribute - ADD CONSTRAINT medium_attribute_fk_medium_attribute_type - FOREIGN KEY (medium_attribute_type) - REFERENCES medium_attribute_type(id); - -ALTER TABLE medium_attribute - ADD CONSTRAINT medium_attribute_fk_medium_attribute_type_allowed_value - FOREIGN KEY (medium_attribute_type_allowed_value) - REFERENCES medium_attribute_type_allowed_value(id); - -ALTER TABLE medium_attribute_type - ADD CONSTRAINT medium_attribute_type_fk_parent - FOREIGN KEY (parent) - REFERENCES medium_attribute_type(id); - -ALTER TABLE medium_attribute_type_allowed_format - ADD CONSTRAINT medium_attribute_type_allowed_format_fk_medium_attribute_type - FOREIGN KEY (medium_attribute_type) - REFERENCES medium_attribute_type(id); - -ALTER TABLE medium_attribute_type_allowed_format - ADD CONSTRAINT medium_attribute_type_allowed_format_fk_medium_format - FOREIGN KEY (medium_format) - REFERENCES medium_format(id); - -ALTER TABLE medium_attribute_type_allowed_value - ADD CONSTRAINT medium_attribute_type_allowed_value_fk_medium_attribute_type - FOREIGN KEY (medium_attribute_type) - REFERENCES medium_attribute_type(id); - -ALTER TABLE medium_attribute_type_allowed_value - ADD CONSTRAINT medium_attribute_type_allowed_value_fk_parent - FOREIGN KEY (parent) - REFERENCES medium_attribute_type_allowed_value(id); - -ALTER TABLE medium_attribute_type_allowed_value_allowed_format - ADD CONSTRAINT medium_attribute_type_allowed_value_allowed_format_fk_medium_attribute_type_allowed_value - FOREIGN KEY (medium_attribute_type_allowed_value) - REFERENCES medium_attribute_type_allowed_value(id); - -ALTER TABLE medium_attribute_type_allowed_value_allowed_format - ADD CONSTRAINT medium_attribute_type_allowed_value_allowed_format_fk_medium_format - FOREIGN KEY (medium_format) - REFERENCES medium_format(id); - -ALTER TABLE place_attribute - ADD CONSTRAINT place_attribute_fk_place - FOREIGN KEY (place) - REFERENCES place(id); - -ALTER TABLE place_attribute - ADD CONSTRAINT place_attribute_fk_place_attribute_type - FOREIGN KEY (place_attribute_type) - REFERENCES place_attribute_type(id); - -ALTER TABLE place_attribute - ADD CONSTRAINT place_attribute_fk_place_attribute_type_allowed_value - FOREIGN KEY (place_attribute_type_allowed_value) - REFERENCES place_attribute_type_allowed_value(id); - -ALTER TABLE place_attribute_type - ADD CONSTRAINT place_attribute_type_fk_parent - FOREIGN KEY (parent) - REFERENCES place_attribute_type(id); - -ALTER TABLE place_attribute_type_allowed_value - ADD CONSTRAINT place_attribute_type_allowed_value_fk_place_attribute_type - FOREIGN KEY (place_attribute_type) - REFERENCES place_attribute_type(id); - -ALTER TABLE place_attribute_type_allowed_value - ADD CONSTRAINT place_attribute_type_allowed_value_fk_parent - FOREIGN KEY (parent) - REFERENCES place_attribute_type_allowed_value(id); - -ALTER TABLE recording_attribute - ADD CONSTRAINT recording_attribute_fk_recording - FOREIGN KEY (recording) - REFERENCES recording(id); - -ALTER TABLE recording_attribute - ADD CONSTRAINT recording_attribute_fk_recording_attribute_type - FOREIGN KEY (recording_attribute_type) - REFERENCES recording_attribute_type(id); - -ALTER TABLE recording_attribute - ADD CONSTRAINT recording_attribute_fk_recording_attribute_type_allowed_value - FOREIGN KEY (recording_attribute_type_allowed_value) - REFERENCES recording_attribute_type_allowed_value(id); - -ALTER TABLE recording_attribute_type - ADD CONSTRAINT recording_attribute_type_fk_parent - FOREIGN KEY (parent) - REFERENCES recording_attribute_type(id); - -ALTER TABLE recording_attribute_type_allowed_value - ADD CONSTRAINT recording_attribute_type_allowed_value_fk_recording_attribute_type - FOREIGN KEY (recording_attribute_type) - REFERENCES recording_attribute_type(id); - -ALTER TABLE recording_attribute_type_allowed_value - ADD CONSTRAINT recording_attribute_type_allowed_value_fk_parent - FOREIGN KEY (parent) - REFERENCES recording_attribute_type_allowed_value(id); - -ALTER TABLE release_attribute - ADD CONSTRAINT release_attribute_fk_release - FOREIGN KEY (release) - REFERENCES release(id); - -ALTER TABLE release_attribute - ADD CONSTRAINT release_attribute_fk_release_attribute_type - FOREIGN KEY (release_attribute_type) - REFERENCES release_attribute_type(id); - -ALTER TABLE release_attribute - ADD CONSTRAINT release_attribute_fk_release_attribute_type_allowed_value - FOREIGN KEY (release_attribute_type_allowed_value) - REFERENCES release_attribute_type_allowed_value(id); - -ALTER TABLE release_attribute_type - ADD CONSTRAINT release_attribute_type_fk_parent - FOREIGN KEY (parent) - REFERENCES release_attribute_type(id); - -ALTER TABLE release_attribute_type_allowed_value - ADD CONSTRAINT release_attribute_type_allowed_value_fk_release_attribute_type - FOREIGN KEY (release_attribute_type) - REFERENCES release_attribute_type(id); - -ALTER TABLE release_attribute_type_allowed_value - ADD CONSTRAINT release_attribute_type_allowed_value_fk_parent - FOREIGN KEY (parent) - REFERENCES release_attribute_type_allowed_value(id); - -ALTER TABLE release_group_attribute - ADD CONSTRAINT release_group_attribute_fk_release_group - FOREIGN KEY (release_group) - REFERENCES release_group(id); - -ALTER TABLE release_group_attribute - ADD CONSTRAINT release_group_attribute_fk_release_group_attribute_type - FOREIGN KEY (release_group_attribute_type) - REFERENCES release_group_attribute_type(id); - -ALTER TABLE release_group_attribute - ADD CONSTRAINT release_group_attribute_fk_release_group_attribute_type_allowed_value - FOREIGN KEY (release_group_attribute_type_allowed_value) - REFERENCES release_group_attribute_type_allowed_value(id); - -ALTER TABLE release_group_attribute_type - ADD CONSTRAINT release_group_attribute_type_fk_parent - FOREIGN KEY (parent) - REFERENCES release_group_attribute_type(id); - -ALTER TABLE release_group_attribute_type_allowed_value - ADD CONSTRAINT release_group_attribute_type_allowed_value_fk_release_group_attribute_type - FOREIGN KEY (release_group_attribute_type) - REFERENCES release_group_attribute_type(id); - -ALTER TABLE release_group_attribute_type_allowed_value - ADD CONSTRAINT release_group_attribute_type_allowed_value_fk_parent - FOREIGN KEY (parent) - REFERENCES release_group_attribute_type_allowed_value(id); - -ALTER TABLE series_attribute - ADD CONSTRAINT series_attribute_fk_series - FOREIGN KEY (series) - REFERENCES series(id); - -ALTER TABLE series_attribute - ADD CONSTRAINT series_attribute_fk_series_attribute_type - FOREIGN KEY (series_attribute_type) - REFERENCES series_attribute_type(id); - -ALTER TABLE series_attribute - ADD CONSTRAINT series_attribute_fk_series_attribute_type_allowed_value - FOREIGN KEY (series_attribute_type_allowed_value) - REFERENCES series_attribute_type_allowed_value(id); - -ALTER TABLE series_attribute_type - ADD CONSTRAINT series_attribute_type_fk_parent - FOREIGN KEY (parent) - REFERENCES series_attribute_type(id); - -ALTER TABLE series_attribute_type_allowed_value - ADD CONSTRAINT series_attribute_type_allowed_value_fk_series_attribute_type - FOREIGN KEY (series_attribute_type) - REFERENCES series_attribute_type(id); - -ALTER TABLE series_attribute_type_allowed_value - ADD CONSTRAINT series_attribute_type_allowed_value_fk_parent - FOREIGN KEY (parent) - REFERENCES series_attribute_type_allowed_value(id); - ------------------------------------------------------------------------ --- create triggers --- ensure attribute type allows free text if free text is added ------------------------------------------------------------------------ - -CREATE TRIGGER ensure_area_attribute_type_allows_text BEFORE INSERT OR UPDATE ON area_attribute - FOR EACH ROW EXECUTE PROCEDURE ensure_area_attribute_type_allows_text(); - -CREATE TRIGGER ensure_artist_attribute_type_allows_text BEFORE INSERT OR UPDATE ON artist_attribute - FOR EACH ROW EXECUTE PROCEDURE ensure_artist_attribute_type_allows_text(); - -CREATE TRIGGER ensure_event_attribute_type_allows_text BEFORE INSERT OR UPDATE ON event_attribute - FOR EACH ROW EXECUTE PROCEDURE ensure_event_attribute_type_allows_text(); - -CREATE TRIGGER ensure_instrument_attribute_type_allows_text BEFORE INSERT OR UPDATE ON instrument_attribute - FOR EACH ROW EXECUTE PROCEDURE ensure_instrument_attribute_type_allows_text(); - -CREATE TRIGGER ensure_label_attribute_type_allows_text BEFORE INSERT OR UPDATE ON label_attribute - FOR EACH ROW EXECUTE PROCEDURE ensure_label_attribute_type_allows_text(); - -CREATE TRIGGER ensure_medium_attribute_type_allows_text BEFORE INSERT OR UPDATE ON medium_attribute - FOR EACH ROW EXECUTE PROCEDURE ensure_medium_attribute_type_allows_text(); - -CREATE TRIGGER ensure_place_attribute_type_allows_text BEFORE INSERT OR UPDATE ON place_attribute - FOR EACH ROW EXECUTE PROCEDURE ensure_place_attribute_type_allows_text(); - -CREATE TRIGGER ensure_recording_attribute_type_allows_text BEFORE INSERT OR UPDATE ON recording_attribute - FOR EACH ROW EXECUTE PROCEDURE ensure_recording_attribute_type_allows_text(); - -CREATE TRIGGER ensure_release_attribute_type_allows_text BEFORE INSERT OR UPDATE ON release_attribute - FOR EACH ROW EXECUTE PROCEDURE ensure_release_attribute_type_allows_text(); - -CREATE TRIGGER ensure_release_group_attribute_type_allows_text BEFORE INSERT OR UPDATE ON release_group_attribute - FOR EACH ROW EXECUTE PROCEDURE ensure_release_group_attribute_type_allows_text(); - -CREATE TRIGGER ensure_series_attribute_type_allows_text BEFORE INSERT OR UPDATE ON series_attribute - FOR EACH ROW EXECUTE PROCEDURE ensure_series_attribute_type_allows_text(); - --------------------------------------------------------------------------------- -SELECT '20170329-mbs-5452-fks.sql'; - -ALTER TABLE work_language - ADD CONSTRAINT work_language_fk_work - FOREIGN KEY (work) - REFERENCES work(id); - -ALTER TABLE work_language - ADD CONSTRAINT work_language_fk_language - FOREIGN KEY (language) - REFERENCES language(id); - --------------------------------------------------------------------------------- -SELECT '20170503-mbs-9329-event-meta-standalone.sql'; - -DROP TRIGGER IF EXISTS a_ins_event ON event; - -CREATE TRIGGER a_ins_event AFTER INSERT ON event - FOR EACH ROW EXECUTE PROCEDURE a_ins_event(); - -COMMIT; diff --git a/mbdata/sql/updates/schema-change/25.mirror.sql b/mbdata/sql/updates/schema-change/25.mirror.sql deleted file mode 100644 index c4afa9e..0000000 --- a/mbdata/sql/updates/schema-change/25.mirror.sql +++ /dev/null @@ -1,718 +0,0 @@ --- Generated by CompileSchemaScripts.pl from: --- 20180503-mbs-9708-drop-area-containment-view.sql --- 20190317-mbs-9941-mbs-10062.sql --- 20190422-mbs-7480.sql --- 20190422-mbs-9973-collection-added-date.sql --- 20190422-mbs-9428-collection-collaborators.sql --- 20190422-mbs-5818-collection-position.sql --- 20190422-mbs-1658-collection-text.sql --- 20190423-mbs-10052-eaa.sql --- 20190423-mbs-5387.sql -\set ON_ERROR_STOP 1 -BEGIN; -SET search_path = musicbrainz, public; -SET LOCAL statement_timeout = 0; --------------------------------------------------------------------------------- -SELECT '20180503-mbs-9708-drop-area-containment-view.sql'; - -DROP VIEW IF EXISTS area_containment; - --------------------------------------------------------------------------------- -SELECT '20190317-mbs-9941-mbs-10062.sql'; - -CREATE TABLE genre ( -- replicate (verbose) - id SERIAL, -- PK - gid UUID NOT NULL, - name VARCHAR NOT NULL, - comment VARCHAR(255) NOT NULL DEFAULT '', - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >=0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW() -); - -CREATE TABLE genre_alias ( -- replicate (verbose) - id SERIAL, - genre INTEGER NOT NULL, -- references genre.id - name VARCHAR NOT NULL, - locale TEXT, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - primary_for_locale BOOLEAN NOT NULL DEFAULT FALSE, - CONSTRAINT primary_check CHECK ((locale IS NULL AND primary_for_locale IS FALSE) OR (locale IS NOT NULL)) -); - -ALTER TABLE genre ADD CONSTRAINT genre_pkey PRIMARY KEY (id); - -ALTER TABLE genre_alias ADD CONSTRAINT genre_alias_pkey PRIMARY KEY (id); - -CREATE UNIQUE INDEX genre_idx_gid ON genre (gid); -CREATE UNIQUE INDEX genre_idx_name ON genre (LOWER(name)); - -CREATE INDEX genre_alias_idx_genre ON genre_alias (genre); -CREATE UNIQUE INDEX genre_alias_idx_primary ON genre_alias (genre, locale) WHERE primary_for_locale = TRUE AND locale IS NOT NULL; - -INSERT INTO genre (gid, name) -VALUES ('54c01942-22fd-4184-9877-1db0089b18f1', 'acid house'), - ('7dc2b20f-3953-4874-b9bf-41b8ba06d20c', 'acid jazz'), - ('ba64013e-27bb-4f14-a530-8d25b296e0da', 'acid techno'), - ('37f85b9c-c3fc-4b5a-8545-51aeb78c8786', 'acoustic blues'), - ('00055e8b-b951-46e2-af1e-58b5624e7952', 'acoustic rock'), - ('fcc58a18-9326-4c92-8b29-c294d44379c3', 'afrobeat'), - ('5f9cba3d-1a9f-46cd-8c49-7ed78d1f3354', 'alternative country'), - ('8301f73c-9166-4108-bfeb-4fd22dc19083', 'alternative dance'), - ('0b48a36c-630f-4ee7-8cf3-480e3dd8be65', 'alternative folk'), - ('924943cd-73c8-45c0-96eb-74f2a15e5d6e', 'alternative hip hop'), - ('7983ff25-ddf9-411e-a7f9-6cca238bff79', 'alternative metal'), - ('d3ebe947-7c03-43f5-b333-09379881b0f6', 'alternative pop'), - ('e096efc6-6c9c-4240-b627-d7bbb5e8fa2a', 'alternative punk'), - ('ceeaa283-5d7b-4202-8d1d-e25d116b2a18', 'alternative rock'), - ('608b0471-7531-4854-a348-e698c69cb699', 'ambient'), - ('cc2327cf-88a3-476b-950c-296c382eabd9', 'ambient house'), - ('1c6e4eae-915d-4662-a7ff-038920b67d9e', 'ambient techno'), - ('2c765e49-a12e-45eb-b628-f8b9cc0a0250', 'americana'), - ('e12fe025-4c13-485e-a2fe-ad5bf2cd75eb', 'anarcho-punk'), - ('aca1caab-09d1-44b5-ae84-590ff1d218fc', 'aor'), - ('26af3760-750a-4b5e-a699-78c87697585a', 'arena rock'), - ('b7ef058e-6d83-4ca4-8123-9724bff4648b', 'art rock'), - ('d14a4c4a-bea5-4b08-b945-59b048acd2d5', 'atmospheric black metal'), - ('966d3d2d-15bd-4f6f-a830-15ab2c5e662f', 'audiobook'), - ('b1c0c2ad-e5ae-4bb6-a1be-d66e195fd2d7', 'avant-garde'), - ('8d901306-d4a3-436c-a1c3-75550e5b6eaf', 'avant-garde jazz'), - ('77c0160b-8090-4493-b229-890addfee1df', 'avant-garde metal'), - ('0e7a3c6a-4fbc-4b66-8201-9196032768ac', 'avant-garde pop'), - ('b413acf5-112a-4d44-a61f-9abe28f0dfac', 'bachata'), - ('17b58d38-1110-4f5a-9412-b0314329622b', 'ballad'), - ('f8f6157d-5ace-4844-90c2-2e2a829b8932', 'barbershop'), - ('9e44c2c9-8c44-4aa6-9de3-0f3e75b49f1b', 'baroque'), - ('ac30756b-55a7-4dc3-8908-8f94c93318d0', 'bebop'), - ('59a849e1-73fe-428d-8a61-3788875f9644', 'bhangra'), - ('e7bb9a21-9556-4b85-bc78-5f69a3d0577d', 'big band'), - ('aac07ae0-8acf-4249-b5c0-2762b53947a2', 'big beat'), - ('a687ea57-487a-440d-b5fd-2f1b2f8b1f57', 'blackgaze'), - ('12568698-97cc-49a9-80ab-9c5e3fe4dd33', 'black metal'), - ('f976d48b-965e-4fe9-aaa6-105aab988c7c', 'blackened death metal'), - ('650bda08-20ca-4012-b873-3b68c5768bdf', 'blue-eyed soul'), - ('a1a7b40d-f6e6-48c1-a5fc-b15af73d7381', 'bluegrass'), - ('fe12b346-a10e-450f-bf81-fa20894b5ea2', 'blues'), - ('58e325d5-54fd-4e98-b39a-3aa6bc319273', 'blues rock'), - ('49fa872d-561c-4f8a-aea4-fbe7f67e1bd6', 'bolero'), - ('ae4e05d3-6ae6-41b2-9b63-7c9e27784e27', 'bolero son'), - ('d8048b43-9edb-4e1a-aa88-bb91fa847d4a', 'boom bap'), - ('573a284f-2ae3-4636-af36-10fc1078d295', 'bossa nova'), - ('3b8f3f65-6caa-47c8-b076-fa59dfb69c43', 'breakbeat'), - ('8aad8a03-be38-48e4-aa43-5ca0f826c569', 'breakcore'), - ('63eddc75-dbad-4a05-a365-e30d1e87bca8', 'breaks'), - ('f1c9b874-7ef2-4e79-9419-c0bcb5f33a30', 'britpop'), - ('cf9daa9d-74e2-4eff-b0eb-7269bbca6501', 'broken beat'), - ('12d11d01-cecc-4f9b-8d3a-99e4590952fe', 'brutal death metal'), - ('6fd83b83-9b63-47fa-a208-5f9e762f40ab', 'bubblegum pop'), - ('0af301ff-3e33-4f5f-934f-5916cfc04157', 'cajun'), - ('b44a8ffd-e717-4d73-99ea-9fe5d245339d', 'calypso'), - ('78caea3b-84fd-4664-878a-fe70a6e1d9d1', 'cantopop'), - ('9c2f8b08-9bac-4bfd-b9ed-6381c65791e9', 'canterbury scene'), - ('34edc6ac-d431-4b36-be15-ecd17533e5e2', 'celtic'), - ('36c0f210-b6c1-4481-bc7c-33de031a4046', 'celtic punk'), - ('f0843e91-c025-4dd7-8aef-6fe3d35470d9', 'chamber pop'), - ('55d05e59-4829-4e98-8cb7-5d769cafb576', 'champeta'), - ('b7864789-29e6-4965-84e4-463baaa869df', 'chanson'), - ('f1e26a78-3e85-4365-a34d-dc4b5389b29d', 'chicago blues'), - ('7232e5df-8466-421f-ad5a-ce2048e5522d', 'chillout'), - ('103a65bb-35d9-4d27-9c9b-f35a458621ba', 'chiptune'), - ('c02cd2c5-9316-4046-a241-f74b773fee06', 'christian rock'), - ('31aee5bc-c1e8-43d7-a7bc-902df802ccbb', 'christmas music'), - ('5fef47af-772b-48e2-8e49-855f7d999e81', 'city pop'), - ('15f9b448-6f2d-45a4-b11b-1fcdf45be203', 'classic blues'), - ('9cc9ea3b-e189-4def-9e47-86e9dc643eee', 'classic country'), - ('f0e90b41-4499-493f-b6e3-05d3c3ea1b20', 'classic jazz'), - ('93244085-20e5-4f16-9067-1d19143b3810', 'classic rock'), - ('bf9955d6-c3eb-466d-95ca-30f3848fc9ea', 'classical'), - ('bab69b07-8bb9-4415-b666-c37609cef80b', 'club'), - ('119ecf69-7d87-4f63-bc83-2959a0111a55', 'comedy'), - ('c0e73bb6-37a4-485e-aaea-11c63b40c9f3', 'conscious hip hop'), - ('2b4f0036-79a0-4ce0-a38c-4c0c8e61c579', 'contemporary christian'), - ('a190bb32-e0a7-4c56-b142-5cf9cfcfa713', 'contemporary classical'), - ('c11e4253-a888-4a2a-adde-c274b748d0b3', 'contemporary folk'), - ('6aeacd9a-3964-4ca4-9e3c-23ec8bd8848d', 'contemporary gospel'), - ('e2b06d21-13df-4a48-aa81-6ddd99344dc7', 'contemporary jazz'), - ('4bb4043a-0ee5-4b84-93fa-6ba4567a6ba0', 'contemporary r&b'), - ('2f7f569a-9348-4384-8508-2d0ac7d6a778', 'contra'), - ('5fc86669-d9ba-4716-8090-eff39081090e', 'cool jazz'), - ('5f665615-7fb3-49d8-b541-62a7b239edbe', 'country'), - ('1a46845c-ed4d-48c5-a93f-45bb85cf56d1', 'country blues'), - ('984e6cb2-823e-4709-a23b-233f7f2ee3aa', 'country folk'), - ('2de61e9c-de1d-47c8-999d-5b44c0cfeca1', 'country pop'), - ('fb07b1e3-411d-4146-a0d6-3479c0e7557b', 'country rock'), - ('eee90717-3eee-41bd-b463-003c180544bd', 'crossover prog'), - ('f66d7266-eb3d-4ef3-b4d8-b7cd992f918b', 'crust punk'), - ('7cd4173c-fef8-4e99-a527-98a25b6487c0', 'cumbia'), - ('ad41288f-0803-4e2e-859f-148e7f7b2eae', 'd-beat'), - ('e5bba957-8c91-496a-a675-c6d0c6b51c33', 'dance'), - ('b739a895-85ed-4ad3-8717-4e9ef5387dd8', 'dance-pop'), - ('509c006f-67c2-4c54-a568-d2b415cb0642', 'dance-punk'), - ('6c3503e3-bae3-42de-9e4c-7861f2053fbe', 'dancehall'), - ('01ecf8e4-7f7a-4145-ae97-504d3109633d', 'dark ambient'), - ('24db3574-7c54-4d9b-b238-8d17eb7e8d63', 'dark electro'), - ('16103855-c0f1-4221-81d8-eafc53b1b41c', 'dark folk'), - ('c4a72fcd-e291-43c8-a546-9ce1764ff31b', 'dark wave'), - ('eacfa027-2fad-413f-a2f1-80fa43674f0b', 'death metal'), - ('2bd1ff1a-777d-4c5c-a1cb-92792adcf10c', 'death-doom metal'), - ('d39cbc30-7dc6-4194-8f99-6d35dd602451', 'deathcore'), - ('619c5945-6484-4a68-96e9-a48d4a4e1f73', 'deathgrind'), - ('d5e21e4f-f6fe-464d-b269-14cf670a6949', 'deathrock'), - ('7fa479e7-3d35-40d1-96f7-b619a5ca9d9f', 'deep house'), - ('b0702eb4-2951-4e1f-bbcd-dd9b0ec63c7c', 'delta blues'), - ('bc1b8c46-5a69-4262-b909-c376f5de491a', 'desert rock'), - ('6d12e828-40a5-4ebc-a5b0-aa5506e2efd0', 'digital hardcore'), - ('a04d680b-b5c5-4f6a-87a3-f9f1ff98e3ea', 'disco'), - ('1696f12e-9f01-4309-be9d-116e31ac65b7', 'doo-wop'), - ('db815815-60fe-44a3-9859-2232df479dc9', 'doom metal'), - ('cc38aba3-48ed-439a-83b9-f81a34a66598', 'downtempo'), - ('1e5e18e5-4e70-4a73-942a-c6c79c1aefe2', 'drill'), - ('75c5866f-0212-4c02-9650-de475dda157e', 'drone'), - ('462f9321-6103-49c9-b6db-96219bce6f62', 'drum and bass'), - ('c72a5d45-75a8-4b35-9f48-67e49eb4b5e5', 'dub'), - ('16aab171-3dce-454e-bb96-2636f15813fc', 'dub techno'), - ('1b50083b-1afa-4778-82c8-548b309af783', 'dubstep'), - ('c89a76aa-2149-499e-946b-8299aa2f4ab3', 'dungeon synth'), - ('1bafab01-c092-47bc-84ee-a6b503b3cb86', 'east coast hip hop'), - ('f3818817-6235-48d5-82f7-b223eb0261d9', 'ebm'), - ('8164d906-055d-4ca8-9ab2-14204b301cc3', 'electric blues'), - ('60f00d05-df4d-496e-8f5a-c45c03a56ad4', 'electro'), - ('05247982-e44f-4c58-96f8-a5453be69f5f', 'electro house'), - ('9b1af4d0-2196-43d4-bbca-845a2e02d962', 'electro swing'), - ('4f476710-cd29-400f-98fe-7782e1f00e06', 'electro-funk'), - ('6e2e809f-8c54-4e0f-aca0-0642771ab3cf', 'electro-industrial'), - ('cae57e98-c939-4b0e-ae49-8e0cb1bdc91d', 'electroclash'), - ('89255676-1f14-4dd8-bbad-fca839d6aff4', 'electronic'), - ('c4a69842-f891-4569-9506-1882aa5db433', 'electronic rock'), - ('53a3cea3-17af-4421-a07a-5824b540aeb5', 'electronica'), - ('f9720c77-3574-4fe8-823b-c290b117222e', 'electronicore'), - ('3f3388b4-e36a-4bf8-a0be-66b10d92aaa4', 'electropop'), - ('c187da0e-48a0-4de5-b759-4ca2a1503008', 'electropunk'), - ('ef0c2769-9c8f-49fc-b66e-27b8242b004a', 'emo'), - ('1d6489a9-5837-43c9-8155-94a126e8a951', 'emocore'), - ('b73d4a65-091e-4f08-8422-93f1b90f95d7', 'enka'), - ('845d2209-0b82-4a87-9405-453fc2e3086c', 'ethereal'), - ('8f8cbcde-3948-4be5-8bf0-8073f13e4b60', 'euro house'), - ('e9a67960-9b49-4967-a1c9-c26360e9c612', 'eurodance'), - ('50e3ff0e-1abb-4577-9bf3-95d5c539ce2d', 'europop'), - ('68c81274-5770-4e7b-a4bf-ab0d7d425d99', 'experimental'), - ('65c97e89-b42b-45c2-a70e-0eca1b8f0ff7', 'experimental rock'), - ('2fb0a213-28f9-4e67-bb02-3df6d396d2de', 'fado'), - ('18a0d235-c8e0-4575-b0dc-e3bb0cc2ad2c', 'filk'), - ('961c6dad-8cf0-47ab-bc09-ccd011f9ef28', 'flamenco'), - ('a91eed3a-fdd0-494e-ade0-95ea4117f6eb', 'folk'), - ('f5b0242a-ede0-4929-9361-4eddeb0516b5', 'folk metal'), - ('6cec5b4d-3c64-44a6-914d-3e833432f631', 'folk punk'), - ('445dc48f-5233-4b4f-987f-867ff9ade836', 'folk rock'), - ('abb2374f-30e5-4d3e-b417-2caf78ef1f6c', 'folk pop'), - ('8103927c-5f4b-4bbc-9d8c-7a1241d2bab8', 'freak folk'), - ('6a1ba2f9-1e5b-446f-9ffa-c0b0963aa08f', 'free improvisation'), - ('3c31635b-a5a7-44eb-ab9d-4bbde11da2d4', 'free jazz'), - ('fe4ba6a1-9873-4fd0-a12b-a70c81818514', 'funk'), - ('dfdf3e46-3b2b-417e-9346-86f9a5bac360', 'funk carioca'), - ('0caaa092-27c4-413e-841c-7c4deeec57a7', 'funk metal'), - ('eca476ac-d63b-431f-9347-c45f530dc15d', 'funk rock'), - ('1fbd6e82-0d33-4d78-a9b1-7d145a8eefa6', 'funk soul'), - ('62e4c7cb-a2b3-462b-8d96-1b0d66ee6cf3', 'funky house'), - ('7af339eb-e666-4aa6-a6ca-8444ca573fe0', 'fusion'), - ('cdc54f47-79fc-42e2-80d8-8ef58bd21122', 'future jazz'), - ('6df6e38b-2a6f-4990-94dc-ea48eba4f8ad', 'futurepop'), - ('b37aef4d-0029-4fc7-b634-6338197335a8', 'g-funk'), - ('2f2118d7-315b-4241-bf40-d5d6ca11348d', 'gabber'), - ('bc8c2f79-dcea-43f3-962b-f0663868d42c', 'gangsta rap'), - ('60c9c6a6-1de7-4010-9f5b-7692d3231d22', 'garage'), - ('092f40b5-9157-41f2-8243-68b704cd0ed1', 'garage house'), - ('fd5bea65-15ef-44c4-83fb-ba15013b3596', 'garage punk'), - ('b7bb11c3-bb83-4047-af65-1e8aba89039f', 'garage rock'), - ('bc08993e-b188-43e8-b358-b84f2db6bfe6', 'glam'), - ('818134e3-9392-4624-a13c-c4b19c54bccd', 'glam metal'), - ('54d89e62-5bfb-42bc-a321-9230e6fdcd75', 'glam rock'), - ('18b010d7-7d85-4445-a4a8-1889a4688308', 'glitch'), - ('ade8f293-c049-438a-a5f0-b51e6776d9c5', 'goa trance'), - ('ca315be3-733b-4630-92d9-cd8ecafe0419', 'goregrind'), - ('08289b42-7e41-4987-9263-c28bb4c59da0', 'gospel'), - ('d9f42dc1-3a92-4217-8ae5-e9672f595b8e', 'gothic'), - ('c73392a9-adaf-4ee4-b911-97a5892ac917', 'gothic metal'), - ('d9858aef-25bf-478b-b135-b900aa1f0fd1', 'gothic rock'), - ('b9c9a69d-5fc2-4317-b25d-5a96c8c9478a', 'grebo'), - ('51cfaac4-6696-480b-8f1b-27cfc789109c', 'grime'), - ('093149ea-d1bc-4f93-bd5a-8fdcd055ea2f', 'grindcore'), - ('1a85800e-945e-4a9d-824e-dbd21ca15757', 'groove metal'), - ('3f08faa9-6c3e-4b6d-b4b8-08eea45954e2', 'grunge'), - ('3c9097f9-10d9-4086-98e3-e8c54ef470b3', 'guaracha'), - ('bd477a3e-9235-4597-9ce5-3caa994baef7', 'happy hardcore'), - ('8c083468-2dce-4a31-ae77-433af3deafd3', 'hard bop'), - ('9c5052e0-36ff-4b92-9447-58f44ffdf682', 'hard house'), - ('51cb9f91-e6a2-41bf-891f-e78e3f1e52ab', 'hard rock'), - ('c8acb78a-8337-4eae-9d19-48220dba03ac', 'hard trance'), - ('3308d0b0-3c7f-45e2-b835-5c2a0d433f02', 'hardcore techno'), - ('055a6e4d-d929-42ac-ba7a-9d063b254ea5', 'hardcore punk'), - ('4a74a604-f702-424c-984f-93c5b04360ea', 'hardstyle'), - ('a6719055-99c4-47eb-beaa-71081f2376f9', 'heavy metal'), - ('52faa157-6bad-4d86-a0ab-d4dec7d2513c', 'hip hop'), - ('59b8a806-8bdd-45b5-978a-b5e404c910aa', 'honky tonk'), - ('66d01f06-21dc-4216-ac63-c5efb7b6338e', 'horrorcore'), - ('36471baf-3fd6-459d-918c-40dc64adea36', 'horror punk'), - ('a2782cb6-1cd0-477c-a61d-b3f8b42dd1b3', 'house'), - ('8eb583f1-4fd7-460c-8246-dcdccc0e3ef9', 'idm'), - ('da52c9d1-73f2-456e-a0d0-94bd854cb338', 'illbient'), - ('538c905b-642d-43c9-b071-439af11cc471', 'indie'), - ('36917620-240a-4fed-abcb-7be611ac3834', 'indie folk'), - ('f390be72-360b-41bb-a310-6a2e638779d2', 'indie pop'), - ('ccd19ebf-052c-4afe-8ad9-fbb0a73f94a7', 'indie rock'), - ('9e7ae1de-d5f2-46a5-b105-11c7367dc70d', 'indietronica'), - ('fde4b353-2d97-4b57-af38-e7c53efa84f3', 'indorock'), - ('060beed7-e597-4c42-8e25-5bf8bd5dd3cb', 'industrial'), - ('d4df54b5-67b4-4fb7-8f73-79e71717a501', 'industrial metal'), - ('ffbc9907-c9be-4ace-876b-b7fd5b9d51f9', 'industrial rock'), - ('4ae63770-68af-4fae-b0f1-5e53f372c743', 'instrumental'), - ('c1a4860e-720f-4f4c-8a54-a8032aac08fa', 'instrumental jazz'), - ('6b3903aa-8abe-4645-b363-558483b1586f', 'instrumental rock'), - ('3d88ed41-624d-4be9-bf9d-ca11991eb250', 'irish folk'), - ('97a4a75a-6e49-4519-9684-ae2ccb2fc0f9', 'italo-disco'), - ('eba7715e-ee26-4989-8d49-9db382955419', 'j-pop'), - ('d181e978-c908-4f33-b2a2-f7454d0cb2c1', 'j-rock'), - ('a715278f-1580-409f-8078-4ffbc800e08b', 'jazz'), - ('9702d99a-823f-47ba-b8c2-af0538c9640b', 'jazz blues'), - ('2377ff19-83e7-4873-b425-dce6d1ad4ef4', 'jazz fusion'), - ('6061fb1b-d733-4643-a3d4-940c9a5e2ab8', 'jazz rap'), - ('5eea976c-1ab2-4d94-9b63-7d1297d5dba5', 'jazz rock'), - ('f3c43ae8-839a-4523-b295-cfa4eba6c911', 'jazz-funk'), - ('ea9b6ec3-fc8f-4c55-b2f9-19bd4511a986', 'jungle'), - ('b74b3b6c-0700-46b1-aa55-1f2869a3bd1a', 'k-pop'), - ('7054e8e2-7c7b-4432-83b9-93423b361792', 'kayōkyoku'), - ('5c8b654c-0f2b-40d5-990b-e070a527b1df', 'kizomba'), - ('06eeec6e-f389-4783-b601-909bb10bd04e', 'klezmer'), - ('ba318056-9ddf-46cd-8b95-61fc993b962d', 'krautrock'), - ('7369bb8b-3399-4180-8cb2-4e37e0e7b0e7', 'latin'), - ('48095aaf-c31d-4bfc-9578-8755c71d44af', 'latin jazz'), - ('2b9b7ea8-cb90-428c-adb2-d55b2faa4f1d', 'latin pop'), - ('b07b5eec-c7f0-4529-a876-e0dd6b350084', 'latin rock'), - ('32bea60c-e201-4241-8ed4-228636d34a97', 'leftfield'), - ('e1e37f00-9bd9-4510-b6ca-9bb128b665f4', 'line dance'), - ('65e2f3ad-e0bd-4627-bd83-cba7c8b6d011', 'lo-fi'), - ('97b15117-c3e2-47ec-9d64-79f90b528a9c', 'lovers rock'), - ('de2785b2-f282-4718-a422-37dc93964bdd', 'lounge'), - ('013161b9-3f21-468f-aa1f-28adf1eae085', 'madchester'), - ('caec8f8d-d862-4b62-9942-5622c2c18446', 'mainstream rock'), - ('f6fb8e67-cd02-4fb4-b256-2970000dcb46', 'mambo'), - ('489cf2f9-0edd-4fbc-aa05-ae248706cb3e', 'mandopop'), - ('482ff4ed-fc37-49fb-9858-92f955a19e6c', 'martial industrial'), - ('a6b55d73-bba3-49fc-a361-ca4bde004717', 'math rock'), - ('8df1241b-2ba1-40b8-bb8f-2dc15ce6dc1e', 'mathcore'), - ('4fc769b7-acac-4061-9129-ee8c6875b4c3', 'medieval'), - ('74ed98e0-d2f4-4d34-9a51-0c18c1303726', 'melodic black metal'), - ('5eeb0431-8160-40a7-ae44-c2ad01fed156', 'melodic death metal'), - ('4f2cd717-7259-48df-8d0a-c17ccd9203b9', 'melodic metalcore'), - ('e6d5e340-d969-4bb1-8342-18abc1d8c611', 'melodic rock'), - ('13e409d0-fe4a-4dd4-a957-6e06462b085f', 'melodic trance'), - ('ce41a887-cdb3-4c52-bbce-604287d74573', 'mento'), - ('3f5f955d-f505-484a-b397-d0bf0760d8f3', 'merengue'), - ('cc28f5aa-5e19-487c-88e1-e56b022f1fdd', 'metal'), - ('62f88295-0605-4ce8-958b-2e0063ece47e', 'metalcore'), - ('bbce54eb-a477-4b23-ac81-d3b9aac43756', 'microhouse'), - ('7588308f-e08b-444e-8d6b-55549c58cf3c', 'milonga'), - ('b0ac2e92-b41d-46e9-8c88-cd254f3a86e0', 'min''yō'), - ('d024e2e6-842c-43f7-b46e-8d0b87a4cd8e', 'mincecore'), - ('8d9a00db-0b8b-41ff-9af7-d0f96793bdc5', 'minimal'), - ('6fb5fe60-b6c2-414f-8011-4f8dc023039b', 'modern blues'), - ('e328c306-8e35-46d2-93c3-623412ec7c13', 'modern classical'), - ('0582ba9e-320b-431d-a925-e1b22cad22d8', 'modern country'), - ('0c44a04f-f7ba-46a0-9dbe-1a21359cfa1e', 'motown'), - ('7b447f98-1e94-4e57-9bb8-373743fbcdd8', 'mpb'), - ('ff6d73e8-bf1a-431e-9911-88ae7ffcfdfb', 'musical'), - ('286f9168-9c46-4e41-94a1-1aa4aeb93b8c', 'neo soul'), - ('d2327987-362f-4d70-8bfd-a8b47c3b0a54', 'neo-progressive rock'), - ('66366e89-590e-424f-b13d-0d0564eb4f27', 'neo-rockabilly'), - ('e94c28db-21a2-43de-9e58-8113fba2c732', 'neofolk'), - ('9c8ba153-740e-4b88-b7ff-31d004944c95', 'nerdcore'), - ('6c76d9ec-0924-4fc9-bb22-91a695ca09d6', 'new age'), - ('dd497eac-e915-49a9-b1e4-482792acf397', 'new jack swing'), - ('391a797d-50d7-46df-b380-39ccacd52a09', 'new romantic'), - ('56407f9d-3398-4bf3-bbbd-ea372fa5adeb', 'new wave'), - ('3188a961-88e0-4b12-9b9e-47f79e53d780', 'no wave'), - ('89c7c9b3-215e-482f-bce3-3219ffd0a222', 'noise'), - ('0cd76818-fdde-4f56-93a1-040f09ca7f23', 'noisecore'), - ('1208a8e7-e5bd-4891-9f81-9a9fdfceeb39', 'noise pop'), - ('018b7630-8941-4966-90e4-3774daea4e04', 'non-music'), - ('3e226375-1286-40e3-92b3-d257e3a1babb', 'norteño'), - ('a18a254b-67ca-4c8b-a13c-87154055e47e', 'northern soul'), - ('848ecccf-e7fa-4439-a8ab-9dd3c31b4cf6', 'nu jazz'), - ('bbad9cda-bde2-448e-821c-7ebf85a54020', 'nu metal'), - ('290afc44-ad41-4d51-9ca6-4ee88df0f4f8', 'occult rock'), - ('221ff39c-4521-49e3-ab52-e4dde85efd1e', 'oi'), - ('ed67ff3f-8f00-4321-badd-e9f183f7584b', 'old-time'), - ('2692f2d7-d680-4a5c-83f0-48e6e7c3ec6b', 'old school death metal'), - ('56e0b906-1018-4a55-8ec7-86746272116e', 'opera'), - ('f3fe6570-1e79-4ed5-8eb9-9ed64d631871', 'orchestral'), - ('f30d5ce4-559c-45c2-897c-089599ac9a83', 'outlaw country'), - ('fadab481-3ced-466e-b828-74aed72d5c2f', 'p-funk'), - ('bbe70cad-e184-42e5-9b90-e14438ba4363', 'pachanga'), - ('911c7bbb-172d-4df8-9478-dbff4296e791', 'pop'), - ('77365c92-f25b-4ed3-8d02-03aae8b6df0e', 'pop metal'), - ('60e21d01-ce21-4127-86b7-aada79558dab', 'pop punk'), - ('da2fc3b4-b97d-491a-ac0f-8a731bee7237', 'pop rap'), - ('797e2e85-5ffd-495c-a757-8b4079052f0e', 'pop rock'), - ('64e0bd76-822f-4549-a6fe-9858561282d1', 'pop soul'), - ('aef2077e-6cbc-47ba-9698-9eb5f842a412', 'pornogrind'), - ('94ce0ba0-9043-4b5b-87d6-3c1a8458f75d', 'post-bop'), - ('842008b8-1c67-4c8c-b450-7f5adf20fb7f', 'post-classical'), - ('bbb1310c-24cb-4fc9-97c4-f93e4549f1e2', 'post-grunge'), - ('aec382b7-b635-470c-9051-2f84e0b5ea1e', 'post-hardcore'), - ('e214700e-dae1-4b69-81e9-276e4e88fa32', 'post-metal'), - ('f6d8cadd-6a5e-4ec9-9c2b-996b5332a639', 'post-punk'), - ('0bfffa19-4e4a-4bf7-bf53-6ec44f0a2f8e', 'post-rock'), - ('4e6e388c-a9d2-45cb-80ad-bf64db4a0759', 'powerviolence'), - ('18527512-634e-48bb-81b2-6bfcf1818b95', 'power electronics'), - ('f0b0aa5f-ed81-456b-85ab-492002a29eeb', 'power metal'), - ('618704fc-daac-44a2-92c9-89e3b1a2fc8c', 'power pop'), - ('5a56d32f-81e4-4301-be70-4a060ab3b4a0', 'production music'), - ('8d275a8d-154a-4bcb-8b5a-f56306ad4bcb', 'progressive'), - ('34d08b64-7426-42e1-959e-48af44352fcd', 'progressive folk'), - ('70adb285-e1f7-458a-823f-5cbda5e291c4', 'progressive house'), - ('5c7785e6-a0b4-4441-a1e6-4fd4c0066a5f', 'progressive metal'), - ('ae9b8279-3959-48d8-8a88-741a7f6d4a48', 'progressive rock'), - ('6bd228be-3374-4c4e-bc0a-46779fafe8f1', 'progressive trance'), - ('d1091878-2332-4f82-9a5c-f6d67cf4b7ef', 'psy-trance'), - ('d698ece0-6fed-4262-b446-42c98b73b65a', 'psychedelic'), - ('507757f0-a63c-422b-93f1-f1d77462033f', 'psychedelic folk'), - ('2aeb5340-c474-4677-b9a6-35ddac9b6a58', 'psychedelic pop'), - ('146ef761-5ad9-48b4-b0b3-483104f7da48', 'psychedelic rock'), - ('8a14f570-7297-438d-996d-8797f9b8cfcc', 'psychobilly'), - ('b3cccf71-e843-4546-87fa-728055ba3147', 'psytrance'), - ('8cc9b280-230b-4a3a-b1e2-8acab0744dd3', 'punk'), - ('bd7e1d40-43b1-4ba5-97b3-05b891466962', 'punk rock'), - ('2481fbdc-05ed-458d-9928-46f3336c343e', 'queercore'), - ('31be54b2-4d0c-42df-aa44-c496c7b4c3c3', 'r&b'), - ('0d15e596-3374-4590-bdb0-0a95d38ab4dc', 'ragga'), - ('4080e55b-ac2e-4907-a724-491b3bfdba63', 'ragga hip-hop'), - ('7aae791f-dfff-4910-b133-ba1b9e9c1560', 'ragga jungle'), - ('deec5f2f-ccfc-4e0c-b1ac-8e5a17cd5cb7', 'raï'), - ('d017dd87-704b-4ad4-8b67-39fb401b8339', 'ragtime'), - ('ca20f188-68d2-4af5-966e-8e2e0f848758', 'ranchera'), - ('b4b184b7-6224-478e-a273-f9da9ee30136', 'rap rock'), - ('2cd7891d-c012-45f1-b1a1-86e34793f7fa', 'rapcore'), - ('660e755a-1b66-440b-9b7c-fbcf245f4415', 'rave'), - ('02b2f720-d06e-42ce-85c2-1ecd4191ffcb', 'reggae'), - ('bb14fb18-af6b-4547-9130-47fc4b208f48', 'reggaeton'), - ('9d4f50e8-5056-435e-8786-2d09e3407622', 'rhythmic noise'), - ('0e3fc579-2d24-4f20-9dae-736e1ec78798', 'rock'), - ('e4581b76-a842-440b-9b0f-1aa7a00a5c57', 'rock and roll'), - ('f1a053eb-61bb-448a-964d-35784c4ae8c1', 'rockabilly'), - ('81638671-c67c-47cf-b21d-e92261068cf6', 'rocksteady'), - ('f2d4991d-97fa-4c1c-8e09-15ec7668aa43', 'roots reggae'), - ('190bba5b-909f-4501-9a00-f96969983459', 'rumba'), - ('717f442d-59d1-4349-a14e-c4874acd3509', 'salsa'), - ('2447a0ec-e65f-48c7-b402-05cfe5c62cb7', 'samba'), - ('7edde935-8094-409e-ba33-34779b4668f8', 'schlager'), - ('8fea0cb0-4205-49cb-95e8-bc1122857c7d', 'screamo'), - ('9864d280-a987-466f-bac2-ce103721c3e2', 'shibuya-kei'), - ('a4012b2e-5c27-4f81-8781-9ae5998d882c', 'shoegaze'), - ('455f264b-db00-4716-991d-fbd32dc24523', 'singer-songwriter'), - ('65877068-2116-4af6-89a2-838179a7e103', 'ska'), - ('89e34d8e-6562-412f-8da3-d040e159e6cd', 'ska punk'), - ('7aabc697-7c79-4f12-bb6f-ee5d70298a3f', 'skacore'), - ('a4704a31-7c69-44d9-a590-8fcc2b258f77', 'slow waltz'), - ('66544dbb-08a8-44c2-a21a-4d251481d2b6', 'sludge metal'), - ('a1f1dcc8-6078-4c12-90b7-47e3080e330c', 'smooth jazz'), - ('d4eafdc7-1a86-422b-b598-79e6bb81745c', 'smooth soul'), - ('b251cd9a-990c-49f6-8da3-db3457aa2114', 'soca'), - ('7d0c6a6b-5d56-4b1e-a8c7-e32194f246b9', 'soft rock'), - ('db48f46a-6467-49b0-a6b2-beb059584d9d', 'son cubano'), - ('7f0d2b34-d0ea-4ab5-a169-934f131bc40c', 'son montuno'), - ('1b5e7b16-336b-473e-a364-5120413a9827', 'soul'), - ('e70f0aa3-9531-448c-8182-7ff34e3d74f8', 'soul jazz'), - ('905c1899-3027-4d29-8d9c-bbeef2c8628a', 'southern rock'), - ('bd61d502-8906-4073-a4ea-18c04e946dbc', 'southern soul'), - ('532dcf83-5641-446d-b007-51292b401650', 'space rock'), - ('59c7776f-fd87-4cfb-a7a5-9fe66ec02b1b', 'speed garage'), - ('13b9a3d0-cadd-483d-9bf5-9c2b32a946a7', 'speed metal'), - ('c774791e-1b78-4794-a109-befb712ef44d', 'spoken word'), - ('5c76eb54-7342-4d1f-9d98-a93f2f6aa7f6', 'stoner metal'), - ('aa5f0254-403e-496a-a388-c01abf62f39a', 'stoner rock'), - ('c2ca3275-7e83-40cc-8f13-7ccae588144d', 'street punk'), - ('b76ee78d-ec97-49e9-8ea6-cfc46ecc3b23', 'surf rock'), - ('063d0461-1e12-4246-87bf-69c5ca611cc2', 'swing'), - ('86a383d3-a4cc-4690-9a0f-f8ee83f7492d', 'symphonic black metal'), - ('2a4cae89-5a5a-44b7-9cf8-bf92c38a31dc', 'symphonic metal'), - ('166be36f-febb-4523-a005-1fb3603bd3f6', 'symphonic prog'), - ('f729e6f8-30dc-4b81-9ff4-f4e7de82225d', 'symphonic rock'), - ('50294a4d-61f0-4dc8-a20f-4708d52fe78a', 'symphony'), - ('19565d07-8460-4773-8d54-149208a61bb4', 'synthwave'), - ('988e91a3-3341-416d-b7f8-7dbef6848dac', 'synth-pop'), - ('267b14aa-3e3c-4615-803c-0255a81c8203', 'tango'), - ('1f9c4b4a-c43d-40bd-b806-357153641fd0', 'tech house'), - ('db37c56d-e6a7-4809-b549-6f1cb559b559', 'technical death metal'), - ('41fe3260-fcc1-450b-bd5a-803886c56912', 'techno'), - ('4b7c8e31-462b-4e06-acfd-fa508ad26e0c', 'teen pop'), - ('e8a3ec42-4427-4365-8180-f1e05b46459e', 'thrashcore'), - ('cc4cf136-5690-4ee3-a62b-b172febfe322', 'thrash metal'), - ('6b8e3c88-add3-4b27-b2ec-a2135edf6e95', 'timba'), - ('037150a6-d83b-4307-908a-84201867186d', 'traditional country'), - ('2afc2320-384f-43a4-a71e-1b763c485045', 'trance'), - ('9a339aa8-a0e5-450c-95a7-b11517bb508f', 'trap'), - ('a21ea484-efba-4119-8120-429b26f98728', 'trap edm'), - ('57159d7c-faa8-4266-abe1-7504e312fc88', 'tribal house'), - ('45eb1d9c-588c-4dc8-9394-a14b7c8f02bc', 'trip hop'), - ('cfe47781-460e-498a-92f5-399d68076727', 'turntablism'), - ('ca5d2892-93bf-4aae-85d5-a4589a1680b9', 'uk drill'), - ('95c57cd7-7fb8-4405-ade1-775c2d27e54e', 'uk garage'), - ('03a8749c-93e6-4b71-8204-b33de116d8fd', 'underground hip hop'), - ('bff33e5d-d591-498f-927f-b26c5527d817', 'vallenato'), - ('e837fa08-f314-428f-af96-ceed9858e3b2', 'vaporwave'), - ('fc736acd-9413-4b86-b8d4-47e9ce61d561', 'viking metal'), - ('823e4a7f-ade7-4d34-927a-721c60469b81', 'visual kei'), - ('9405d427-8b33-4670-a41a-040e23cef8ce', 'vocal house'), - ('782dc157-d1a5-42b9-9174-d329c24a7ef3', 'vocal jazz'), - ('f4dec9c1-abe2-4f3f-adee-5aa8f395d5ce', 'vocal trance'), - ('149a3524-0fd3-4bdc-9876-0361dfee8908', 'west coast hip hop'), - ('bb071d13-8c80-411b-9c0b-16b37bf71ae6', 'west coast swing'), - ('e6d6a58f-6c00-484e-9bc7-12e2c4d024e2', 'yé-yé'), - ('281e2c3f-80ad-4bc4-8b30-54222dee3b9c', 'zamrock'), - ('498229df-4956-4ed7-91f7-a9d4b1877af1', 'zydeco') -; - -CREATE OR REPLACE FUNCTION unique_primary_genre_alias() -RETURNS trigger AS $$ -BEGIN - IF NEW.primary_for_locale THEN - UPDATE genre_alias SET primary_for_locale = FALSE - WHERE locale = NEW.locale AND id != NEW.id - AND genre = NEW.genre; - END IF; - RETURN NEW; -END; -$$ LANGUAGE 'plpgsql'; - --------------------------------------------------------------------------------- -SELECT '20190422-mbs-7480.sql'; - -ALTER TABLE cover_art_archive.cover_art ADD COLUMN filesize INTEGER; -ALTER TABLE cover_art_archive.cover_art ADD COLUMN thumb_250_filesize INTEGER; -ALTER TABLE cover_art_archive.cover_art ADD COLUMN thumb_500_filesize INTEGER; -ALTER TABLE cover_art_archive.cover_art ADD COLUMN thumb_1200_filesize INTEGER; - --------------------------------------------------------------------------------- -SELECT '20190422-mbs-9973-collection-added-date.sql'; - -ALTER TABLE editor_collection_area ADD COLUMN added TIMESTAMP WITH TIME ZONE DEFAULT NOW(); -ALTER TABLE editor_collection_artist ADD COLUMN added TIMESTAMP WITH TIME ZONE DEFAULT NOW(); -ALTER TABLE editor_collection_event ADD COLUMN added TIMESTAMP WITH TIME ZONE DEFAULT NOW(); -ALTER TABLE editor_collection_instrument ADD COLUMN added TIMESTAMP WITH TIME ZONE DEFAULT NOW(); -ALTER TABLE editor_collection_label ADD COLUMN added TIMESTAMP WITH TIME ZONE DEFAULT NOW(); -ALTER TABLE editor_collection_place ADD COLUMN added TIMESTAMP WITH TIME ZONE DEFAULT NOW(); -ALTER TABLE editor_collection_recording ADD COLUMN added TIMESTAMP WITH TIME ZONE DEFAULT NOW(); -ALTER TABLE editor_collection_release ADD COLUMN added TIMESTAMP WITH TIME ZONE DEFAULT NOW(); -ALTER TABLE editor_collection_release_group ADD COLUMN added TIMESTAMP WITH TIME ZONE DEFAULT NOW(); -ALTER TABLE editor_collection_series ADD COLUMN added TIMESTAMP WITH TIME ZONE DEFAULT NOW(); -ALTER TABLE editor_collection_work ADD COLUMN added TIMESTAMP WITH TIME ZONE DEFAULT NOW(); -ALTER TABLE editor_collection_deleted_entity ADD COLUMN added TIMESTAMP WITH TIME ZONE DEFAULT NOW(); - -UPDATE editor_collection_area SET added = NULL; -UPDATE editor_collection_artist SET added = NULL; -UPDATE editor_collection_event SET added = NULL; -UPDATE editor_collection_instrument SET added = NULL; -UPDATE editor_collection_label SET added = NULL; -UPDATE editor_collection_place SET added = NULL; -UPDATE editor_collection_recording SET added = NULL; -UPDATE editor_collection_release SET added = NULL; -UPDATE editor_collection_release_group SET added = NULL; -UPDATE editor_collection_series SET added = NULL; -UPDATE editor_collection_work SET added = NULL; -UPDATE editor_collection_deleted_entity SET added = NULL; - --------------------------------------------------------------------------------- -SELECT '20190422-mbs-9428-collection-collaborators.sql'; - -CREATE TABLE editor_collection_collaborator ( - collection INTEGER NOT NULL, -- PK, references editor_collection.id - editor INTEGER NOT NULL -- references editor.id -); - -ALTER TABLE editor_collection_collaborator ADD CONSTRAINT editor_collection_collaborator_pkey PRIMARY KEY (collection, editor); - --------------------------------------------------------------------------------- -SELECT '20190422-mbs-5818-collection-position.sql'; - -ALTER TABLE editor_collection_area ADD COLUMN position INTEGER NOT NULL DEFAULT 0 CHECK (position >= 0); -ALTER TABLE editor_collection_artist ADD COLUMN position INTEGER NOT NULL DEFAULT 0 CHECK (position >= 0); -ALTER TABLE editor_collection_event ADD COLUMN position INTEGER NOT NULL DEFAULT 0 CHECK (position >= 0); -ALTER TABLE editor_collection_instrument ADD COLUMN position INTEGER NOT NULL DEFAULT 0 CHECK (position >= 0); -ALTER TABLE editor_collection_label ADD COLUMN position INTEGER NOT NULL DEFAULT 0 CHECK (position >= 0); -ALTER TABLE editor_collection_place ADD COLUMN position INTEGER NOT NULL DEFAULT 0 CHECK (position >= 0); -ALTER TABLE editor_collection_recording ADD COLUMN position INTEGER NOT NULL DEFAULT 0 CHECK (position >= 0); -ALTER TABLE editor_collection_release ADD COLUMN position INTEGER NOT NULL DEFAULT 0 CHECK (position >= 0); -ALTER TABLE editor_collection_release_group ADD COLUMN position INTEGER NOT NULL DEFAULT 0 CHECK (position >= 0); -ALTER TABLE editor_collection_series ADD COLUMN position INTEGER NOT NULL DEFAULT 0 CHECK (position >= 0); -ALTER TABLE editor_collection_work ADD COLUMN position INTEGER NOT NULL DEFAULT 0 CHECK (position >= 0); -ALTER TABLE editor_collection_deleted_entity ADD COLUMN position INTEGER NOT NULL DEFAULT 0 CHECK (position >= 0); - --------------------------------------------------------------------------------- -SELECT '20190422-mbs-1658-collection-text.sql'; - -ALTER TABLE editor_collection_area ADD COLUMN comment TEXT DEFAULT '' NOT NULL; -ALTER TABLE editor_collection_artist ADD COLUMN comment TEXT DEFAULT '' NOT NULL; -ALTER TABLE editor_collection_event ADD COLUMN comment TEXT DEFAULT '' NOT NULL; -ALTER TABLE editor_collection_instrument ADD COLUMN comment TEXT DEFAULT '' NOT NULL; -ALTER TABLE editor_collection_label ADD COLUMN comment TEXT DEFAULT '' NOT NULL; -ALTER TABLE editor_collection_place ADD COLUMN comment TEXT DEFAULT '' NOT NULL; -ALTER TABLE editor_collection_recording ADD COLUMN comment TEXT DEFAULT '' NOT NULL; -ALTER TABLE editor_collection_release ADD COLUMN comment TEXT DEFAULT '' NOT NULL; -ALTER TABLE editor_collection_release_group ADD COLUMN comment TEXT DEFAULT '' NOT NULL; -ALTER TABLE editor_collection_series ADD COLUMN comment TEXT DEFAULT '' NOT NULL; -ALTER TABLE editor_collection_work ADD COLUMN comment TEXT DEFAULT '' NOT NULL; -ALTER TABLE editor_collection_deleted_entity ADD COLUMN comment TEXT DEFAULT '' NOT NULL; - --------------------------------------------------------------------------------- -SELECT '20190423-mbs-10052-eaa.sql'; - -CREATE SCHEMA event_art_archive; - -SET search_path = event_art_archive, musicbrainz; - -CREATE TYPE musicbrainz.event_art_presence AS ENUM ('absent', 'present', 'darkened'); - -ALTER TABLE musicbrainz.event_meta -ADD COLUMN event_art_presence musicbrainz.event_art_presence NOT NULL DEFAULT 'absent'; - --- Tables - -CREATE TABLE art_type ( -- replicate (verbose) - id SERIAL NOT NULL, -- PK - name TEXT NOT NULL, - parent INTEGER, -- references event_art_archive.art_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -INSERT INTO art_type VALUES - (1, 'Poster', NULL, 0, NULL, generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'even_art_archive.art_type' || 1)); - -CREATE TABLE event_art ( -- replicate (verbose) - id BIGINT NOT NULL, -- PK - event INTEGER NOT NULL, -- references musicbrainz.event.id CASCADE - comment TEXT NOT NULL DEFAULT '', - edit INTEGER NOT NULL, -- separately references musicbrainz.edit.id - ordering INTEGER NOT NULL CHECK (ordering > 0), - date_uploaded TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - mime_type TEXT NOT NULL, -- references cover_art_archive.image_type.mime_type - filesize INTEGER, - thumb_250_filesize INTEGER, - thumb_500_filesize INTEGER, - thumb_1200_filesize INTEGER -); - -CREATE TABLE event_art_type ( -- replicate (verbose) - id BIGINT NOT NULL, -- PK, references event_art_archive.event_art.id CASCADE, - type_id INTEGER NOT NULL -- PK, references event_art_archive.art_type.id, -); - --- Primary keys - -ALTER TABLE art_type ADD CONSTRAINT art_type_pkey PRIMARY KEY (id); -ALTER TABLE event_art ADD CONSTRAINT event_art_pkey PRIMARY KEY (id); -ALTER TABLE event_art_type ADD CONSTRAINT event_art_type_pkey PRIMARY KEY (id, type_id); - --- Indexes - -CREATE INDEX event_art_idx_event ON event_art (event); -CREATE UNIQUE INDEX art_type_idx_gid ON art_type (gid); - --- Functions - -CREATE OR REPLACE FUNCTION materialize_eaa_presence() RETURNS trigger AS $$ - BEGIN - -- On delete, set the presence flag to 'absent' if there's no more - -- event art - IF TG_OP = 'DELETE' THEN - IF NOT EXISTS ( - SELECT TRUE FROM event_art_archive.event_art - WHERE event = OLD.event - ) THEN - UPDATE musicbrainz.event_meta - SET event_art_presence = 'absent' - WHERE id = OLD.event; - END IF; - END IF; - - -- On insert, set the presence flag to 'present' if it was previously - -- 'absent' - IF TG_OP = 'INSERT' THEN - CASE ( - SELECT event_art_presence FROM musicbrainz.event_meta - WHERE id = NEW.event - ) - WHEN 'absent' THEN - UPDATE musicbrainz.event_meta - SET event_art_presence = 'present' - WHERE id = NEW.event; - WHEN 'darkened' THEN - RAISE EXCEPTION 'This event has been darkened and cannot have new event art'; - ELSE - END CASE; - END IF; - - RETURN NULL; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION resequence_positions(event_id INT) RETURNS void AS $$ - BEGIN - UPDATE event_art_archive.event_art - SET ordering = recalculated.row_number - FROM ( - SELECT *, - row_number() OVER (PARTITION BY event ORDER BY ordering ASC) - FROM event_art_archive.event_art - WHERE event_art.event = event_id - ) recalculated - WHERE recalculated.id = event_art.id AND - recalculated.row_number != event_art.ordering; - END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION resequence_event_art_trigger() RETURNS trigger AS $$ - BEGIN - IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN - PERFORM event_art_archive.resequence_positions(NEW.event); - END IF; - - IF (TG_OP = 'DELETE') OR - (TG_OP = 'UPDATE' AND NEW.event != OLD.event) - THEN - PERFORM event_art_archive.resequence_positions(OLD.event); - END IF; - - RETURN NULL; - END; -$$ LANGUAGE 'plpgsql'; - --- Views - -CREATE OR REPLACE VIEW index_listing AS -SELECT event_art.*, - (edit.close_time IS NOT NULL) AS approved, - coalesce(event_art.id = (SELECT id FROM event_art_archive.event_art_type - JOIN event_art_archive.event_art ea_front USING (id) - WHERE ea_front.event = event_art.event - AND type_id = 1 - AND mime_type != 'application/pdf' - ORDER BY ea_front.ordering - LIMIT 1), FALSE) AS is_front, - array(SELECT art_type.name - FROM event_art_archive.event_art_type - JOIN event_art_archive.art_type ON event_art_type.type_id = art_type.id - WHERE event_art_type.id = event_art.id) AS types -FROM event_art_archive.event_art -LEFT JOIN musicbrainz.edit ON edit.id = event_art.edit; - --------------------------------------------------------------------------------- -SELECT '20190423-mbs-5387.sql'; - -ALTER TABLE artist_credit -ADD COLUMN edits_pending INTEGER NOT NULL DEFAULT 0 -CHECK (edits_pending >= 0); - -COMMIT; diff --git a/mbdata/sql/updates/schema-change/25.standalone.sql b/mbdata/sql/updates/schema-change/25.standalone.sql deleted file mode 100644 index ba0546a..0000000 --- a/mbdata/sql/updates/schema-change/25.standalone.sql +++ /dev/null @@ -1,155 +0,0 @@ --- Generated by CompileSchemaScripts.pl from: --- 20170604-mbs-9365.sql --- 20170909-mbs-9462-missing-event-triggers.sql --- 20180331-mbs-9664-non-loop-checks.sql --- 20190317-mbs-9941-mbs-10062-fks.sql --- 20190422-mbs-9428-collection-collaborators-fks.sql --- 20190423-mbs-10052-eaa-standalone.sql -\set ON_ERROR_STOP 1 -BEGIN; -SET search_path = musicbrainz, public; -SET LOCAL statement_timeout = 0; --------------------------------------------------------------------------------- -SELECT '20170604-mbs-9365.sql'; - -ALTER TABLE event_meta DROP CONSTRAINT IF EXISTS event_meta_fk_id; - -ALTER TABLE event_meta - ADD CONSTRAINT event_meta_fk_id - FOREIGN KEY (id) - REFERENCES event(id) - ON DELETE CASCADE; - --------------------------------------------------------------------------------- -SELECT '20170909-mbs-9462-missing-event-triggers.sql'; - -DROP TRIGGER IF EXISTS b_upd_l_event_url ON l_event_url; -DROP TRIGGER IF EXISTS remove_unused_links ON l_event_url; -DROP TRIGGER IF EXISTS url_gc_a_del_l_event_url ON l_event_url; -DROP TRIGGER IF EXISTS url_gc_a_upd_l_event_url ON l_event_url; - -CREATE TRIGGER b_upd_l_event_url - BEFORE UPDATE ON l_event_url - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_event_url DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER url_gc_a_del_l_event_url - AFTER DELETE ON l_event_url DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_url(); - -CREATE CONSTRAINT TRIGGER url_gc_a_upd_l_event_url - AFTER UPDATE ON l_event_url DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_url(); - --------------------------------------------------------------------------------- -SELECT '20180331-mbs-9664-non-loop-checks.sql'; - -ALTER TABLE l_area_area DROP CONSTRAINT IF EXISTS non_loop_relationship; -ALTER TABLE l_artist_artist DROP CONSTRAINT IF EXISTS non_loop_relationship; -ALTER TABLE l_event_event DROP CONSTRAINT IF EXISTS non_loop_relationship; -ALTER TABLE l_label_label DROP CONSTRAINT IF EXISTS non_loop_relationship; -ALTER TABLE l_instrument_instrument DROP CONSTRAINT IF EXISTS non_loop_relationship; -ALTER TABLE l_place_place DROP CONSTRAINT IF EXISTS non_loop_relationship; -ALTER TABLE l_recording_recording DROP CONSTRAINT IF EXISTS non_loop_relationship; -ALTER TABLE l_release_release DROP CONSTRAINT IF EXISTS non_loop_relationship; -ALTER TABLE l_release_group_release_group DROP CONSTRAINT IF EXISTS non_loop_relationship; -ALTER TABLE l_series_series DROP CONSTRAINT IF EXISTS non_loop_relationship; -ALTER TABLE l_url_url DROP CONSTRAINT IF EXISTS non_loop_relationship; -ALTER TABLE l_work_work DROP CONSTRAINT IF EXISTS non_loop_relationship; - -ALTER TABLE l_area_area ADD CONSTRAINT non_loop_relationship CHECK (entity0 != entity1); -ALTER TABLE l_artist_artist ADD CONSTRAINT non_loop_relationship CHECK (entity0 != entity1); -ALTER TABLE l_event_event ADD CONSTRAINT non_loop_relationship CHECK (entity0 != entity1); -ALTER TABLE l_label_label ADD CONSTRAINT non_loop_relationship CHECK (entity0 != entity1); -ALTER TABLE l_instrument_instrument ADD CONSTRAINT non_loop_relationship CHECK (entity0 != entity1); -ALTER TABLE l_place_place ADD CONSTRAINT non_loop_relationship CHECK (entity0 != entity1); -ALTER TABLE l_recording_recording ADD CONSTRAINT non_loop_relationship CHECK (entity0 != entity1); -ALTER TABLE l_release_release ADD CONSTRAINT non_loop_relationship CHECK (entity0 != entity1); -ALTER TABLE l_release_group_release_group ADD CONSTRAINT non_loop_relationship CHECK (entity0 != entity1); -ALTER TABLE l_series_series ADD CONSTRAINT non_loop_relationship CHECK (entity0 != entity1); -ALTER TABLE l_url_url ADD CONSTRAINT non_loop_relationship CHECK (entity0 != entity1); -ALTER TABLE l_work_work ADD CONSTRAINT non_loop_relationship CHECK (entity0 != entity1); - --------------------------------------------------------------------------------- -SELECT '20190317-mbs-9941-mbs-10062-fks.sql'; - -ALTER TABLE genre_alias - ADD CONSTRAINT genre_alias_fk_genre - FOREIGN KEY (genre) - REFERENCES genre(id); - -CREATE TRIGGER b_upd_genre BEFORE UPDATE ON genre - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_genre_alias BEFORE UPDATE ON genre_alias - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER unique_primary_for_locale BEFORE UPDATE OR INSERT ON genre_alias - FOR EACH ROW EXECUTE PROCEDURE unique_primary_genre_alias(); - --------------------------------------------------------------------------------- -SELECT '20190422-mbs-9428-collection-collaborators-fks.sql'; - -ALTER TABLE editor_collection_collaborator - ADD CONSTRAINT editor_collection_collaborator_fk_collection - FOREIGN KEY (collection) - REFERENCES editor_collection(id); - -ALTER TABLE editor_collection_collaborator - ADD CONSTRAINT editor_collection_collaborator_fk_editor - FOREIGN KEY (editor) - REFERENCES editor(id); - --------------------------------------------------------------------------------- -SELECT '20190423-mbs-10052-eaa-standalone.sql'; - -SET search_path = 'event_art_archive'; - --- Foreign keys - -ALTER TABLE event_art - ADD CONSTRAINT event_art_fk_edit - FOREIGN KEY (edit) - REFERENCES musicbrainz.edit(id); - -ALTER TABLE art_type - ADD CONSTRAINT art_type_fk_parent - FOREIGN KEY (parent) - REFERENCES event_art_archive.art_type(id); - -ALTER TABLE event_art - ADD CONSTRAINT event_art_fk_event - FOREIGN KEY (event) - REFERENCES musicbrainz.event(id) - ON DELETE CASCADE; - -ALTER TABLE event_art - ADD CONSTRAINT event_art_fk_mime_type - FOREIGN KEY (mime_type) - REFERENCES cover_art_archive.image_type(mime_type); - -ALTER TABLE event_art_type - ADD CONSTRAINT event_art_type_fk_id - FOREIGN KEY (id) - REFERENCES event_art_archive.event_art(id) - ON DELETE CASCADE; - -ALTER TABLE event_art_type - ADD CONSTRAINT event_art_type_fk_type_id - FOREIGN KEY (type_id) - REFERENCES event_art_archive.art_type(id); - --- Triggers - -CREATE TRIGGER update_event_art AFTER INSERT OR DELETE -ON event_art_archive.event_art -FOR EACH ROW EXECUTE PROCEDURE materialize_eaa_presence(); - -CREATE CONSTRAINT TRIGGER resquence_event_art AFTER INSERT OR UPDATE OR DELETE -ON event_art_archive.event_art DEFERRABLE INITIALLY DEFERRED -FOR EACH ROW EXECUTE PROCEDURE resequence_event_art_trigger(); - -COMMIT; diff --git a/mbdata/sql/updates/schema-change/26.mirror.sql b/mbdata/sql/updates/schema-change/26.mirror.sql deleted file mode 100644 index cc51dac..0000000 --- a/mbdata/sql/updates/schema-change/26.mirror.sql +++ /dev/null @@ -1,1165 +0,0 @@ --- Generated by CompileSchemaScripts.pl from: --- 20200512-mbs-10821-orphaned-recording-collection.sql --- 20200914-oauth-pkce.sql --- 20201028-mbs-1424.sql --- 20210215-mbs-11268.sql --- 20210309-mbs-11431.sql --- 20210311-mbs-11438.sql --- 20210319-mbs-10208.sql --- 20210319-mbs-11451.sql --- 20210319-mbs-11453.sql --- 20210319-mbs-11464.sql --- 20210319-mbs-11466.sql --- 20210406-mbs-11459.sql --- 20210505-mbs-11641.sql --- 20210507-mbs-11652-artist-series.sql -\set ON_ERROR_STOP 1 -BEGIN; -SET search_path = musicbrainz, public; -SET LOCAL statement_timeout = 0; --------------------------------------------------------------------------------- -SELECT '20200512-mbs-10821-orphaned-recording-collection.sql'; - -CREATE OR REPLACE FUNCTION delete_orphaned_recordings() -RETURNS TRIGGER -AS $$ - BEGIN - PERFORM TRUE - FROM recording outer_r - WHERE id = OLD.recording - AND edits_pending = 0 - AND NOT EXISTS ( - SELECT TRUE - FROM edit JOIN edit_recording er ON edit.id = er.edit - WHERE er.recording = outer_r.id - AND type IN (71, 207, 218) - LIMIT 1 - ) AND NOT EXISTS ( - SELECT TRUE FROM track WHERE track.recording = outer_r.id LIMIT 1 - ) AND NOT EXISTS ( - SELECT TRUE FROM l_area_recording WHERE entity1 = outer_r.id - UNION ALL - SELECT TRUE FROM l_artist_recording WHERE entity1 = outer_r.id - UNION ALL - SELECT TRUE FROM l_event_recording WHERE entity1 = outer_r.id - UNION ALL - SELECT TRUE FROM l_instrument_recording WHERE entity1 = outer_r.id - UNION ALL - SELECT TRUE FROM l_label_recording WHERE entity1 = outer_r.id - UNION ALL - SELECT TRUE FROM l_place_recording WHERE entity1 = outer_r.id - UNION ALL - SELECT TRUE FROM l_recording_recording WHERE entity1 = outer_r.id OR entity0 = outer_r.id - UNION ALL - SELECT TRUE FROM l_recording_release WHERE entity0 = outer_r.id - UNION ALL - SELECT TRUE FROM l_recording_release_group WHERE entity0 = outer_r.id - UNION ALL - SELECT TRUE FROM l_recording_series WHERE entity0 = outer_r.id - UNION ALL - SELECT TRUE FROM l_recording_work WHERE entity0 = outer_r.id - UNION ALL - SELECT TRUE FROM l_recording_url WHERE entity0 = outer_r.id - ); - - IF FOUND THEN - -- Remove references from tables that don't change whether or not this recording - -- is orphaned. - DELETE FROM isrc WHERE recording = OLD.recording; - DELETE FROM recording_alias WHERE recording = OLD.recording; - DELETE FROM recording_annotation WHERE recording = OLD.recording; - DELETE FROM recording_gid_redirect WHERE new_id = OLD.recording; - DELETE FROM recording_rating_raw WHERE recording = OLD.recording; - DELETE FROM recording_tag WHERE recording = OLD.recording; - DELETE FROM recording_tag_raw WHERE recording = OLD.recording; - DELETE FROM editor_collection_recording WHERE recording = OLD.recording; - - DELETE FROM recording WHERE id = OLD.recording; - END IF; - - RETURN NULL; - END; -$$ LANGUAGE 'plpgsql'; - --------------------------------------------------------------------------------- -SELECT '20200914-oauth-pkce.sql'; - - -DO $$ -BEGIN - PERFORM 1 FROM pg_type - WHERE typname = 'oauth_code_challenge_method'; - - IF NOT FOUND THEN - CREATE TYPE oauth_code_challenge_method AS ENUM ('plain', 'S256'); - END IF; -END -$$; - -ALTER TABLE editor_oauth_token ADD COLUMN IF NOT EXISTS code_challenge TEXT; -ALTER TABLE editor_oauth_token ADD COLUMN IF NOT EXISTS code_challenge_method oauth_code_challenge_method; - -DO $$ -BEGIN - PERFORM 1 FROM information_schema.constraint_column_usage - WHERE table_name = 'editor_oauth_token' - AND constraint_name = 'valid_code_challenge'; - - IF NOT FOUND THEN - ALTER TABLE editor_oauth_token ADD CONSTRAINT valid_code_challenge CHECK ( - (code_challenge IS NULL) = (code_challenge_method IS NULL) AND - (code_challenge IS NULL OR code_challenge ~ E'^[A-Za-z0-9.~_-]{43,128}$') - ); - END IF; -END -$$; - --------------------------------------------------------------------------------- -SELECT '20201028-mbs-1424.sql'; - - -DROP TABLE IF EXISTS release_first_release_date CASCADE; -DROP TABLE IF EXISTS recording_first_release_date CASCADE; - -CREATE TABLE release_first_release_date ( - release INTEGER NOT NULL, - year SMALLINT, - month SMALLINT, - day SMALLINT -); - -CREATE TABLE recording_first_release_date ( - recording INTEGER NOT NULL, - year SMALLINT, - month SMALLINT, - day SMALLINT -); - -CREATE OR REPLACE FUNCTION get_release_first_release_date_rows(condition TEXT) -RETURNS SETOF release_first_release_date AS $$ -BEGIN - RETURN QUERY EXECUTE ' - SELECT DISTINCT ON (release) release, - date_year AS year, - date_month AS month, - date_day AS day - FROM ( - SELECT release, date_year, date_month, date_day FROM release_country - WHERE (date_year IS NOT NULL OR date_month IS NOT NULL OR date_day IS NOT NULL) - UNION ALL - SELECT release, date_year, date_month, date_day FROM release_unknown_country - ) all_dates - WHERE ' || condition || - ' ORDER BY release, year NULLS LAST, month NULLS LAST, day NULLS LAST'; -END; -$$ LANGUAGE 'plpgsql' STRICT; - -CREATE OR REPLACE FUNCTION set_release_first_release_date(release_id INTEGER) -RETURNS VOID AS $$ -BEGIN - -- DO NOT modify any replicated tables in this function; it's used - -- by a trigger on slaves. - DELETE FROM release_first_release_date - WHERE release = release_id; - - INSERT INTO release_first_release_date - SELECT * FROM get_release_first_release_date_rows( - format('release = %L', release_id) - ); -END; -$$ LANGUAGE 'plpgsql' STRICT; - -CREATE OR REPLACE FUNCTION set_release_group_first_release_date(release_group_id INTEGER) -RETURNS VOID AS $$ -BEGIN - UPDATE release_group_meta SET first_release_date_year = first.year, - first_release_date_month = first.month, - first_release_date_day = first.day - FROM ( - SELECT rd.year, rd.month, rd.day - FROM release - LEFT JOIN release_first_release_date rd ON (rd.release = release.id) - WHERE release.release_group = release_group_id - ORDER BY - rd.year NULLS LAST, - rd.month NULLS LAST, - rd.day NULLS LAST - LIMIT 1 - ) AS first - WHERE id = release_group_id; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION get_recording_first_release_date_rows(condition TEXT) -RETURNS SETOF recording_first_release_date AS $$ -BEGIN - RETURN QUERY EXECUTE ' - SELECT DISTINCT ON (track.recording) - track.recording, rd.year, rd.month, rd.day - FROM track - JOIN medium ON medium.id = track.medium - JOIN release_first_release_date rd ON rd.release = medium.release - WHERE ' || condition || ' - ORDER BY track.recording, - rd.year NULLS LAST, - rd.month NULLS LAST, - rd.day NULLS LAST'; -END; -$$ LANGUAGE 'plpgsql' STRICT; - -CREATE OR REPLACE FUNCTION set_recordings_first_release_dates(recording_ids INTEGER[]) -RETURNS VOID AS $$ -BEGIN - -- DO NOT modify any replicated tables in this function; it's used - -- by a trigger on slaves. - DELETE FROM recording_first_release_date - WHERE recording = ANY(recording_ids); - - INSERT INTO recording_first_release_date - SELECT * FROM get_recording_first_release_date_rows( - format('track.recording = any(%L)', recording_ids) - ); -END; -$$ LANGUAGE 'plpgsql' STRICT; - -CREATE OR REPLACE FUNCTION set_releases_recordings_first_release_dates(release_ids INTEGER[]) -RETURNS VOID AS $$ -BEGIN - PERFORM set_recordings_first_release_dates(( - SELECT array_agg(recording) - FROM track - JOIN medium ON medium.id = track.medium - WHERE medium.release = any(release_ids) - )); - RETURN; -END; -$$ LANGUAGE 'plpgsql' STRICT; - -CREATE OR REPLACE FUNCTION a_ins_track() RETURNS trigger AS $$ -BEGIN - PERFORM inc_ref_count('artist_credit', NEW.artist_credit, 1); - -- increment track_count in the parent medium - UPDATE medium SET track_count = track_count + 1 WHERE id = NEW.medium; - PERFORM materialise_recording_length(NEW.recording); - PERFORM set_recordings_first_release_dates(ARRAY[NEW.recording]); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_upd_track() RETURNS trigger AS $$ -BEGIN - IF NEW.artist_credit != OLD.artist_credit THEN - PERFORM dec_ref_count('artist_credit', OLD.artist_credit, 1); - PERFORM inc_ref_count('artist_credit', NEW.artist_credit, 1); - END IF; - IF NEW.medium != OLD.medium THEN - -- medium is changed, decrement track_count in the original medium, increment in the new one - UPDATE medium SET track_count = track_count - 1 WHERE id = OLD.medium; - UPDATE medium SET track_count = track_count + 1 WHERE id = NEW.medium; - END IF; - IF OLD.recording <> NEW.recording THEN - PERFORM materialise_recording_length(OLD.recording); - PERFORM set_recordings_first_release_dates(ARRAY[OLD.recording, NEW.recording]); - END IF; - PERFORM materialise_recording_length(NEW.recording); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_del_track() RETURNS trigger AS $$ -BEGIN - PERFORM dec_ref_count('artist_credit', OLD.artist_credit, 1); - -- decrement track_count in the parent medium - UPDATE medium SET track_count = track_count - 1 WHERE id = OLD.medium; - PERFORM materialise_recording_length(OLD.recording); - PERFORM set_recordings_first_release_dates(ARRAY[OLD.recording]); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_ins_release_event() -RETURNS TRIGGER AS $$ -BEGIN - PERFORM set_release_first_release_date(NEW.release); - - PERFORM set_release_group_first_release_date(release_group) - FROM release - WHERE release.id = NEW.release; - - PERFORM set_releases_recordings_first_release_dates(ARRAY[NEW.release]); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_upd_release_event() -RETURNS TRIGGER AS $$ -BEGIN - PERFORM set_release_first_release_date(OLD.release); - PERFORM set_release_first_release_date(NEW.release); - - PERFORM set_release_group_first_release_date(release_group) - FROM release - WHERE release.id IN (NEW.release, OLD.release); - - PERFORM set_releases_recordings_first_release_dates(ARRAY[NEW.release, OLD.release]); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_del_release_event() -RETURNS TRIGGER AS $$ -BEGIN - PERFORM set_release_first_release_date(OLD.release); - - PERFORM set_release_group_first_release_date(release_group) - FROM release - WHERE release.id = OLD.release; - - PERFORM set_releases_recordings_first_release_dates(ARRAY[OLD.release]); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -ALTER TABLE release_first_release_date - ADD CONSTRAINT release_first_release_date_pkey - PRIMARY KEY (release); - -ALTER TABLE recording_first_release_date - ADD CONSTRAINT recording_first_release_date_pkey - PRIMARY KEY (recording); - --- **NOTE**: The new triggers overlap with ones created in --- admin/sql/updates/20210311-mbs-11438.sql, --- so somes changes have been consolidated into there. --- --- This includes the following functions: --- a_ins_release_event --- a_upd_release_event --- a_del_release_event --- a_ins_track --- a_upd_track --- a_del_track - --------------------------------------------------------------------------------- -SELECT '20210215-mbs-11268.sql'; - - -CREATE OR REPLACE VIEW medium_track_durations AS - SELECT - medium.id AS medium, - array_agg(track.length ORDER BY track.position) FILTER (WHERE track.position = 0) AS pregap_length, - array_agg(track.length ORDER BY track.position) FILTER (WHERE track.position > 0 AND track.is_data_track = false) AS cdtoc_track_lengths, - array_agg(track.length ORDER BY track.position) FILTER (WHERE track.is_data_track = true) AS data_track_lengths - FROM medium - JOIN track ON track.medium = medium.id - GROUP BY medium.id; - --------------------------------------------------------------------------------- -SELECT '20210309-mbs-11431.sql'; - - -CREATE INDEX IF NOT EXISTS artist_idx_lower_unaccent_name_comment ON artist (lower(musicbrainz_unaccent(name)), lower(musicbrainz_unaccent(comment))); -CREATE INDEX IF NOT EXISTS label_idx_lower_unaccent_name_comment ON label (lower(musicbrainz_unaccent(name)), lower(musicbrainz_unaccent(comment))); -CREATE INDEX IF NOT EXISTS place_idx_lower_unaccent_name_comment ON place (lower(musicbrainz_unaccent(name)), lower(musicbrainz_unaccent(comment))); -CREATE INDEX IF NOT EXISTS series_idx_lower_unaccent_name_comment ON series (lower(musicbrainz_unaccent(name)), lower(musicbrainz_unaccent(comment))); - -CREATE INDEX IF NOT EXISTS artist_alias_idx_lower_unaccent_name ON artist_alias (lower(musicbrainz_unaccent(name))); -CREATE INDEX IF NOT EXISTS label_alias_idx_lower_unaccent_name ON label_alias (lower(musicbrainz_unaccent(name))); -CREATE INDEX IF NOT EXISTS place_alias_idx_lower_unaccent_name ON place_alias (lower(musicbrainz_unaccent(name))); -CREATE INDEX IF NOT EXISTS series_alias_idx_lower_unaccent_name ON series_alias (lower(musicbrainz_unaccent(name))); - -DROP INDEX IF EXISTS artist_idx_lower_name; -DROP INDEX IF EXISTS label_idx_lower_name; - --------------------------------------------------------------------------------- -SELECT '20210311-mbs-11438.sql'; - - --- Tables - -CREATE TABLE artist_release ( - is_track_artist BOOLEAN NOT NULL, - artist INTEGER NOT NULL, - first_release_date INTEGER, - catalog_numbers TEXT[], - country_code CHAR(2), - barcode BIGINT, - sort_character CHAR(1) COLLATE musicbrainz NOT NULL, - release INTEGER NOT NULL -) PARTITION BY LIST (is_track_artist); - -CREATE TABLE artist_release_nonva - PARTITION OF artist_release FOR VALUES IN (FALSE); - -CREATE TABLE artist_release_va - PARTITION OF artist_release FOR VALUES IN (TRUE); - -CREATE TABLE artist_release_pending_update ( - release INTEGER NOT NULL -); - -CREATE TABLE artist_release_group ( - is_track_artist BOOLEAN NOT NULL, - artist INTEGER NOT NULL, - unofficial BOOLEAN NOT NULL, - primary_type SMALLINT, - secondary_types SMALLINT[], - first_release_date INTEGER, - sort_character CHAR(1) COLLATE musicbrainz NOT NULL, - release_group INTEGER NOT NULL -) PARTITION BY LIST (is_track_artist); - -CREATE TABLE artist_release_group_nonva - PARTITION OF artist_release_group FOR VALUES IN (FALSE); - -CREATE TABLE artist_release_group_va - PARTITION OF artist_release_group FOR VALUES IN (TRUE); - -CREATE TABLE artist_release_group_pending_update ( - release_group INTEGER NOT NULL -); - --- Functions - -CREATE OR REPLACE FUNCTION integer_date(year SMALLINT, month SMALLINT, day SMALLINT) -RETURNS INTEGER AS $$ - -- Returns an integer representation of the given date, keeping - -- NULL values sorted last. - SELECT ( - CASE - WHEN year IS NULL AND month IS NULL AND day IS NULL - THEN NULL - ELSE ( - coalesce(year::TEXT, '9999') || - lpad(coalesce(month::TEXT, '99'), 2, '0') || - lpad(coalesce(day::TEXT, '99'), 2, '0') - )::INTEGER - END - ) -$$ LANGUAGE SQL IMMUTABLE PARALLEL SAFE; - -CREATE OR REPLACE FUNCTION b_upd_artist_credit_name() RETURNS trigger AS $$ -BEGIN - -- Artist credits are assumed to be immutable. When changes need to - -- be made, we `find_or_insert` the new artist credits and swap - -- them with the old ones rather than mutate existing entries. - -- - -- This simplifies a lot of assumptions we can make about their - -- cacheability, and the consistency of materialized tables like - -- artist_release_group. - RAISE EXCEPTION 'Cannot update artist_credit_name'; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION b_upd_release_group_secondary_type_join() RETURNS trigger AS $$ -BEGIN - -- Like artist credits, rows in release_group_secondary_type_join - -- are immutable. When updates need to be made for a particular - -- release group, they're deleted and re-inserted. - -- - -- A benefit of this is that we don't need UPDATE triggers to keep - -- artist_release_group up-to-date. - RAISE EXCEPTION 'Cannot update release_group_secondary_type_join'; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_ins_release() RETURNS trigger AS $$ -BEGIN - -- increment ref_count of the name - PERFORM inc_ref_count('artist_credit', NEW.artist_credit, 1); - -- increment release_count of the parent release group - UPDATE release_group_meta SET release_count = release_count + 1 WHERE id = NEW.release_group; - -- add new release_meta - INSERT INTO release_meta (id) VALUES (NEW.id); - INSERT INTO release_coverart (id) VALUES (NEW.id); - INSERT INTO artist_release_pending_update VALUES (NEW.id); - INSERT INTO artist_release_group_pending_update VALUES (NEW.release_group); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_upd_release() RETURNS trigger AS $$ -BEGIN - IF NEW.artist_credit != OLD.artist_credit THEN - PERFORM dec_ref_count('artist_credit', OLD.artist_credit, 1); - PERFORM inc_ref_count('artist_credit', NEW.artist_credit, 1); - END IF; - IF NEW.release_group != OLD.release_group THEN - -- release group is changed, decrement release_count in the original RG, increment in the new one - UPDATE release_group_meta SET release_count = release_count - 1 WHERE id = OLD.release_group; - UPDATE release_group_meta SET release_count = release_count + 1 WHERE id = NEW.release_group; - PERFORM set_release_group_first_release_date(OLD.release_group); - PERFORM set_release_group_first_release_date(NEW.release_group); - END IF; - IF ( - NEW.status IS DISTINCT FROM OLD.status OR - NEW.release_group != OLD.release_group OR - NEW.artist_credit != OLD.artist_credit - ) THEN - INSERT INTO artist_release_group_pending_update - VALUES (NEW.release_group), (OLD.release_group); - END IF; - IF ( - NEW.barcode IS DISTINCT FROM OLD.barcode OR - NEW.name != OLD.name OR - NEW.artist_credit != OLD.artist_credit - ) THEN - INSERT INTO artist_release_pending_update VALUES (OLD.id); - END IF; - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_del_release() RETURNS trigger AS $$ -BEGIN - -- decrement ref_count of the name - PERFORM dec_ref_count('artist_credit', OLD.artist_credit, 1); - -- decrement release_count of the parent release group - UPDATE release_group_meta SET release_count = release_count - 1 WHERE id = OLD.release_group; - INSERT INTO artist_release_pending_update VALUES (OLD.id); - INSERT INTO artist_release_group_pending_update VALUES (OLD.release_group); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_ins_release_event() -RETURNS TRIGGER AS $$ -BEGIN - PERFORM set_release_first_release_date(NEW.release); - - PERFORM set_release_group_first_release_date(release_group) - FROM release - WHERE release.id = NEW.release; - - PERFORM set_releases_recordings_first_release_dates(ARRAY[NEW.release]); - - IF TG_TABLE_NAME = 'release_country' THEN - INSERT INTO artist_release_pending_update VALUES (NEW.release); - END IF; - - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_upd_release_event() -RETURNS TRIGGER AS $$ -BEGIN - PERFORM set_release_first_release_date(OLD.release); - PERFORM set_release_first_release_date(NEW.release); - - PERFORM set_release_group_first_release_date(release_group) - FROM release - WHERE release.id IN (NEW.release, OLD.release); - - PERFORM set_releases_recordings_first_release_dates(ARRAY[NEW.release, OLD.release]); - - IF TG_TABLE_NAME = 'release_country' THEN - IF NEW.country != OLD.country THEN - INSERT INTO artist_release_pending_update VALUES (OLD.release); - END IF; - END IF; - - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_del_release_event() -RETURNS TRIGGER AS $$ -BEGIN - PERFORM set_release_first_release_date(OLD.release); - - PERFORM set_release_group_first_release_date(release_group) - FROM release - WHERE release.id = OLD.release; - - PERFORM set_releases_recordings_first_release_dates(ARRAY[OLD.release]); - - IF TG_TABLE_NAME = 'release_country' THEN - INSERT INTO artist_release_pending_update VALUES (OLD.release); - END IF; - - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_ins_release_group_secondary_type_join() -RETURNS trigger AS $$ -BEGIN - INSERT INTO artist_release_group_pending_update VALUES (NEW.release_group); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_del_release_group_secondary_type_join() -RETURNS trigger AS $$ -BEGIN - INSERT INTO artist_release_group_pending_update VALUES (OLD.release_group); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_ins_release_label() -RETURNS trigger AS $$ -BEGIN - INSERT INTO artist_release_pending_update VALUES (NEW.release); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_upd_release_label() -RETURNS trigger AS $$ -BEGIN - IF NEW.catalog_number IS DISTINCT FROM OLD.catalog_number THEN - INSERT INTO artist_release_pending_update VALUES (OLD.release); - END IF; - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_del_release_label() -RETURNS trigger AS $$ -BEGIN - INSERT INTO artist_release_pending_update VALUES (OLD.release); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_ins_release_group() RETURNS trigger AS $$ -BEGIN - PERFORM inc_ref_count('artist_credit', NEW.artist_credit, 1); - INSERT INTO release_group_meta (id) VALUES (NEW.id); - INSERT INTO artist_release_group_pending_update VALUES (NEW.id); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_upd_release_group() RETURNS trigger AS $$ -BEGIN - IF NEW.artist_credit != OLD.artist_credit THEN - PERFORM dec_ref_count('artist_credit', OLD.artist_credit, 1); - PERFORM inc_ref_count('artist_credit', NEW.artist_credit, 1); - END IF; - IF ( - NEW.name != OLD.name OR - NEW.artist_credit != OLD.artist_credit OR - NEW.type IS DISTINCT FROM OLD.type - ) THEN - INSERT INTO artist_release_group_pending_update VALUES (OLD.id); - END IF; - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_del_release_group() RETURNS trigger AS $$ -BEGIN - PERFORM dec_ref_count('artist_credit', OLD.artist_credit, 1); - INSERT INTO artist_release_group_pending_update VALUES (OLD.id); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION b_upd_release_group_secondary_type_join() RETURNS trigger AS $$ -BEGIN - -- Like artist credits, rows in release_group_secondary_type_join - -- are immutable. When updates need to be made for a particular - -- release group, they're deleted and re-inserted. - -- - -- A benefit of this is that we don't need UPDATE triggers to keep - -- artist_release_group up-to-date. - RAISE EXCEPTION 'Cannot update release_group_secondary_type_join'; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_ins_track() RETURNS trigger AS $$ -BEGIN - PERFORM inc_ref_count('artist_credit', NEW.artist_credit, 1); - -- increment track_count in the parent medium - UPDATE medium SET track_count = track_count + 1 WHERE id = NEW.medium; - PERFORM materialise_recording_length(NEW.recording); - PERFORM set_recordings_first_release_dates(ARRAY[NEW.recording]); - INSERT INTO artist_release_pending_update ( - SELECT release FROM medium - WHERE id = NEW.medium - ); - INSERT INTO artist_release_group_pending_update ( - SELECT release_group FROM release - JOIN medium ON medium.release = release.id - WHERE medium.id = NEW.medium - ); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_upd_track() RETURNS trigger AS $$ -BEGIN - IF NEW.artist_credit != OLD.artist_credit THEN - PERFORM dec_ref_count('artist_credit', OLD.artist_credit, 1); - PERFORM inc_ref_count('artist_credit', NEW.artist_credit, 1); - INSERT INTO artist_release_pending_update ( - SELECT release FROM medium - WHERE id = OLD.medium - ); - INSERT INTO artist_release_group_pending_update ( - SELECT release_group FROM release - JOIN medium ON medium.release = release.id - WHERE medium.id = OLD.medium - ); - END IF; - IF NEW.medium != OLD.medium THEN - IF ( - SELECT count(DISTINCT release) - FROM medium - WHERE id IN (NEW.medium, OLD.medium) - ) = 2 - THEN - -- I don't believe this code path should ever be hit. - -- We have no functionality to move tracks between - -- mediums. If this is ever allowed, however, we should - -- ensure that both old and new mediums share the same - -- release, otherwise we'd have to carefully handle this - -- case when when updating materialized tables for - -- recordings' first release dates and artists' release - -- groups. -mwiencek, 2021-03-14 - RAISE EXCEPTION 'Cannot move a track between releases'; - END IF; - - -- medium is changed, decrement track_count in the original medium, increment in the new one - UPDATE medium SET track_count = track_count - 1 WHERE id = OLD.medium; - UPDATE medium SET track_count = track_count + 1 WHERE id = NEW.medium; - END IF; - IF OLD.recording <> NEW.recording THEN - PERFORM materialise_recording_length(OLD.recording); - PERFORM set_recordings_first_release_dates(ARRAY[OLD.recording, NEW.recording]); - END IF; - PERFORM materialise_recording_length(NEW.recording); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION a_del_track() RETURNS trigger AS $$ -BEGIN - PERFORM dec_ref_count('artist_credit', OLD.artist_credit, 1); - -- decrement track_count in the parent medium - UPDATE medium SET track_count = track_count - 1 WHERE id = OLD.medium; - PERFORM materialise_recording_length(OLD.recording); - PERFORM set_recordings_first_release_dates(ARRAY[OLD.recording]); - INSERT INTO artist_release_pending_update ( - SELECT release FROM medium - WHERE id = OLD.medium - ); - INSERT INTO artist_release_group_pending_update ( - SELECT release_group FROM release - JOIN medium ON medium.release = release.id - WHERE medium.id = OLD.medium - ); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION set_release_first_release_date(release_id INTEGER) -RETURNS VOID AS $$ -BEGIN - -- DO NOT modify any replicated tables in this function; it's used - -- by a trigger on slaves. - DELETE FROM release_first_release_date - WHERE release = release_id; - - INSERT INTO release_first_release_date - SELECT * FROM get_release_first_release_date_rows( - format('release = %L', release_id) - ); - - INSERT INTO artist_release_pending_update VALUES (release_id); -END; -$$ LANGUAGE 'plpgsql' STRICT; - -CREATE OR REPLACE FUNCTION set_release_group_first_release_date(release_group_id INTEGER) -RETURNS VOID AS $$ -BEGIN - UPDATE release_group_meta SET first_release_date_year = first.year, - first_release_date_month = first.month, - first_release_date_day = first.day - FROM ( - SELECT rd.year, rd.month, rd.day - FROM release - LEFT JOIN release_first_release_date rd ON (rd.release = release.id) - WHERE release.release_group = release_group_id - ORDER BY - rd.year NULLS LAST, - rd.month NULLS LAST, - rd.day NULLS LAST - LIMIT 1 - ) AS first - WHERE id = release_group_id; - INSERT INTO artist_release_group_pending_update VALUES (release_group_id); -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION get_artist_release_rows( - release_id INTEGER -) RETURNS SETOF artist_release AS $$ -BEGIN - -- PostgreSQL 12 generates a vastly more efficient plan when only - -- one release ID is passed. A condition like `r.id = any(...)` - -- can be over 200x slower, even with only one release ID in the - -- array. - RETURN QUERY EXECUTE $SQL$ - SELECT DISTINCT ON (ar.artist, r.id) - ar.is_track_artist, - ar.artist, - integer_date(rfrd.year, rfrd.month, rfrd.day) AS first_release_date, - array_agg( - DISTINCT rl.catalog_number ORDER BY rl.catalog_number - ) FILTER (WHERE rl.catalog_number IS NOT NULL)::TEXT[] AS catalog_numbers, - min(iso.code ORDER BY iso.code)::CHAR(2) AS country_code, - left(regexp_replace( - (CASE r.barcode WHEN '' THEN '0' ELSE r.barcode END), - '[^0-9]+', '', 'g' - ), 18)::BIGINT AS barcode, - left(r.name, 1)::CHAR(1) AS sort_character, - r.id - FROM ( - SELECT FALSE AS is_track_artist, racn.artist, r.id AS release - FROM release r - JOIN artist_credit_name racn ON racn.artist_credit = r.artist_credit - UNION ALL - SELECT TRUE AS is_track_artist, tacn.artist, m.release - FROM medium m - JOIN track t ON t.medium = m.id - JOIN artist_credit_name tacn ON tacn.artist_credit = t.artist_credit - ) ar - JOIN release r ON r.id = ar.release - LEFT JOIN release_first_release_date rfrd ON rfrd.release = r.id - LEFT JOIN release_label rl ON rl.release = r.id - LEFT JOIN release_country rc ON rc.release = r.id - LEFT JOIN iso_3166_1 iso ON iso.area = rc.country - $SQL$ || (CASE WHEN release_id IS NULL THEN '' ELSE 'WHERE r.id = $1' END) || - $SQL$ - GROUP BY ar.is_track_artist, ar.artist, rfrd.release, r.id - ORDER BY ar.artist, r.id, ar.is_track_artist - $SQL$ - USING release_id; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE FUNCTION apply_artist_release_pending_updates() -RETURNS trigger AS $$ -DECLARE - release_ids INTEGER[]; - release_id INTEGER; -BEGIN - -- DO NOT modify any replicated tables in this function; it's used - -- by a trigger on slaves. - SELECT array_agg(DISTINCT release) - INTO release_ids - FROM artist_release_pending_update; - - IF coalesce(array_length(release_ids, 1), 0) > 0 THEN - -- If the user hasn't generated `artist_release`, then we - -- shouldn't update or insert to it. MBS determines whether to - -- use this table based on it being non-empty, so a partial - -- table would manifest as partial data on the website and - -- webservice. - PERFORM 1 FROM artist_release LIMIT 1; - IF FOUND THEN - DELETE FROM artist_release WHERE release = any(release_ids); - - FOREACH release_id IN ARRAY release_ids LOOP - -- We handle each release ID separately because the - -- `get_artist_release_rows` query can be planned much - -- more efficiently that way. - INSERT INTO artist_release - SELECT * FROM get_artist_release_rows(release_id); - END LOOP; - END IF; - END IF; - - TRUNCATE artist_release_pending_update; - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION get_artist_release_group_rows( - release_group_id INTEGER -) RETURNS SETOF artist_release_group AS $$ -BEGIN - -- PostgreSQL 12 generates a vastly more efficient plan when only - -- one release group ID is passed. A condition like - -- `rg.id = any(...)` can be over 200x slower, even with only one - -- release group ID in the array. - RETURN QUERY EXECUTE $SQL$ - SELECT DISTINCT ON (arg.artist, rg.id) - arg.is_track_artist, - arg.artist, - bool_and(r.status IS NOT NULL AND r.status != 1), - rg.type::SMALLINT, - array_agg( - DISTINCT st.secondary_type ORDER BY st.secondary_type) - FILTER (WHERE st.secondary_type IS NOT NULL - )::SMALLINT[], - integer_date( - rgm.first_release_date_year, - rgm.first_release_date_month, - rgm.first_release_date_day - ), - left(rg.name, 1)::CHAR(1), - rg.id - FROM ( - SELECT FALSE AS is_track_artist, rgacn.artist, rg.id AS release_group - FROM release_group rg - JOIN artist_credit_name rgacn ON rgacn.artist_credit = rg.artist_credit - UNION ALL - SELECT TRUE AS is_track_artist, tacn.artist, r.release_group - FROM release r - JOIN medium m ON m.release = r.id - JOIN track t ON t.medium = m.id - JOIN artist_credit_name tacn ON tacn.artist_credit = t.artist_credit - ) arg - JOIN release_group rg ON rg.id = arg.release_group - LEFT JOIN release r ON r.release_group = rg.id - JOIN release_group_meta rgm ON rgm.id = rg.id - LEFT JOIN release_group_secondary_type_join st ON st.release_group = rg.id - $SQL$ || (CASE WHEN release_group_id IS NULL THEN '' ELSE 'WHERE rg.id = $1' END) || - $SQL$ - GROUP BY arg.is_track_artist, arg.artist, rgm.id, rg.id - ORDER BY arg.artist, rg.id, arg.is_track_artist - $SQL$ - USING release_group_id; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE FUNCTION apply_artist_release_group_pending_updates() -RETURNS trigger AS $$ -DECLARE - release_group_ids INTEGER[]; - release_group_id INTEGER; -BEGIN - -- DO NOT modify any replicated tables in this function; it's used - -- by a trigger on slaves. - SELECT array_agg(DISTINCT release_group) - INTO release_group_ids - FROM artist_release_group_pending_update; - - IF coalesce(array_length(release_group_ids, 1), 0) > 0 THEN - -- If the user hasn't generated `artist_release_group`, then we - -- shouldn't update or insert to it. MBS determines whether to - -- use this table based on it being non-empty, so a partial - -- table would manifest as partial data on the website and - -- webservice. - PERFORM 1 FROM artist_release_group LIMIT 1; - IF FOUND THEN - DELETE FROM artist_release_group WHERE release_group = any(release_group_ids); - - FOREACH release_group_id IN ARRAY release_group_ids LOOP - -- We handle each release group ID separately because - -- the `get_artist_release_group_rows` query can be - -- planned much more efficiently that way. - INSERT INTO artist_release_group - SELECT * FROM get_artist_release_group_rows(release_group_id); - END LOOP; - END IF; - END IF; - - TRUNCATE artist_release_group_pending_update; - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - --- Indexes - -CREATE INDEX artist_release_nonva_idx_sort ON artist_release_nonva (artist, first_release_date NULLS LAST, catalog_numbers NULLS LAST, country_code NULLS LAST, barcode NULLS LAST, sort_character, release); -CREATE INDEX artist_release_va_idx_sort ON artist_release_va (artist, first_release_date NULLS LAST, catalog_numbers NULLS LAST, country_code NULLS LAST, barcode NULLS LAST, sort_character, release); - -CREATE UNIQUE INDEX artist_release_nonva_idx_uniq ON artist_release_nonva (release, artist); -CREATE UNIQUE INDEX artist_release_va_idx_uniq ON artist_release_va (release, artist); - -CREATE INDEX artist_release_pending_update_idx_release ON artist_release_pending_update USING HASH (release); - -CREATE INDEX artist_release_group_nonva_idx_sort ON artist_release_group_nonva (artist, unofficial, primary_type NULLS FIRST, secondary_types NULLS FIRST, first_release_date NULLS LAST, sort_character, release_group); -CREATE INDEX artist_release_group_va_idx_sort ON artist_release_group_va (artist, unofficial, primary_type NULLS FIRST, secondary_types NULLS FIRST, first_release_date NULLS LAST, sort_character, release_group); - -CREATE UNIQUE INDEX artist_release_group_nonva_idx_uniq ON artist_release_group_nonva (release_group, artist); -CREATE UNIQUE INDEX artist_release_group_va_idx_uniq ON artist_release_group_va (release_group, artist); - -CREATE INDEX artist_release_group_pending_update_idx_release_group ON artist_release_group_pending_update USING HASH (release_group); - --------------------------------------------------------------------------------- -SELECT '20210319-mbs-10208.sql'; - - -CREATE TABLE editor_collection_gid_redirect ( - gid UUID NOT NULL, -- PK - new_id INTEGER NOT NULL, -- references editor_collection.id - created TIMESTAMP WITH TIME ZONE DEFAULT NOW() -); - -ALTER TABLE editor_collection_gid_redirect - ADD CONSTRAINT editor_collection_gid_redirect_pkey - PRIMARY KEY (gid); - -CREATE INDEX editor_collection_gid_redirect_idx_new_id ON editor_collection_gid_redirect (new_id); - --------------------------------------------------------------------------------- -SELECT '20210319-mbs-11451.sql'; - -CREATE TABLE place_meta ( -- replicate - id INTEGER NOT NULL, -- PK, references place.id CASCADE - rating SMALLINT CHECK (rating >= 0 AND rating <= 100), - rating_count INTEGER -); - -CREATE TABLE place_rating_raw -( - place INTEGER NOT NULL, -- PK, references place.id - editor INTEGER NOT NULL, -- PK, references editor.id - rating SMALLINT NOT NULL CHECK (rating >= 0 AND rating <= 100) -); - -ALTER TABLE place_meta ADD CONSTRAINT place_meta_pkey PRIMARY KEY (id); -ALTER TABLE place_rating_raw ADD CONSTRAINT place_rating_raw_pkey PRIMARY KEY (place, editor); - -CREATE OR REPLACE FUNCTION a_ins_place() RETURNS trigger AS $$ -BEGIN - -- add a new entry to the place_meta table - INSERT INTO place_meta (id) VALUES (NEW.id); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -INSERT INTO place_meta (id) - (SELECT id FROM place); - -CREATE INDEX place_rating_raw_idx_editor ON place_rating_raw (editor); - --------------------------------------------------------------------------------- -SELECT '20210319-mbs-11453.sql'; - -ALTER TABLE link_type - ALTER COLUMN entity0_cardinality SET DATA TYPE SMALLINT, - ALTER COLUMN entity1_cardinality SET DATA TYPE SMALLINT; - --------------------------------------------------------------------------------- -SELECT '20210319-mbs-11464.sql'; - -DROP TABLE IF EXISTS statistics.log_statistic; - --------------------------------------------------------------------------------- -SELECT '20210319-mbs-11466.sql'; - -ALTER TABLE language - ALTER COLUMN frequency SET DATA TYPE SMALLINT; - -ALTER TABLE script - ALTER COLUMN frequency SET DATA TYPE SMALLINT; - --------------------------------------------------------------------------------- -SELECT '20210406-mbs-11459.sql'; - - -CREATE OR REPLACE FUNCTION edit_data_type_info(data JSONB) RETURNS TEXT AS $$ -BEGIN - CASE jsonb_typeof(data) - WHEN 'object' THEN - RETURN '{' || - (SELECT string_agg( - to_json(key) || ':' || - edit_data_type_info(jsonb_extract_path(data, key)), - ',' ORDER BY key) - FROM jsonb_object_keys(data) AS key) || - '}'; - WHEN 'array' THEN - RETURN '[' || - (SELECT string_agg( - DISTINCT edit_data_type_info(item), - ',' ORDER BY edit_data_type_info(item)) - FROM jsonb_array_elements(data) AS item) || - ']'; - WHEN 'string' THEN - RETURN '1'; - WHEN 'number' THEN - RETURN '2'; - WHEN 'boolean' THEN - RETURN '4'; - WHEN 'null' THEN - RETURN '8'; - END CASE; - RETURN ''; -END; -$$ LANGUAGE plpgsql IMMUTABLE PARALLEL SAFE STRICT; - --------------------------------------------------------------------------------- -SELECT '20210505-mbs-11641.sql'; - - -DROP INDEX IF EXISTS artist_rating_raw_idx_artist; -DROP INDEX IF EXISTS event_rating_raw_idx_event; -DROP INDEX IF EXISTS label_rating_raw_idx_label; -DROP INDEX IF EXISTS release_group_rating_raw_idx_release_group; - --------------------------------------------------------------------------------- -SELECT '20210507-mbs-11652-artist-series.sql'; - -\set ARTIST_PART_OF_SERIES_ID '996' - --- generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'http://musicbrainz.org/linktype/artist/series/part_of') -\set ARTIST_PART_OF_SERIES_GID '''d1a845d1-8c03-3191-9454-e4e8d37fa5e0''' - --- id from link_attribute_type where name = 'number' -\set LINK_ATTRIBUTE_TYPE_NUMBER_ID '788' - ------------------------ --- CREATE NEW VIEWS -- ------------------------ - -CREATE OR REPLACE VIEW artist_series AS - SELECT entity0 AS artist, - entity1 AS series, - las.id AS relationship, - link_order, - las.link, - COALESCE(text_value, '') AS text_value - FROM l_artist_series las - JOIN series s ON s.id = las.entity1 - JOIN link l ON l.id = las.link - JOIN link_type lt ON (lt.id = l.link_type AND lt.gid = :ARTIST_PART_OF_SERIES_GID) - LEFT OUTER JOIN link_attribute_text_value latv ON (latv.attribute_type = :LINK_ATTRIBUTE_TYPE_NUMBER_ID AND latv.link = l.id) - ORDER BY series, link_order; - -------------------------- --- INSERT INITIAL DATA -- -------------------------- - --- Part-of-series rel - -INSERT INTO link_type (id, gid, entity_type0, entity_type1, entity0_cardinality, - entity1_cardinality, name, description, link_phrase, - reverse_link_phrase, long_link_phrase) VALUES - ( - :ARTIST_PART_OF_SERIES_ID, - :ARTIST_PART_OF_SERIES_GID, - 'artist', 'series', 0, 0, 'part of', - 'Indicates that the artist is part of a series.', - 'part of', 'has parts', 'is a part of' - ); - -INSERT INTO link_type_attribute_type (link_type, attribute_type, min, max) VALUES - ( - :ARTIST_PART_OF_SERIES_ID, - :LINK_ATTRIBUTE_TYPE_NUMBER_ID, - 0, - 1 - ); - -INSERT INTO orderable_link_type (link_type, direction) VALUES - (:ARTIST_PART_OF_SERIES_ID, 2); - -ALTER TABLE series_type DROP CONSTRAINT IF EXISTS allowed_series_entity_type; - -INSERT INTO series_type (id, name, entity_type, parent, child_order, description, gid) VALUES - (13, 'Artist series', 'artist', NULL, 4, 'A series of artists.', generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'series_type13')), - (14, 'Artist award', 'artist', 13, 0, 'A series of artists honoured by the same award.', generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'series_type14')); - -\unset ARTIST_PART_OF_SERIES_GID -\unset LINK_ATTRIBUTE_TYPE_NUMBER_ID - -COMMIT; diff --git a/mbdata/sql/updates/schema-change/26.standalone.sql b/mbdata/sql/updates/schema-change/26.standalone.sql deleted file mode 100644 index 4432e8d..0000000 --- a/mbdata/sql/updates/schema-change/26.standalone.sql +++ /dev/null @@ -1,177 +0,0 @@ --- Generated by CompileSchemaScripts.pl from: --- 20201028-mbs-1424-fks.sql --- 20210311-mbs-11438-standalone.sql --- 20210319-mbs-10208-standalone.sql --- 20210319-mbs-10647.sql --- 20210319-mbs-11451-standalone.sql --- 20210507-mbs-11652-artist-series-fks.sql -\set ON_ERROR_STOP 1 -BEGIN; -SET search_path = musicbrainz, public; -SET LOCAL statement_timeout = 0; --------------------------------------------------------------------------------- -SELECT '20201028-mbs-1424-fks.sql'; - - -ALTER TABLE release_first_release_date - ADD CONSTRAINT release_first_release_date_fk_release - FOREIGN KEY (release) - REFERENCES release(id) - ON DELETE CASCADE; - -ALTER TABLE recording_first_release_date - ADD CONSTRAINT recording_first_release_date_fk_recording - FOREIGN KEY (recording) - REFERENCES recording(id) - ON DELETE CASCADE; - --------------------------------------------------------------------------------- -SELECT '20210311-mbs-11438-standalone.sql'; - - -ALTER TABLE artist_release - ADD CONSTRAINT artist_release_fk_artist - FOREIGN KEY (artist) - REFERENCES artist(id) - ON DELETE CASCADE; - -ALTER TABLE artist_release - ADD CONSTRAINT artist_release_fk_release - FOREIGN KEY (release) - REFERENCES release(id) - ON DELETE CASCADE; - -ALTER TABLE artist_release_group - ADD CONSTRAINT artist_release_group_fk_artist - FOREIGN KEY (artist) - REFERENCES artist(id) - ON DELETE CASCADE; - -ALTER TABLE artist_release_group - ADD CONSTRAINT artist_release_group_fk_release_group - FOREIGN KEY (release_group) - REFERENCES release_group(id) - ON DELETE CASCADE; - -CREATE TRIGGER b_upd_artist_credit_name BEFORE UPDATE ON artist_credit_name - FOR EACH ROW EXECUTE PROCEDURE b_upd_artist_credit_name(); - -CREATE TRIGGER a_ins_release_group_secondary_type_join AFTER INSERT ON release_group_secondary_type_join - FOR EACH ROW EXECUTE PROCEDURE a_ins_release_group_secondary_type_join(); - -CREATE TRIGGER a_del_release_group_secondary_type_join AFTER DELETE ON release_group_secondary_type_join - FOR EACH ROW EXECUTE PROCEDURE a_del_release_group_secondary_type_join(); - -CREATE TRIGGER b_upd_release_group_secondary_type_join BEFORE UPDATE ON release_group_secondary_type_join - FOR EACH ROW EXECUTE PROCEDURE b_upd_release_group_secondary_type_join(); - -CREATE TRIGGER a_ins_release_label AFTER INSERT ON release_label - FOR EACH ROW EXECUTE PROCEDURE a_ins_release_label(); - -CREATE TRIGGER a_upd_release_label AFTER UPDATE ON release_label - FOR EACH ROW EXECUTE PROCEDURE a_upd_release_label(); - -CREATE TRIGGER a_del_release_label AFTER DELETE ON release_label - FOR EACH ROW EXECUTE PROCEDURE a_del_release_label(); - -CREATE CONSTRAINT TRIGGER apply_artist_release_group_pending_updates - AFTER INSERT OR UPDATE OR DELETE ON release DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE apply_artist_release_group_pending_updates(); - -CREATE CONSTRAINT TRIGGER apply_artist_release_pending_updates - AFTER INSERT OR UPDATE OR DELETE ON release DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE apply_artist_release_pending_updates(); - -CREATE CONSTRAINT TRIGGER apply_artist_release_pending_updates - AFTER INSERT OR UPDATE OR DELETE ON release_country DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE apply_artist_release_pending_updates(); - -CREATE CONSTRAINT TRIGGER apply_artist_release_pending_updates - AFTER INSERT OR UPDATE OR DELETE ON release_first_release_date DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE apply_artist_release_pending_updates(); - -CREATE CONSTRAINT TRIGGER apply_artist_release_group_pending_updates - AFTER INSERT OR UPDATE OR DELETE ON release_group DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE apply_artist_release_group_pending_updates(); - -CREATE CONSTRAINT TRIGGER apply_artist_release_group_pending_updates - AFTER UPDATE ON release_group_meta DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE apply_artist_release_group_pending_updates(); - -CREATE CONSTRAINT TRIGGER apply_artist_release_group_pending_updates - AFTER INSERT OR DELETE ON release_group_secondary_type_join DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE apply_artist_release_group_pending_updates(); - -CREATE CONSTRAINT TRIGGER apply_artist_release_pending_updates - AFTER INSERT OR UPDATE OR DELETE ON release_label DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE apply_artist_release_pending_updates(); - -CREATE CONSTRAINT TRIGGER apply_artist_release_group_pending_updates - AFTER INSERT OR UPDATE OR DELETE ON track DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE apply_artist_release_group_pending_updates(); - -CREATE CONSTRAINT TRIGGER apply_artist_release_pending_updates - AFTER INSERT OR UPDATE OR DELETE ON track DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE apply_artist_release_pending_updates(); - --------------------------------------------------------------------------------- -SELECT '20210319-mbs-10208-standalone.sql'; - - -ALTER TABLE editor_collection_gid_redirect - ADD CONSTRAINT editor_collection_gid_redirect_fk_new_id - FOREIGN KEY (new_id) - REFERENCES editor_collection(id); - --------------------------------------------------------------------------------- -SELECT '20210319-mbs-10647.sql'; - -DROP TRIGGER IF EXISTS b_del_label_special ON label; - -CREATE TRIGGER b_del_label_special BEFORE DELETE ON label - FOR EACH ROW WHEN (OLD.id IN (1, 3267)) EXECUTE PROCEDURE deny_special_purpose_deletion(); - --------------------------------------------------------------------------------- -SELECT '20210319-mbs-11451-standalone.sql'; - -DROP TRIGGER IF EXISTS a_ins_place ON place; - -CREATE TRIGGER a_ins_place AFTER INSERT ON place - FOR EACH ROW EXECUTE PROCEDURE a_ins_place(); - -ALTER TABLE ONLY musicbrainz.place_meta - ADD CONSTRAINT place_meta_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.place(id) - ON DELETE CASCADE; - -ALTER TABLE ONLY musicbrainz.place_rating_raw - ADD CONSTRAINT place_rating_raw_fk_editor - FOREIGN KEY (editor) - REFERENCES musicbrainz.editor(id); - -ALTER TABLE ONLY musicbrainz.place_rating_raw - ADD CONSTRAINT place_rating_raw_fk_place - FOREIGN KEY (place) - REFERENCES musicbrainz.place(id); - --------------------------------------------------------------------------------- -SELECT '20210507-mbs-11652-artist-series-fks.sql'; - ------------------- --- constraints -- ------------------- - -ALTER TABLE series_type ADD CONSTRAINT allowed_series_entity_type - CHECK ( - entity_type IN ( - 'artist', - 'event', - 'recording', - 'release', - 'release_group', - 'work' - ) - ); - -COMMIT; diff --git a/mbdata/sql/updates/schema-change/27.mirror.sql b/mbdata/sql/updates/schema-change/27.mirror.sql deleted file mode 100644 index ca299f2..0000000 --- a/mbdata/sql/updates/schema-change/27.mirror.sql +++ /dev/null @@ -1,2040 +0,0 @@ --- Generated by CompileSchemaScripts.pl from: --- 20210406-mbs-11457.sql --- 20210419-mbs-11456.sql --- 20210526-a_upd_release_event.sql --- 20210606-mbs-11682.sql --- 20220207-mbs-12224-mirror.sql --- 20220218-mbs-12208.sql --- 20220302-mbs-12225.sql --- 20220314-mbs-12252.sql --- 20220314-mbs-12253.sql --- 20220314-mbs-12254.sql --- 20220314-mbs-12255.sql --- 20220328-mbs-12250-mirror.sql --- 20220322-mbs-12256-mirror.sql --- 20220324-mbs-12200.sql --- 20220408-immutable-link-tables.sql --- 20220408-mbs-12249.sql --- 20220412-mbs-12190.sql --- 20220426-mbs-12131.sql -\set ON_ERROR_STOP 1 -BEGIN; -SET search_path = musicbrainz, public; -SET LOCAL statement_timeout = 0; --------------------------------------------------------------------------------- -SELECT '20210406-mbs-11457.sql'; - - --- I) Replace s.ordering_attribute with the only possible value, 788 - -CREATE OR REPLACE VIEW event_series AS - SELECT entity0 AS event, - entity1 AS series, - lrs.id AS relationship, - link_order, - lrs.link, - COALESCE(text_value, '') AS text_value - FROM l_event_series lrs - JOIN series s ON s.id = lrs.entity1 - JOIN link l ON l.id = lrs.link - JOIN link_type lt ON (lt.id = l.link_type AND lt.gid = '707d947d-9563-328a-9a7d-0c5b9c3a9791') - LEFT OUTER JOIN link_attribute_text_value latv ON (latv.attribute_type = 788 AND latv.link = l.id) - ORDER BY series, link_order; - -CREATE OR REPLACE VIEW recording_series AS - SELECT entity0 AS recording, - entity1 AS series, - lrs.id AS relationship, - link_order, - lrs.link, - COALESCE(text_value, '') AS text_value - FROM l_recording_series lrs - JOIN series s ON s.id = lrs.entity1 - JOIN link l ON l.id = lrs.link - JOIN link_type lt ON (lt.id = l.link_type AND lt.gid = 'ea6f0698-6782-30d6-b16d-293081b66774') - LEFT OUTER JOIN link_attribute_text_value latv ON (latv.attribute_type = 788 AND latv.link = l.id) - ORDER BY series, link_order; - -CREATE OR REPLACE VIEW release_series AS - SELECT entity0 AS release, - entity1 AS series, - lrs.id AS relationship, - link_order, - lrs.link, - COALESCE(text_value, '') AS text_value - FROM l_release_series lrs - JOIN series s ON s.id = lrs.entity1 - JOIN link l ON l.id = lrs.link - JOIN link_type lt ON (lt.id = l.link_type AND lt.gid = '3fa29f01-8e13-3e49-9b0a-ad212aa2f81d') - LEFT OUTER JOIN link_attribute_text_value latv ON (latv.attribute_type = 788 AND latv.link = l.id) - ORDER BY series, link_order; - -CREATE OR REPLACE VIEW release_group_series AS - SELECT entity0 AS release_group, - entity1 AS series, - lrgs.id AS relationship, - link_order, - lrgs.link, - COALESCE(text_value, '') AS text_value - FROM l_release_group_series lrgs - JOIN series s ON s.id = lrgs.entity1 - JOIN link l ON l.id = lrgs.link - JOIN link_type lt ON (lt.id = l.link_type AND lt.gid = '01018437-91d8-36b9-bf89-3f885d53b5bd') - LEFT OUTER JOIN link_attribute_text_value latv ON (latv.attribute_type = 788 AND latv.link = l.id) - ORDER BY series, link_order; - -CREATE OR REPLACE VIEW work_series AS - SELECT entity1 AS work, - entity0 AS series, - lsw.id AS relationship, - link_order, - lsw.link, - COALESCE(text_value, '') AS text_value - FROM l_series_work lsw - JOIN series s ON s.id = lsw.entity0 - JOIN link l ON l.id = lsw.link - JOIN link_type lt ON (lt.id = l.link_type AND lt.gid = 'b0d44366-cdf0-3acb-bee6-0f65a77a6ef0') - LEFT OUTER JOIN link_attribute_text_value latv ON (latv.attribute_type = 788 AND latv.link = l.id) - ORDER BY series, link_order; - --- II) Drop the ordering_attribute column - -ALTER TABLE series DROP COLUMN ordering_attribute CASCADE; - --------------------------------------------------------------------------------- -SELECT '20210419-mbs-11456.sql'; - - --- Artist credit GID - --- Creating column -ALTER TABLE artist_credit ADD COLUMN gid uuid; - --- Generating GIDs -UPDATE artist_credit SET gid = - generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'artist_credit' || id); - --- Adding NOT NULL constraint -ALTER TABLE artist_credit ALTER COLUMN gid SET NOT NULL; - --- Creating index -CREATE UNIQUE INDEX artist_credit_idx_gid ON artist_credit (gid); - --- Artist credit GID redirect -CREATE TABLE artist_credit_gid_redirect ( -- replicate (verbose) - gid UUID NOT NULL, -- PK - new_id INTEGER NOT NULL, -- references artist_credit.id - created TIMESTAMP WITH TIME ZONE DEFAULT NOW() -); - -ALTER TABLE artist_credit_gid_redirect ADD CONSTRAINT artist_credit_gid_redirect_pkey PRIMARY KEY (gid); - -CREATE INDEX artist_credit_gid_redirect_idx_new_id ON artist_credit_gid_redirect (new_id); - --------------------------------------------------------------------------------- -SELECT '20210526-a_upd_release_event.sql'; - - -CREATE OR REPLACE FUNCTION a_upd_release_event() -RETURNS TRIGGER AS $$ -BEGIN - IF ( - NEW.release != OLD.release OR - NEW.date_year IS DISTINCT FROM OLD.date_year OR - NEW.date_month IS DISTINCT FROM OLD.date_month OR - NEW.date_day IS DISTINCT FROM OLD.date_day - ) THEN - PERFORM set_release_first_release_date(OLD.release); - IF NEW.release != OLD.release THEN - PERFORM set_release_first_release_date(NEW.release); - END IF; - - PERFORM set_release_group_first_release_date(release_group) - FROM release - WHERE release.id IN (NEW.release, OLD.release); - - PERFORM set_releases_recordings_first_release_dates(ARRAY[NEW.release, OLD.release]); - END IF; - - IF TG_TABLE_NAME = 'release_country' THEN - IF NEW.country != OLD.country THEN - INSERT INTO artist_release_pending_update VALUES (OLD.release); - END IF; - END IF; - - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - --------------------------------------------------------------------------------- -SELECT '20210606-mbs-11682.sql'; - - -CREATE OR REPLACE FUNCTION apply_artist_release_pending_updates() -RETURNS trigger AS $$ -DECLARE - release_ids INTEGER[]; - release_id INTEGER; -BEGIN - -- DO NOT modify any replicated tables in this function; it's used - -- by a trigger on mirrors. - WITH pending AS ( - DELETE FROM artist_release_pending_update - RETURNING release - ) - SELECT array_agg(DISTINCT release) - INTO release_ids - FROM pending; - - IF coalesce(array_length(release_ids, 1), 0) > 0 THEN - -- If the user hasn't generated `artist_release`, then we - -- shouldn't update or insert to it. MBS determines whether to - -- use this table based on it being non-empty, so a partial - -- table would manifest as partial data on the website and - -- webservice. - PERFORM 1 FROM artist_release LIMIT 1; - IF FOUND THEN - DELETE FROM artist_release WHERE release = any(release_ids); - - FOREACH release_id IN ARRAY release_ids LOOP - -- We handle each release ID separately because the - -- `get_artist_release_rows` query can be planned much - -- more efficiently that way. - INSERT INTO artist_release - SELECT * FROM get_artist_release_rows(release_id); - END LOOP; - END IF; - END IF; - - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION apply_artist_release_group_pending_updates() -RETURNS trigger AS $$ -DECLARE - release_group_ids INTEGER[]; - release_group_id INTEGER; -BEGIN - -- DO NOT modify any replicated tables in this function; it's used - -- by a trigger on mirrors. - WITH pending AS ( - DELETE FROM artist_release_group_pending_update - RETURNING release_group - ) - SELECT array_agg(DISTINCT release_group) - INTO release_group_ids - FROM pending; - - IF coalesce(array_length(release_group_ids, 1), 0) > 0 THEN - -- If the user hasn't generated `artist_release_group`, then we - -- shouldn't update or insert to it. MBS determines whether to - -- use this table based on it being non-empty, so a partial - -- table would manifest as partial data on the website and - -- webservice. - PERFORM 1 FROM artist_release_group LIMIT 1; - IF FOUND THEN - DELETE FROM artist_release_group WHERE release_group = any(release_group_ids); - - FOREACH release_group_id IN ARRAY release_group_ids LOOP - -- We handle each release group ID separately because - -- the `get_artist_release_group_rows` query can be - -- planned much more efficiently that way. - INSERT INTO artist_release_group - SELECT * FROM get_artist_release_group_rows(release_group_id); - END LOOP; - END IF; - END IF; - - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - --------------------------------------------------------------------------------- -SELECT '20220207-mbs-12224-mirror.sql'; - - -DELETE FROM area_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM area_tag_raw r - WHERE r.area = a.area AND r.tag = a.tag -); - -UPDATE area_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM area_tag_raw r - WHERE r.area = a.area AND r.tag = a.tag - GROUP BY r.area, r.tag -); - -DELETE FROM artist_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM artist_tag_raw r - WHERE r.artist = a.artist AND r.tag = a.tag -); - -UPDATE artist_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM artist_tag_raw r - WHERE r.artist = a.artist AND r.tag = a.tag - GROUP BY r.artist, r.tag -); - -DELETE FROM event_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM event_tag_raw r - WHERE r.event = a.event AND r.tag = a.tag -); - -UPDATE event_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM event_tag_raw r - WHERE r.event = a.event AND r.tag = a.tag - GROUP BY r.event, r.tag -); - -DELETE FROM instrument_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM instrument_tag_raw r - WHERE r.instrument = a.instrument AND r.tag = a.tag -); - -UPDATE instrument_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM instrument_tag_raw r - WHERE r.instrument = a.instrument AND r.tag = a.tag - GROUP BY r.instrument, r.tag -); - -DELETE FROM label_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM label_tag_raw r - WHERE r.label = a.label AND r.tag = a.tag -); - -UPDATE label_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM label_tag_raw r - WHERE r.label = a.label AND r.tag = a.tag - GROUP BY r.label, r.tag -); - -DELETE FROM place_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM place_tag_raw r - WHERE r.place = a.place AND r.tag = a.tag -); - -UPDATE place_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM place_tag_raw r - WHERE r.place = a.place AND r.tag = a.tag - GROUP BY r.place, r.tag -); - -DELETE FROM recording_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM recording_tag_raw r - WHERE r.recording = a.recording AND r.tag = a.tag -); - -UPDATE recording_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM recording_tag_raw r - WHERE r.recording = a.recording AND r.tag = a.tag - GROUP BY r.recording, r.tag -); - -DELETE FROM release_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM release_tag_raw r - WHERE r.release = a.release AND r.tag = a.tag -); - -UPDATE release_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM release_tag_raw r - WHERE r.release = a.release AND r.tag = a.tag - GROUP BY r.release, r.tag -); - -DELETE FROM release_group_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM release_group_tag_raw r - WHERE r.release_group = a.release_group AND r.tag = a.tag -); - -UPDATE release_group_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM release_group_tag_raw r - WHERE r.release_group = a.release_group AND r.tag = a.tag - GROUP BY r.release_group, r.tag -); - -DELETE FROM series_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM series_tag_raw r - WHERE r.series = a.series AND r.tag = a.tag -); - -UPDATE series_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM series_tag_raw r - WHERE r.series = a.series AND r.tag = a.tag - GROUP BY r.series, r.tag -); - -DELETE FROM work_tag a WHERE NOT EXISTS ( - SELECT 1 - FROM work_tag_raw r - WHERE r.work = a.work AND r.tag = a.tag -); - -UPDATE work_tag a SET count = ( - SELECT sum(CASE WHEN is_upvote THEN 1 ELSE -1 END) - FROM work_tag_raw r - WHERE r.work = a.work AND r.tag = a.tag - GROUP BY r.work, r.tag -); - -UPDATE tag t SET ref_count = ( - (SELECT count(*) FROM area_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM artist_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM event_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM instrument_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM label_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM place_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM recording_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM release_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM release_group_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM series_tag_raw r WHERE r.tag = t.id) + - (SELECT count(*) FROM work_tag_raw r WHERE r.tag = t.id) -); - --- Unused, non-replicated table that holds FKs to tag. -TRUNCATE tag_relation; - -DELETE FROM tag WHERE ref_count = 0; - -CREATE TYPE taggable_entity_type AS ENUM ( - 'area', - 'artist', - 'event', - 'instrument', - 'label', - 'place', - 'recording', - 'release', - 'release_group', - 'series', - 'work' -); - -CREATE OR REPLACE FUNCTION update_aggregate_tag_count(entity_type taggable_entity_type, entity_id INTEGER, tag_id INTEGER, count_change SMALLINT) -RETURNS VOID AS $$ -BEGIN - -- Insert-or-update the aggregate vote count for the given (entity_id, tag_id). - EXECUTE format( - $SQL$ - INSERT INTO %1$I AS agg (%2$I, tag, count) - VALUES ($1, $2, $3) - ON CONFLICT (%2$I, tag) DO UPDATE SET count = agg.count + $3 - $SQL$, - entity_type::TEXT || '_tag', - entity_type::TEXT - ) USING entity_id, tag_id, count_change; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION delete_unused_aggregate_tag(entity_type taggable_entity_type, entity_id INTEGER, tag_id INTEGER) -RETURNS VOID AS $$ -BEGIN - -- Delete the aggregate tag row for (entity_id, tag_id) if no raw tag pair - -- exists for the same. - -- - -- Note that an aggregate vote count of 0 doesn't imply there are no raw - -- tags; it's a sum of all the votes, so it can also mean that there's a - -- downvote for every upvote. - EXECUTE format( - $SQL$ - DELETE FROM %1$I - WHERE %2$I = $1 - AND tag = $2 - AND NOT EXISTS (SELECT 1 FROM %3$I WHERE %2$I = $1 AND tag = $2) - $SQL$, - entity_type::TEXT || '_tag', - entity_type::TEXT, - entity_type::TEXT || '_tag_raw' - ) USING entity_id, tag_id; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION update_tag_counts_for_raw_insert() -RETURNS trigger AS $$ -DECLARE - entity_type taggable_entity_type; - new_entity_id INTEGER; -BEGIN - entity_type := TG_ARGV[0]::taggable_entity_type; - EXECUTE format('SELECT ($1).%s', entity_type::TEXT) INTO new_entity_id USING NEW; - PERFORM update_aggregate_tag_count(entity_type, new_entity_id, NEW.tag, (CASE WHEN NEW.is_upvote THEN 1 ELSE -1 END)::SMALLINT); - UPDATE tag SET ref_count = ref_count + 1 WHERE id = NEW.tag; - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION update_tag_counts_for_raw_update() -RETURNS trigger AS $$ -DECLARE - entity_type taggable_entity_type; - new_entity_id INTEGER; - old_entity_id INTEGER; -BEGIN - entity_type := TG_ARGV[0]::taggable_entity_type; - EXECUTE format('SELECT ($1).%s', entity_type) INTO new_entity_id USING NEW; - EXECUTE format('SELECT ($1).%s', entity_type) INTO old_entity_id USING OLD; - IF (old_entity_id = new_entity_id AND OLD.tag = NEW.tag AND OLD.is_upvote != NEW.is_upvote) THEN - -- Case 1: only the vote changed. - PERFORM update_aggregate_tag_count(entity_type, old_entity_id, OLD.tag, (CASE WHEN OLD.is_upvote THEN -2 ELSE 2 END)::SMALLINT); - ELSIF (old_entity_id != new_entity_id OR OLD.tag != NEW.tag OR OLD.is_upvote != NEW.is_upvote) THEN - -- Case 2: the entity, tag, or vote changed. - PERFORM update_aggregate_tag_count(entity_type, old_entity_id, OLD.tag, (CASE WHEN OLD.is_upvote THEN -1 ELSE 1 END)::SMALLINT); - PERFORM update_aggregate_tag_count(entity_type, new_entity_id, NEW.tag, (CASE WHEN NEW.is_upvote THEN 1 ELSE -1 END)::SMALLINT); - PERFORM delete_unused_aggregate_tag(entity_type, old_entity_id, OLD.tag); - END IF; - IF OLD.tag != NEW.tag THEN - UPDATE tag SET ref_count = ref_count - 1 WHERE id = OLD.tag; - UPDATE tag SET ref_count = ref_count + 1 WHERE id = NEW.tag; - END IF; - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION update_tag_counts_for_raw_delete() -RETURNS trigger AS $$ -DECLARE - entity_type taggable_entity_type; - old_entity_id INTEGER; -BEGIN - entity_type := TG_ARGV[0]::taggable_entity_type; - EXECUTE format('SELECT ($1).%s', entity_type::TEXT) INTO old_entity_id USING OLD; - PERFORM update_aggregate_tag_count(entity_type, old_entity_id, OLD.tag, (CASE WHEN OLD.is_upvote THEN -1 ELSE 1 END)::SMALLINT); - PERFORM delete_unused_aggregate_tag(entity_type, old_entity_id, OLD.tag); - UPDATE tag SET ref_count = ref_count - 1 WHERE id = OLD.tag; - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - --------------------------------------------------------------------------------- -SELECT '20220218-mbs-12208.sql'; - - -CREATE OR REPLACE FUNCTION get_artist_release_group_rows( - release_group_id INTEGER -) RETURNS SETOF artist_release_group AS $$ -BEGIN - -- PostgreSQL 12 generates a vastly more efficient plan when only - -- one release group ID is passed. A condition like - -- `rg.id = any(...)` can be over 200x slower, even with only one - -- release group ID in the array. - RETURN QUERY EXECUTE $SQL$ - SELECT DISTINCT ON (a_rg.artist, rg.id) - a_rg.is_track_artist, - a_rg.artist, - -- Withdrawn releases were once official by definition - bool_and(r.status IS NOT NULL AND r.status != 1 AND r.status != 5), - rg.type::SMALLINT, - array_agg( - DISTINCT st.secondary_type ORDER BY st.secondary_type) - FILTER (WHERE st.secondary_type IS NOT NULL - )::SMALLINT[], - integer_date( - rgm.first_release_date_year, - rgm.first_release_date_month, - rgm.first_release_date_day - ), - left(rg.name, 1)::CHAR(1), - rg.id - FROM ( - SELECT FALSE AS is_track_artist, rgacn.artist, rg.id AS release_group - FROM release_group rg - JOIN artist_credit_name rgacn ON rgacn.artist_credit = rg.artist_credit - UNION ALL - SELECT TRUE AS is_track_artist, tacn.artist, r.release_group - FROM release r - JOIN medium m ON m.release = r.id - JOIN track t ON t.medium = m.id - JOIN artist_credit_name tacn ON tacn.artist_credit = t.artist_credit - ) a_rg - JOIN release_group rg ON rg.id = a_rg.release_group - LEFT JOIN release r ON r.release_group = rg.id - JOIN release_group_meta rgm ON rgm.id = rg.id - LEFT JOIN release_group_secondary_type_join st ON st.release_group = rg.id - $SQL$ || (CASE WHEN release_group_id IS NULL THEN '' ELSE 'WHERE rg.id = $1' END) || - $SQL$ - GROUP BY a_rg.is_track_artist, a_rg.artist, rgm.id, rg.id - ORDER BY a_rg.artist, rg.id, a_rg.is_track_artist - $SQL$ - USING release_group_id; -END; -$$ LANGUAGE plpgsql; - --- We update the table for any existing RGs containing withdrawn releases --- with this one-off script; the updated function will keep it up after this. -DO $$ -DECLARE - release_group_ids INTEGER[]; - release_group_id INTEGER; -BEGIN - SELECT array_agg(DISTINCT rg.id) - INTO release_group_ids - FROM release_group rg - JOIN release r ON rg.id = r.release_group - WHERE r.status = 5; -- Withdrawn - - IF coalesce(array_length(release_group_ids, 1), 0) > 0 THEN - -- If the user hasn't generated `artist_release_group`, then we - -- shouldn't update or insert to it. MBS determines whether to - -- use this table based on it being non-empty, so a partial - -- table would manifest as partial data on the website and - -- webservice. - PERFORM 1 FROM artist_release_group LIMIT 1; - IF FOUND THEN - DELETE FROM artist_release_group WHERE release_group = any(release_group_ids); - - FOREACH release_group_id IN ARRAY release_group_ids LOOP - -- We handle each release group ID separately because - -- the `get_artist_release_group_rows` query can be - -- planned much more efficiently that way. - INSERT INTO artist_release_group - SELECT * FROM get_artist_release_group_rows(release_group_id); - END LOOP; - END IF; - END IF; -END $$; - --------------------------------------------------------------------------------- -SELECT '20220302-mbs-12225.sql'; - - --- The internal comment had the word "slaves" changed to "mirrors." --- The function is otherwise unchanged. -CREATE OR REPLACE FUNCTION set_recordings_first_release_dates(recording_ids INTEGER[]) -RETURNS VOID AS $$ -BEGIN - -- DO NOT modify any replicated tables in this function; it's used - -- by a trigger on mirrors. - DELETE FROM recording_first_release_date - WHERE recording = ANY(recording_ids); - - INSERT INTO recording_first_release_date - SELECT * FROM get_recording_first_release_date_rows( - format('track.recording = any(%L)', recording_ids) - ); -END; -$$ LANGUAGE 'plpgsql' STRICT; - --- The internal comment had the word "slaves" changed to "mirrors." --- The function is otherwise unchanged. -CREATE OR REPLACE FUNCTION set_release_first_release_date(release_id INTEGER) -RETURNS VOID AS $$ -BEGIN - -- DO NOT modify any replicated tables in this function; it's used - -- by a trigger on mirrors. - DELETE FROM release_first_release_date - WHERE release = release_id; - - INSERT INTO release_first_release_date - SELECT * FROM get_release_first_release_date_rows( - format('release = %L', release_id) - ); - - INSERT INTO artist_release_pending_update VALUES (release_id); -END; -$$ LANGUAGE 'plpgsql' STRICT; - --------------------------------------------------------------------------------- -SELECT '20220314-mbs-12252.sql'; - - -CREATE TABLE edit_genre -( - edit INTEGER NOT NULL, -- PK, references edit.id - genre INTEGER NOT NULL -- PK, references genre.id CASCADE -); - -ALTER TABLE edit_genre ADD CONSTRAINT edit_genre_pkey PRIMARY KEY (edit, genre); - -CREATE INDEX edit_genre_idx ON edit_genre (genre); - --------------------------------------------------------------------------------- -SELECT '20220314-mbs-12253.sql'; - - -CREATE TABLE l_area_genre ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references area.id - entity1 INTEGER NOT NULL, -- references genre.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_artist_genre ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references artist.id - entity1 INTEGER NOT NULL, -- references genre.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_event_genre ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references event.id - entity1 INTEGER NOT NULL, -- references genre.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_genre_genre ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references genre.id - entity1 INTEGER NOT NULL, -- references genre.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_genre_instrument ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references genre.id - entity1 INTEGER NOT NULL, -- references instrument.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_genre_label ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references genre.id - entity1 INTEGER NOT NULL, -- references label.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_genre_place ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references genre.id - entity1 INTEGER NOT NULL, -- references place.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_genre_recording ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references genre.id - entity1 INTEGER NOT NULL, -- references recording.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_genre_release ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references genre.id - entity1 INTEGER NOT NULL, -- references release.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_genre_release_group ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references genre.id - entity1 INTEGER NOT NULL, -- references release_group.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_genre_series ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references genre.id - entity1 INTEGER NOT NULL, -- references series.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_genre_url ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references genre.id - entity1 INTEGER NOT NULL, -- references url.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_genre_work ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references genre.id - entity1 INTEGER NOT NULL, -- references work.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - - -ALTER TABLE l_area_genre ADD CONSTRAINT l_area_genre_pkey PRIMARY KEY (id); -ALTER TABLE l_artist_genre ADD CONSTRAINT l_artist_genre_pkey PRIMARY KEY (id); -ALTER TABLE l_event_genre ADD CONSTRAINT l_event_genre_pkey PRIMARY KEY (id); -ALTER TABLE l_genre_genre ADD CONSTRAINT l_genre_genre_pkey PRIMARY KEY (id); -ALTER TABLE l_genre_instrument ADD CONSTRAINT l_genre_instrument_pkey PRIMARY KEY (id); -ALTER TABLE l_genre_label ADD CONSTRAINT l_genre_label_pkey PRIMARY KEY (id); -ALTER TABLE l_genre_place ADD CONSTRAINT l_genre_place_pkey PRIMARY KEY (id); -ALTER TABLE l_genre_recording ADD CONSTRAINT l_genre_recording_pkey PRIMARY KEY (id); -ALTER TABLE l_genre_release ADD CONSTRAINT l_genre_release_pkey PRIMARY KEY (id); -ALTER TABLE l_genre_release_group ADD CONSTRAINT l_genre_release_group_pkey PRIMARY KEY (id); -ALTER TABLE l_genre_series ADD CONSTRAINT l_genre_series_pkey PRIMARY KEY (id); -ALTER TABLE l_genre_url ADD CONSTRAINT l_genre_url_pkey PRIMARY KEY (id); -ALTER TABLE l_genre_work ADD CONSTRAINT l_genre_work_pkey PRIMARY KEY (id); - -CREATE OR REPLACE FUNCTION delete_unused_url(ids INTEGER[]) -RETURNS VOID AS $$ -DECLARE - clear_up INTEGER[]; -BEGIN - SELECT ARRAY( - SELECT id FROM url url_row WHERE id = any(ids) - EXCEPT - SELECT url FROM edit_url JOIN edit ON (edit.id = edit_url.edit) WHERE edit.status = 1 - EXCEPT - SELECT entity1 FROM l_area_url - EXCEPT - SELECT entity1 FROM l_artist_url - EXCEPT - SELECT entity1 FROM l_event_url - EXCEPT - SELECT entity1 FROM l_genre_url - EXCEPT - SELECT entity1 FROM l_instrument_url - EXCEPT - SELECT entity1 FROM l_label_url - EXCEPT - SELECT entity1 FROM l_place_url - EXCEPT - SELECT entity1 FROM l_recording_url - EXCEPT - SELECT entity1 FROM l_release_url - EXCEPT - SELECT entity1 FROM l_release_group_url - EXCEPT - SELECT entity1 FROM l_series_url - EXCEPT - SELECT entity1 FROM l_url_url - EXCEPT - SELECT entity0 FROM l_url_url - EXCEPT - SELECT entity0 FROM l_url_work - ) INTO clear_up; - - DELETE FROM url_gid_redirect WHERE new_id = any(clear_up); - DELETE FROM url WHERE id = any(clear_up); -END; -$$ LANGUAGE 'plpgsql'; - - -CREATE UNIQUE INDEX l_area_genre_idx_uniq ON l_area_genre (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_artist_genre_idx_uniq ON l_artist_genre (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_event_genre_idx_uniq ON l_event_genre (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_genre_genre_idx_uniq ON l_genre_genre (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_genre_instrument_idx_uniq ON l_genre_instrument (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_genre_label_idx_uniq ON l_genre_label (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_genre_place_idx_uniq ON l_genre_place (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_genre_recording_idx_uniq ON l_genre_recording (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_genre_release_idx_uniq ON l_genre_release (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_genre_release_group_idx_uniq ON l_genre_release_group (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_genre_series_idx_uniq ON l_genre_series (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_genre_url_idx_uniq ON l_genre_url (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_genre_work_idx_uniq ON l_genre_work (entity0, entity1, link, link_order); - -CREATE INDEX l_area_genre_idx_entity1 ON l_area_genre (entity1); -CREATE INDEX l_artist_genre_idx_entity1 ON l_artist_genre (entity1); -CREATE INDEX l_event_genre_idx_entity1 ON l_event_genre (entity1); -CREATE INDEX l_genre_genre_idx_entity1 ON l_genre_genre (entity1); -CREATE INDEX l_genre_instrument_idx_entity1 ON l_genre_instrument (entity1); -CREATE INDEX l_genre_label_idx_entity1 ON l_genre_label (entity1); -CREATE INDEX l_genre_place_idx_entity1 ON l_genre_place (entity1); -CREATE INDEX l_genre_recording_idx_entity1 ON l_genre_recording (entity1); -CREATE INDEX l_genre_release_idx_entity1 ON l_genre_release (entity1); -CREATE INDEX l_genre_release_group_idx_entity1 ON l_genre_release_group (entity1); -CREATE INDEX l_genre_series_idx_entity1 ON l_genre_series (entity1); -CREATE INDEX l_genre_url_idx_entity1 ON l_genre_url (entity1); -CREATE INDEX l_genre_work_idx_entity1 ON l_genre_work (entity1); - - -CREATE TABLE documentation.l_area_genre_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_area_genre.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_artist_genre_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_artist_genre.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_event_genre_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_event_genre.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_genre_genre_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_genre_genre.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_genre_instrument_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_genre_instrument.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_genre_label_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_genre_label.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_genre_place_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_genre_place.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_genre_recording_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_genre_recording.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_genre_release_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_genre_release.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_genre_release_group_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_genre_release_group.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_genre_series_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_genre_series.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_genre_url_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_genre_url.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_genre_work_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_genre_work.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - - -ALTER TABLE documentation.l_area_genre_example ADD CONSTRAINT l_area_genre_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_artist_genre_example ADD CONSTRAINT l_artist_genre_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_event_genre_example ADD CONSTRAINT l_event_genre_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_genre_genre_example ADD CONSTRAINT l_genre_genre_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_genre_instrument_example ADD CONSTRAINT l_genre_instrument_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_genre_label_example ADD CONSTRAINT l_genre_label_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_genre_place_example ADD CONSTRAINT l_genre_place_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_genre_recording_example ADD CONSTRAINT l_genre_recording_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_genre_release_example ADD CONSTRAINT l_genre_release_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_genre_release_group_example ADD CONSTRAINT l_genre_release_group_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_genre_series_example ADD CONSTRAINT l_genre_series_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_genre_url_example ADD CONSTRAINT l_genre_url_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_genre_work_example ADD CONSTRAINT l_genre_work_example_pkey PRIMARY KEY (id); - --------------------------------------------------------------------------------- -SELECT '20220314-mbs-12254.sql'; - - -CREATE TABLE genre_annotation ( -- replicate (verbose) - genre INTEGER NOT NULL, -- PK, references genre.id - annotation INTEGER NOT NULL -- PK, references annotation.id -); - -ALTER TABLE genre_annotation ADD CONSTRAINT genre_annotation_pkey PRIMARY KEY (genre, annotation); - --------------------------------------------------------------------------------- -SELECT '20220314-mbs-12255.sql'; - - -CREATE TABLE genre_alias_type ( -- replicate - id SERIAL, -- PK, - name TEXT NOT NULL, - parent INTEGER, -- references genre_alias_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -ALTER TABLE genre_alias_type ADD CONSTRAINT genre_alias_type_pkey PRIMARY KEY (id); - -CREATE UNIQUE INDEX genre_alias_type_idx_gid ON genre_alias_type (gid); - --- generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'genre_type' || id); -INSERT INTO genre_alias_type (id, gid, name) - VALUES (1, '61e89fea-acce-3908-a590-d999dc627ac9', 'Genre name'), - (2, '5d81fc72-598a-3a9d-a85a-a471c6ba84dc', 'Search hint'); - --- We drop and recreate the table to standardise it --- rather than adding a ton of rows to it out of the standard order. --- This is empty in production and mirrors but might not be on standalone -CREATE TEMPORARY TABLE tmp_genre_alias - ON COMMIT DROP - AS - SELECT * FROM genre_alias; - -DROP TABLE genre_alias; - -CREATE TABLE genre_alias ( -- replicate (verbose) - id SERIAL, --PK - genre INTEGER NOT NULL, -- references genre.id - name VARCHAR NOT NULL, - locale TEXT, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - type INTEGER, -- references genre_alias_type.id - sort_name VARCHAR NOT NULL, - begin_date_year SMALLINT, - begin_date_month SMALLINT, - begin_date_day SMALLINT, - end_date_year SMALLINT, - end_date_month SMALLINT, - end_date_day SMALLINT, - primary_for_locale BOOLEAN NOT NULL DEFAULT false, - ended BOOLEAN NOT NULL DEFAULT FALSE - CHECK ( - ( - -- If any end date fields are not null, then ended must be true - (end_date_year IS NOT NULL OR - end_date_month IS NOT NULL OR - end_date_day IS NOT NULL) AND - ended = TRUE - ) OR ( - -- Otherwise, all end date fields must be null - (end_date_year IS NULL AND - end_date_month IS NULL AND - end_date_day IS NULL) - ) - ), - CONSTRAINT primary_check CHECK ((locale IS NULL AND primary_for_locale IS FALSE) OR (locale IS NOT NULL)), - CONSTRAINT search_hints_are_empty - CHECK ( - (type <> 2) OR ( - type = 2 AND sort_name = name AND - begin_date_year IS NULL AND begin_date_month IS NULL AND begin_date_day IS NULL AND - end_date_year IS NULL AND end_date_month IS NULL AND end_date_day IS NULL AND - primary_for_locale IS FALSE AND locale IS NULL - ) - ) -); - -ALTER TABLE genre_alias ADD CONSTRAINT genre_alias_pkey PRIMARY KEY (id); - -CREATE INDEX genre_alias_idx_genre ON genre_alias (genre); -CREATE UNIQUE INDEX genre_alias_idx_primary ON genre_alias (genre, locale) WHERE primary_for_locale = TRUE AND locale IS NOT NULL; - -INSERT INTO genre_alias (id, genre, name, locale, edits_pending, last_updated, type, sort_name) -SELECT id, genre, name, locale, edits_pending, last_updated, 1, name -- sortname = name, type = genre name -FROM tmp_genre_alias; - --------------------------------------------------------------------------------- -SELECT '20220328-mbs-12250-mirror.sql'; - - -CREATE SCHEMA IF NOT EXISTS dbmirror2; - --------------------------------------------------------------------------------- -SELECT '20220322-mbs-12256-mirror.sql'; - - -UPDATE artist_meta - SET rating = agg.rating - FROM ( - SELECT artist, - trunc((sum(rating)::REAL / - count(rating)::REAL) + - 0.5::REAL)::SMALLINT AS rating - FROM artist_rating_raw - GROUP BY artist - ) agg - WHERE id = agg.artist; - -UPDATE event_meta - SET rating = agg.rating - FROM ( - SELECT event, - trunc((sum(rating)::REAL / - count(rating)::REAL) + - 0.5::REAL)::SMALLINT AS rating - FROM event_rating_raw - GROUP BY event - ) agg - WHERE id = agg.event; - -UPDATE label_meta - SET rating = agg.rating - FROM ( - SELECT label, - trunc((sum(rating)::REAL / - count(rating)::REAL) + - 0.5::REAL)::SMALLINT AS rating - FROM label_rating_raw - GROUP BY label - ) agg - WHERE id = agg.label; - -UPDATE place_meta - SET rating = agg.rating - FROM ( - SELECT place, - trunc((sum(rating)::REAL / - count(rating)::REAL) + - 0.5::REAL)::SMALLINT AS rating - FROM place_rating_raw - GROUP BY place - ) agg - WHERE id = agg.place; - -UPDATE recording_meta - SET rating = agg.rating - FROM ( - SELECT recording, - trunc((sum(rating)::REAL / - count(rating)::REAL) + - 0.5::REAL)::SMALLINT AS rating - FROM recording_rating_raw - GROUP BY recording - ) agg - WHERE id = agg.recording; - -UPDATE release_group_meta - SET rating = agg.rating - FROM ( - SELECT release_group, - trunc((sum(rating)::REAL / - count(rating)::REAL) + - 0.5::REAL)::SMALLINT AS rating - FROM release_group_rating_raw - GROUP BY release_group - ) agg - WHERE id = agg.release_group; - -UPDATE work_meta - SET rating = agg.rating - FROM ( - SELECT work, - trunc((sum(rating)::REAL / - count(rating)::REAL) + - 0.5::REAL)::SMALLINT AS rating - FROM work_rating_raw - GROUP BY work - ) agg - WHERE id = agg.work; - -CREATE TYPE ratable_entity_type AS ENUM ( - 'artist', - 'event', - 'label', - 'place', - 'recording', - 'release_group', - 'work' -); - -CREATE OR REPLACE FUNCTION update_aggregate_rating(entity_type ratable_entity_type, entity_id INTEGER) -RETURNS VOID AS $$ -BEGIN - -- update the aggregate rating for the given entity_id. - EXECUTE format( - $SQL$ - UPDATE %2$I - SET rating = agg.rating, - rating_count = nullif(agg.rating_count, 0) - FROM ( - SELECT count(rating)::INTEGER AS rating_count, - -- trunc(x + 0.5) is used because round() on REAL values - -- rounds to the nearest even number. - trunc((sum(rating)::REAL / - count(rating)::REAL) + - 0.5::REAL)::SMALLINT AS rating - FROM %3$I - WHERE %1$I = $1 - ) agg - WHERE id = $1 - $SQL$, - entity_type::TEXT, - entity_type::TEXT || '_meta', - entity_type::TEXT || '_rating_raw' - ) USING entity_id; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION update_aggregate_rating_for_raw_insert() -RETURNS trigger AS $$ -DECLARE - entity_type ratable_entity_type; - new_entity_id INTEGER; -BEGIN - entity_type := TG_ARGV[0]::ratable_entity_type; - EXECUTE format('SELECT ($1).%s', entity_type::TEXT) INTO new_entity_id USING NEW; - PERFORM update_aggregate_rating(entity_type, new_entity_id); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION update_aggregate_rating_for_raw_update() -RETURNS trigger AS $$ -DECLARE - entity_type ratable_entity_type; - new_entity_id INTEGER; - old_entity_id INTEGER; -BEGIN - entity_type := TG_ARGV[0]::ratable_entity_type; - EXECUTE format('SELECT ($1).%s', entity_type) INTO new_entity_id USING NEW; - EXECUTE format('SELECT ($1).%s', entity_type) INTO old_entity_id USING OLD; - IF (old_entity_id = new_entity_id AND OLD.rating != NEW.rating) THEN - -- Case 1: only the rating changed. - PERFORM update_aggregate_rating(entity_type, old_entity_id); - ELSIF (old_entity_id != new_entity_id OR OLD.rating != NEW.rating) THEN - -- Case 2: the entity or rating changed. - PERFORM update_aggregate_rating(entity_type, old_entity_id); - PERFORM update_aggregate_rating(entity_type, new_entity_id); - END IF; - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION update_aggregate_rating_for_raw_delete() -RETURNS trigger AS $$ -DECLARE - entity_type ratable_entity_type; - old_entity_id INTEGER; -BEGIN - entity_type := TG_ARGV[0]::ratable_entity_type; - EXECUTE format('SELECT ($1).%s', entity_type::TEXT) INTO old_entity_id USING OLD; - PERFORM update_aggregate_rating(entity_type, old_entity_id); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - --------------------------------------------------------------------------------- -SELECT '20220324-mbs-12200.sql'; - - --- Redefined to remove `INSERT INTO release_coverart (id) VALUES (NEW.id);`. -CREATE OR REPLACE FUNCTION a_ins_release() RETURNS trigger AS $$ -BEGIN - -- increment ref_count of the name - PERFORM inc_ref_count('artist_credit', NEW.artist_credit, 1); - -- increment release_count of the parent release group - UPDATE release_group_meta SET release_count = release_count + 1 WHERE id = NEW.release_group; - -- add new release_meta - INSERT INTO release_meta (id) VALUES (NEW.id); - INSERT INTO artist_release_pending_update VALUES (NEW.id); - INSERT INTO artist_release_group_pending_update VALUES (NEW.release_group); - RETURN NULL; -END; -$$ LANGUAGE 'plpgsql'; - -DROP TABLE release_coverart; - -ALTER TABLE release_meta DROP COLUMN amazon_store; - --------------------------------------------------------------------------------- -SELECT '20220408-immutable-link-tables.sql'; - - -CREATE OR REPLACE FUNCTION deny_deprecated_links() -RETURNS trigger AS $$ -BEGIN - IF (SELECT is_deprecated FROM link_type WHERE id = NEW.link_type) - THEN - RAISE EXCEPTION 'Attempt to create a relationship with a deprecated type'; - END IF; - RETURN NEW; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION b_upd_link() RETURNS trigger AS $$ -BEGIN - -- Like artist credits, links are shared across many entities - -- (relationships) and so are immutable: they can only be inserted - -- or deleted. - -- - -- This helps ensure the data integrity of relationships and other - -- materialized tables that rely on their immutability, like - -- area_containment. - RAISE EXCEPTION 'link rows are immutable'; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION b_upd_link_attribute() RETURNS trigger AS $$ -BEGIN - -- Refer to b_upd_link. - RAISE EXCEPTION 'link_attribute rows are immutable'; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION b_upd_link_attribute_credit() RETURNS trigger AS $$ -BEGIN - -- Refer to b_upd_link. - RAISE EXCEPTION 'link_attribute_credit rows are immutable'; -END; -$$ LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION b_upd_link_attribute_text_value() RETURNS trigger AS $$ -BEGIN - -- Refer to b_upd_link. - RAISE EXCEPTION 'link_attribute_text_value rows are immutable'; -END; -$$ LANGUAGE 'plpgsql'; - --------------------------------------------------------------------------------- -SELECT '20220408-mbs-12249.sql'; - - -CREATE TABLE area_containment ( - descendant INTEGER NOT NULL, -- PK, references area.id - parent INTEGER NOT NULL, -- PK, references area.id - depth SMALLINT NOT NULL -); - -CREATE OR REPLACE FUNCTION a_ins_l_area_area_mirror() RETURNS trigger AS $$ -DECLARE - part_of_area_link_type_id CONSTANT SMALLINT := 356; -BEGIN - -- DO NOT modify any replicated tables in this function; it's used - -- by a trigger on mirrors. - IF (SELECT link_type FROM link WHERE id = NEW.link) = part_of_area_link_type_id THEN - PERFORM update_area_containment_mirror(ARRAY[NEW.entity0], ARRAY[NEW.entity1]); - END IF; - RETURN NULL; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE FUNCTION a_upd_l_area_area_mirror() RETURNS trigger AS $$ -DECLARE - part_of_area_link_type_id CONSTANT SMALLINT := 356; - old_lt_id INTEGER; - new_lt_id INTEGER; -BEGIN - -- DO NOT modify any replicated tables in this function; it's used - -- by a trigger on mirrors. - SELECT link_type INTO old_lt_id FROM link WHERE id = OLD.link; - SELECT link_type INTO new_lt_id FROM link WHERE id = NEW.link; - IF ( - ( - old_lt_id = part_of_area_link_type_id AND - new_lt_id = part_of_area_link_type_id AND - (OLD.entity0 != NEW.entity0 OR OLD.entity1 != NEW.entity1) - ) OR - (old_lt_id = part_of_area_link_type_id) != (new_lt_id = part_of_area_link_type_id) - ) THEN - PERFORM update_area_containment_mirror(ARRAY[OLD.entity0, NEW.entity0], ARRAY[OLD.entity1, NEW.entity1]); - END IF; - RETURN NULL; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE FUNCTION a_del_l_area_area_mirror() RETURNS trigger AS $$ -DECLARE - part_of_area_link_type_id CONSTANT SMALLINT := 356; -BEGIN - -- DO NOT modify any replicated tables in this function; it's used - -- by a trigger on mirrors. - IF (SELECT link_type FROM link WHERE id = OLD.link) = part_of_area_link_type_id THEN - PERFORM update_area_containment_mirror(ARRAY[OLD.entity0], ARRAY[OLD.entity1]); - END IF; - RETURN NULL; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE FUNCTION get_area_parent_hierarchy_rows( - descendant_area_ids INTEGER[] -) RETURNS SETOF area_containment AS $$ -DECLARE - part_of_area_link_type_id CONSTANT SMALLINT := 356; -BEGIN - RETURN QUERY EXECUTE $SQL$ - WITH RECURSIVE area_parent_hierarchy(descendant, parent, path, cycle) AS ( - SELECT entity1, entity0, ARRAY[ROW(entity1, entity0)], FALSE - FROM l_area_area laa - JOIN link ON laa.link = link.id - WHERE link.link_type = $1 - $SQL$ || (CASE WHEN descendant_area_ids IS NULL THEN '' ELSE 'AND entity1 = any($2)' END) || - $SQL$ - UNION ALL - SELECT descendant, entity0, path || ROW(descendant, entity0), ROW(descendant, entity0) = any(path) - FROM l_area_area laa - JOIN link ON laa.link = link.id - JOIN area_parent_hierarchy ON area_parent_hierarchy.parent = laa.entity1 - WHERE link.link_type = $1 - AND descendant != entity0 - AND NOT cycle - ) - SELECT descendant, parent, array_length(path, 1)::SMALLINT - FROM area_parent_hierarchy - $SQL$ - USING part_of_area_link_type_id, descendant_area_ids; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE FUNCTION get_area_descendant_hierarchy_rows( - parent_area_ids INTEGER[] -) RETURNS SETOF area_containment AS $$ -DECLARE - part_of_area_link_type_id CONSTANT SMALLINT := 356; -BEGIN - RETURN QUERY EXECUTE $SQL$ - WITH RECURSIVE area_descendant_hierarchy(descendant, parent, path, cycle) AS ( - SELECT entity1, entity0, ARRAY[ROW(entity1, entity0)], FALSE - FROM l_area_area laa - JOIN link ON laa.link = link.id - WHERE link.link_type = $1 - $SQL$ || (CASE WHEN parent_area_ids IS NULL THEN '' ELSE 'AND entity0 = any($2)' END) || - $SQL$ - UNION ALL - SELECT entity1, parent, path || ROW(entity1, parent), ROW(entity1, parent) = any(path) - FROM l_area_area laa - JOIN link ON laa.link = link.id - JOIN area_descendant_hierarchy ON area_descendant_hierarchy.descendant = laa.entity0 - WHERE link.link_type = $1 - AND parent != entity1 - AND NOT cycle - ) - SELECT descendant, parent, array_length(path, 1)::SMALLINT - FROM area_descendant_hierarchy - $SQL$ - USING part_of_area_link_type_id, parent_area_ids; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE FUNCTION update_area_containment_mirror( - parent_ids INTEGER[], -- entity0 of area-area "part of" - descendant_ids INTEGER[] -- entity1 -) RETURNS VOID AS $$ -DECLARE - part_of_area_link_type_id CONSTANT SMALLINT := 356; - descendant_ids_to_update INTEGER[]; - parent_ids_to_update INTEGER[]; -BEGIN - -- DO NOT modify any replicated tables in this function; it's used - -- by a trigger on mirrors. - - SELECT array_agg(descendant) - INTO descendant_ids_to_update - FROM area_containment - WHERE parent = any(parent_ids); - - SELECT array_agg(parent) - INTO parent_ids_to_update - FROM area_containment - WHERE descendant = any(descendant_ids); - - -- For INSERTS/UPDATES, include the new IDs that aren't present in - -- area_containment yet. - descendant_ids_to_update := descendant_ids_to_update || descendant_ids; - parent_ids_to_update := parent_ids_to_update || parent_ids; - - DELETE FROM area_containment - WHERE descendant = any(descendant_ids_to_update); - - DELETE FROM area_containment - WHERE parent = any(parent_ids_to_update); - - -- Update the parents of all descendants of parent_ids. - -- Update the descendants of all parents of descendant_ids. - - INSERT INTO area_containment - SELECT DISTINCT ON (descendant, parent) - descendant, parent, depth - FROM ( - SELECT * FROM get_area_parent_hierarchy_rows(descendant_ids_to_update) - UNION ALL - SELECT * FROM get_area_descendant_hierarchy_rows(parent_ids_to_update) - ) area_hierarchy - ORDER BY descendant, parent, depth; -END; -$$ LANGUAGE plpgsql; - --- Note: when passing NULL, it doesn't matter whether we use --- get_area_parent_hierarchy_rows vs. get_area_descendant_hierarchy_rows --- to build the entire table. -INSERT INTO area_containment -SELECT DISTINCT ON (descendant, parent) - descendant, - parent, - depth - FROM get_area_parent_hierarchy_rows(NULL) -ORDER BY descendant, parent, depth; - -ALTER TABLE area_containment ADD CONSTRAINT area_containment_pkey PRIMARY KEY (descendant, parent); - -CREATE INDEX area_containment_idx_parent ON area_containment (parent); - --------------------------------------------------------------------------------- -SELECT '20220412-mbs-12190.sql'; - - --- Tables - -CREATE TABLE edit_mood -( - edit INTEGER NOT NULL, -- PK, references edit.id - mood INTEGER NOT NULL -- PK, references mood.id CASCADE -); - -CREATE TABLE l_area_mood ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references area.id - entity1 INTEGER NOT NULL, -- references mood.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_artist_mood ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references artist.id - entity1 INTEGER NOT NULL, -- references mood.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_event_mood ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references event.id - entity1 INTEGER NOT NULL, -- references mood.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_genre_mood ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references genre.id - entity1 INTEGER NOT NULL, -- references mood.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_instrument_mood ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references instrument.id - entity1 INTEGER NOT NULL, -- references mood.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_label_mood ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references label.id - entity1 INTEGER NOT NULL, -- references mood.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_mood_mood ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references mood.id - entity1 INTEGER NOT NULL, -- references mood.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_mood_place ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references mood.id - entity1 INTEGER NOT NULL, -- references place.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_mood_recording ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references mood.id - entity1 INTEGER NOT NULL, -- references recording.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_mood_release ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references mood.id - entity1 INTEGER NOT NULL, -- references release.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_mood_release_group ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references mood.id - entity1 INTEGER NOT NULL, -- references release_group.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_mood_series ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references mood.id - entity1 INTEGER NOT NULL, -- references series.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_mood_url ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references mood.id - entity1 INTEGER NOT NULL, -- references url.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE l_mood_work ( -- replicate - id SERIAL, - link INTEGER NOT NULL, -- references link.id - entity0 INTEGER NOT NULL, -- references mood.id - entity1 INTEGER NOT NULL, -- references work.id - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - link_order INTEGER NOT NULL DEFAULT 0 CHECK (link_order >= 0), - entity0_credit TEXT NOT NULL DEFAULT '', - entity1_credit TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE mood ( -- replicate (verbose) - id SERIAL, -- PK - gid UUID NOT NULL, - name VARCHAR NOT NULL, - comment VARCHAR(255) NOT NULL DEFAULT '', - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >=0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW() -); - -CREATE TABLE mood_alias_type ( -- replicate - id SERIAL, -- PK, - name TEXT NOT NULL, - parent INTEGER, -- references mood_alias_type.id - child_order INTEGER NOT NULL DEFAULT 0, - description TEXT, - gid uuid NOT NULL -); - -CREATE TABLE mood_alias ( -- replicate (verbose) - id SERIAL, --PK - mood INTEGER NOT NULL, -- references mood.id - name VARCHAR NOT NULL, - locale TEXT, - edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0), - last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(), - type INTEGER, -- references mood_alias_type.id - sort_name VARCHAR NOT NULL, - begin_date_year SMALLINT, - begin_date_month SMALLINT, - begin_date_day SMALLINT, - end_date_year SMALLINT, - end_date_month SMALLINT, - end_date_day SMALLINT, - primary_for_locale BOOLEAN NOT NULL DEFAULT false, - ended BOOLEAN NOT NULL DEFAULT FALSE - CHECK ( - ( - -- If any end date fields are not null, then ended must be true - (end_date_year IS NOT NULL OR - end_date_month IS NOT NULL OR - end_date_day IS NOT NULL) AND - ended = TRUE - ) OR ( - -- Otherwise, all end date fields must be null - (end_date_year IS NULL AND - end_date_month IS NULL AND - end_date_day IS NULL) - ) - ), - CONSTRAINT primary_check CHECK ((locale IS NULL AND primary_for_locale IS FALSE) OR (locale IS NOT NULL)), - CONSTRAINT search_hints_are_empty - CHECK ( - (type <> 2) OR ( - type = 2 AND sort_name = name AND - begin_date_year IS NULL AND begin_date_month IS NULL AND begin_date_day IS NULL AND - end_date_year IS NULL AND end_date_month IS NULL AND end_date_day IS NULL AND - primary_for_locale IS FALSE AND locale IS NULL - ) - ) -); - -CREATE TABLE mood_annotation ( -- replicate (verbose) - mood INTEGER NOT NULL, -- PK, references mood.id - annotation INTEGER NOT NULL -- PK, references annotation.id -); - - --- Indexes - -CREATE INDEX edit_mood_idx ON edit_mood (mood); - -CREATE UNIQUE INDEX l_area_mood_idx_uniq ON l_area_mood (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_artist_mood_idx_uniq ON l_artist_mood (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_event_mood_idx_uniq ON l_event_mood (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_genre_mood_idx_uniq ON l_genre_mood (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_instrument_mood_idx_uniq ON l_instrument_mood (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_label_mood_idx_uniq ON l_label_mood (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_mood_mood_idx_uniq ON l_mood_mood (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_mood_place_idx_uniq ON l_mood_place (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_mood_recording_idx_uniq ON l_mood_recording (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_mood_release_idx_uniq ON l_mood_release (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_mood_release_group_idx_uniq ON l_mood_release_group (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_mood_series_idx_uniq ON l_mood_series (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_mood_url_idx_uniq ON l_mood_url (entity0, entity1, link, link_order); -CREATE UNIQUE INDEX l_mood_work_idx_uniq ON l_mood_work (entity0, entity1, link, link_order); - -CREATE INDEX l_area_mood_idx_entity1 ON l_area_mood (entity1); -CREATE INDEX l_artist_mood_idx_entity1 ON l_artist_mood (entity1); -CREATE INDEX l_event_mood_idx_entity1 ON l_event_mood (entity1); -CREATE INDEX l_genre_mood_idx_entity1 ON l_genre_mood (entity1); -CREATE INDEX l_instrument_mood_idx_entity1 ON l_instrument_mood (entity1); -CREATE INDEX l_label_mood_idx_entity1 ON l_label_mood (entity1); -CREATE INDEX l_mood_mood_idx_entity1 ON l_mood_mood (entity1); -CREATE INDEX l_mood_place_idx_entity1 ON l_mood_place (entity1); -CREATE INDEX l_mood_recording_idx_entity1 ON l_mood_recording (entity1); -CREATE INDEX l_mood_release_idx_entity1 ON l_mood_release (entity1); -CREATE INDEX l_mood_release_group_idx_entity1 ON l_mood_release_group (entity1); -CREATE INDEX l_mood_series_idx_entity1 ON l_mood_series (entity1); -CREATE INDEX l_mood_url_idx_entity1 ON l_mood_url (entity1); -CREATE INDEX l_mood_work_idx_entity1 ON l_mood_work (entity1); - -CREATE UNIQUE INDEX mood_idx_gid ON mood (gid); -CREATE UNIQUE INDEX mood_idx_name ON mood (LOWER(name)); - -CREATE INDEX mood_alias_idx_mood ON mood_alias (mood); -CREATE UNIQUE INDEX mood_alias_idx_primary ON mood_alias (mood, locale) WHERE primary_for_locale = TRUE AND locale IS NOT NULL; - -CREATE UNIQUE INDEX mood_alias_type_idx_gid ON mood_alias_type (gid); - --- generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'mood_type' || id); -INSERT INTO mood_alias_type (id, gid, name) - VALUES (1, '4df5b403-3059-36f8-a96f-cf04313dc007', 'Mood name'), - (2, 'ccd867f1-81ba-3520-89a5-0b0d7a5f6f74', 'Search hint'); - - --- PKs - -ALTER TABLE edit_mood ADD CONSTRAINT edit_mood_pkey PRIMARY KEY (edit, mood); -ALTER TABLE l_area_mood ADD CONSTRAINT l_area_mood_pkey PRIMARY KEY (id); -ALTER TABLE l_artist_mood ADD CONSTRAINT l_artist_mood_pkey PRIMARY KEY (id); -ALTER TABLE l_event_mood ADD CONSTRAINT l_event_mood_pkey PRIMARY KEY (id); -ALTER TABLE l_genre_mood ADD CONSTRAINT l_genre_mood_pkey PRIMARY KEY (id); -ALTER TABLE l_instrument_mood ADD CONSTRAINT l_instrument_mood_pkey PRIMARY KEY (id); -ALTER TABLE l_label_mood ADD CONSTRAINT l_label_mood_pkey PRIMARY KEY (id); -ALTER TABLE l_mood_mood ADD CONSTRAINT l_mood_mood_pkey PRIMARY KEY (id); -ALTER TABLE l_mood_place ADD CONSTRAINT l_mood_place_pkey PRIMARY KEY (id); -ALTER TABLE l_mood_recording ADD CONSTRAINT l_mood_recording_pkey PRIMARY KEY (id); -ALTER TABLE l_mood_release ADD CONSTRAINT l_mood_release_pkey PRIMARY KEY (id); -ALTER TABLE l_mood_release_group ADD CONSTRAINT l_mood_release_group_pkey PRIMARY KEY (id); -ALTER TABLE l_mood_series ADD CONSTRAINT l_mood_series_pkey PRIMARY KEY (id); -ALTER TABLE l_mood_url ADD CONSTRAINT l_mood_url_pkey PRIMARY KEY (id); -ALTER TABLE l_mood_work ADD CONSTRAINT l_mood_work_pkey PRIMARY KEY (id); -ALTER TABLE mood ADD CONSTRAINT mood_pkey PRIMARY KEY (id); -ALTER TABLE mood_alias ADD CONSTRAINT mood_alias_pkey PRIMARY KEY (id); -ALTER TABLE mood_alias_type ADD CONSTRAINT mood_alias_type_pkey PRIMARY KEY (id); -ALTER TABLE mood_annotation ADD CONSTRAINT mood_annotation_pkey PRIMARY KEY (mood, annotation); - - --- Functions - -CREATE OR REPLACE FUNCTION delete_unused_url(ids INTEGER[]) -RETURNS VOID AS $$ -DECLARE - clear_up INTEGER[]; -BEGIN - SELECT ARRAY( - SELECT id FROM url url_row WHERE id = any(ids) - EXCEPT - SELECT url FROM edit_url JOIN edit ON (edit.id = edit_url.edit) WHERE edit.status = 1 - EXCEPT - SELECT entity1 FROM l_area_url - EXCEPT - SELECT entity1 FROM l_artist_url - EXCEPT - SELECT entity1 FROM l_event_url - EXCEPT - SELECT entity1 FROM l_genre_url - EXCEPT - SELECT entity1 FROM l_instrument_url - EXCEPT - SELECT entity1 FROM l_label_url - EXCEPT - SELECT entity1 FROM l_mood_url - EXCEPT - SELECT entity1 FROM l_place_url - EXCEPT - SELECT entity1 FROM l_recording_url - EXCEPT - SELECT entity1 FROM l_release_url - EXCEPT - SELECT entity1 FROM l_release_group_url - EXCEPT - SELECT entity1 FROM l_series_url - EXCEPT - SELECT entity1 FROM l_url_url - EXCEPT - SELECT entity0 FROM l_url_url - EXCEPT - SELECT entity0 FROM l_url_work - ) INTO clear_up; - - DELETE FROM url_gid_redirect WHERE new_id = any(clear_up); - DELETE FROM url WHERE id = any(clear_up); -END; -$$ LANGUAGE 'plpgsql'; - - --- Examples - -CREATE TABLE documentation.l_area_mood_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_area_mood.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_artist_mood_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_artist_mood.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_event_mood_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_event_mood.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_genre_mood_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_genre_mood.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_instrument_mood_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_instrument_mood.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_label_mood_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_label_mood.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_mood_mood_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_mood_mood.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_mood_place_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_mood_place.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_mood_recording_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_mood_recording.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_mood_release_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_mood_release.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_mood_release_group_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_mood_release_group.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_mood_series_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_mood_series.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_mood_url_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_mood_url.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -CREATE TABLE documentation.l_mood_work_example ( -- replicate (verbose) - id INTEGER NOT NULL, -- PK, references musicbrainz.l_mood_work.id - published BOOLEAN NOT NULL, - name TEXT NOT NULL -); - -ALTER TABLE documentation.l_area_mood_example ADD CONSTRAINT l_area_mood_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_artist_mood_example ADD CONSTRAINT l_artist_mood_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_event_mood_example ADD CONSTRAINT l_event_mood_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_genre_mood_example ADD CONSTRAINT l_genre_mood_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_instrument_mood_example ADD CONSTRAINT l_instrument_mood_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_label_mood_example ADD CONSTRAINT l_label_mood_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_mood_mood_example ADD CONSTRAINT l_mood_mood_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_mood_place_example ADD CONSTRAINT l_mood_place_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_mood_recording_example ADD CONSTRAINT l_mood_recording_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_mood_release_example ADD CONSTRAINT l_mood_release_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_mood_release_group_example ADD CONSTRAINT l_mood_release_group_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_mood_series_example ADD CONSTRAINT l_mood_series_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_mood_url_example ADD CONSTRAINT l_mood_url_example_pkey PRIMARY KEY (id); -ALTER TABLE documentation.l_mood_work_example ADD CONSTRAINT l_mood_work_example_pkey PRIMARY KEY (id); - --------------------------------------------------------------------------------- -SELECT '20220426-mbs-12131.sql'; - - -DROP AGGREGATE IF EXISTS median(anyelement); -DROP FUNCTION IF EXISTS _median(anyarray); - -CREATE OR REPLACE FUNCTION _median(INTEGER[]) RETURNS INTEGER AS $$ - WITH q AS ( - SELECT val - FROM unnest($1) val - WHERE VAL IS NOT NULL - ORDER BY val - ) - SELECT val - FROM q - LIMIT 1 - -- Subtracting (n + 1) % 2 creates a left bias - OFFSET greatest(0, floor((select count(*) FROM q) / 2.0) - ((select count(*) + 1 FROM q) % 2)); -$$ LANGUAGE sql IMMUTABLE; - -CREATE OR REPLACE AGGREGATE median(INTEGER) ( - SFUNC=array_append, - STYPE=INTEGER[], - FINALFUNC=_median, - INITCOND='{}' -); - -DROP AGGREGATE IF EXISTS array_accum(anyelement); - -COMMIT; diff --git a/mbdata/sql/updates/schema-change/27.standalone.sql b/mbdata/sql/updates/schema-change/27.standalone.sql deleted file mode 100644 index 9a7dc4f..0000000 --- a/mbdata/sql/updates/schema-change/27.standalone.sql +++ /dev/null @@ -1,2301 +0,0 @@ --- Generated by CompileSchemaScripts.pl from: --- 20210419-mbs-11456-fks.sql --- 20210702-mbs-11760.sql --- 20210916-mbs-11896.sql --- 20210924-mbs-10327.sql --- 20211008-mbs-11903.sql --- 20211216-mbs-12140-12141.sql --- 20220207-mbs-12224-standalone.sql --- 20220309-mbs-12241.sql --- 20220314-mbs-12252-standalone.sql --- 20220314-mbs-12253-standalone.sql --- 20220314-mbs-12254-standalone.sql --- 20220314-mbs-12255-standalone.sql --- 20220322-mbs-12256-standalone.sql --- 20220408-immutable-link-tables-standalone.sql --- 20220408-mbs-12249-standalone.sql --- 20220412-mbs-12190-fks.sql --- 20220512-mbs-12369.sql -\set ON_ERROR_STOP 1 -BEGIN; -SET search_path = musicbrainz, public; -SET LOCAL statement_timeout = 0; --------------------------------------------------------------------------------- -SELECT '20210419-mbs-11456-fks.sql'; - -SET search_path = musicbrainz; - - -ALTER TABLE artist_credit_gid_redirect - ADD CONSTRAINT artist_credit_gid_redirect_fk_new_id - FOREIGN KEY (new_id) - REFERENCES artist_credit(id); - --------------------------------------------------------------------------------- -SELECT '20210702-mbs-11760.sql'; - - -DROP TRIGGER IF EXISTS delete_unused_tag ON event_tag; -DROP TRIGGER IF EXISTS delete_unused_tag ON place_tag; -DROP TRIGGER IF EXISTS delete_unused_tag ON recording_tag; -DROP TRIGGER IF EXISTS delete_unused_tag ON release_tag; - -CREATE CONSTRAINT TRIGGER delete_unused_tag -AFTER DELETE ON event_tag DEFERRABLE INITIALLY DEFERRED -FOR EACH ROW EXECUTE PROCEDURE trg_delete_unused_tag_ref(); - -CREATE CONSTRAINT TRIGGER delete_unused_tag -AFTER DELETE ON place_tag DEFERRABLE INITIALLY DEFERRED -FOR EACH ROW EXECUTE PROCEDURE trg_delete_unused_tag_ref(); - -CREATE CONSTRAINT TRIGGER delete_unused_tag -AFTER DELETE ON recording_tag DEFERRABLE INITIALLY DEFERRED -FOR EACH ROW EXECUTE PROCEDURE trg_delete_unused_tag_ref(); - -CREATE CONSTRAINT TRIGGER delete_unused_tag -AFTER DELETE ON release_tag DEFERRABLE INITIALLY DEFERRED -FOR EACH ROW EXECUTE PROCEDURE trg_delete_unused_tag_ref(); - --------------------------------------------------------------------------------- -SELECT '20210916-mbs-11896.sql'; - - -DROP TRIGGER IF EXISTS unique_primary_for_locale ON area_alias; -DROP TRIGGER IF EXISTS unique_primary_for_locale ON artist_alias; -DROP TRIGGER IF EXISTS unique_primary_for_locale ON event_alias; -DROP TRIGGER IF EXISTS unique_primary_for_locale ON genre_alias; -DROP TRIGGER IF EXISTS unique_primary_for_locale ON instrument_alias; -DROP TRIGGER IF EXISTS unique_primary_for_locale ON label_alias; -DROP TRIGGER IF EXISTS unique_primary_for_locale ON place_alias; -DROP TRIGGER IF EXISTS unique_primary_for_locale ON recording_alias; -DROP TRIGGER IF EXISTS unique_primary_for_locale ON release_alias; -DROP TRIGGER IF EXISTS unique_primary_for_locale ON release_group_alias; -DROP TRIGGER IF EXISTS unique_primary_for_locale ON series_alias; -DROP TRIGGER IF EXISTS unique_primary_for_locale ON work_alias; - -DROP FUNCTION IF EXISTS unique_primary_area_alias(); -DROP FUNCTION IF EXISTS unique_primary_artist_alias(); -DROP FUNCTION IF EXISTS unique_primary_event_alias(); -DROP FUNCTION IF EXISTS unique_primary_genre_alias(); -DROP FUNCTION IF EXISTS unique_primary_instrument_alias(); -DROP FUNCTION IF EXISTS unique_primary_label_alias(); -DROP FUNCTION IF EXISTS unique_primary_place_alias(); -DROP FUNCTION IF EXISTS unique_primary_recording_alias(); -DROP FUNCTION IF EXISTS unique_primary_release_alias(); -DROP FUNCTION IF EXISTS unique_primary_release_group_alias(); -DROP FUNCTION IF EXISTS unique_primary_series_alias(); -DROP FUNCTION IF EXISTS unique_primary_work_alias(); - --------------------------------------------------------------------------------- -SELECT '20210924-mbs-10327.sql'; - - -CREATE OR REPLACE FUNCTION del_collection_sub_on_private() -RETURNS trigger AS $$ - BEGIN - IF NEW.public = FALSE AND OLD.public = TRUE THEN - UPDATE editor_subscribe_collection sub - SET available = FALSE, - last_seen_name = OLD.name - WHERE sub.collection = OLD.id - AND sub.editor != NEW.editor - AND sub.editor NOT IN (SELECT ecc.editor - FROM editor_collection_collaborator ecc - WHERE ecc.collection = sub.collection); - END IF; - - RETURN NEW; - END; -$$ LANGUAGE 'plpgsql'; - --------------------------------------------------------------------------------- -SELECT '20211008-mbs-11903.sql'; - - -DROP TRIGGER IF EXISTS restore_collection_sub_on_public ON editor_collection; - -CREATE OR REPLACE FUNCTION restore_collection_sub_on_public() -RETURNS trigger AS $$ - BEGIN - IF NEW.public = TRUE AND OLD.public = FALSE THEN - UPDATE editor_subscribe_collection sub - SET available = TRUE, - last_seen_name = NEW.name - WHERE sub.collection = OLD.id - AND sub.available = FALSE; - END IF; - - RETURN NULL; - END; -$$ LANGUAGE 'plpgsql'; - --- Create triggers -CREATE TRIGGER restore_collection_sub_on_public AFTER UPDATE ON editor_collection - FOR EACH ROW EXECUTE PROCEDURE restore_collection_sub_on_public(); - --------------------------------------------------------------------------------- -SELECT '20211216-mbs-12140-12141.sql'; - - --- NOTE: Make sure this script runs *before* any that recalculates --- count/ref_count for the schema change. - -DO $$ -DECLARE - empty_tag_ids INTEGER[]; - -- An "uncontrolled for whitespace" tag. - ufw_tag RECORD; - -- An existing "controlled for whitespace" tag ID that would conflict with - -- ufw_tag if it were cleaned. - existing_cfw_tag_id INTEGER; - tag_cursor REFCURSOR; -BEGIN - SELECT array_agg(id) - FROM tag - WHERE name ~ E'^\\s*$' - INTO empty_tag_ids; - - RAISE NOTICE 'Deleting empty tag IDs: %', empty_tag_ids; - - DELETE FROM area_tag_raw WHERE tag = any(empty_tag_ids); - DELETE FROM artist_tag_raw WHERE tag = any(empty_tag_ids); - DELETE FROM event_tag_raw WHERE tag = any(empty_tag_ids); - DELETE FROM instrument_tag_raw WHERE tag = any(empty_tag_ids); - DELETE FROM label_tag_raw WHERE tag = any(empty_tag_ids); - DELETE FROM place_tag_raw WHERE tag = any(empty_tag_ids); - DELETE FROM recording_tag_raw WHERE tag = any(empty_tag_ids); - DELETE FROM release_tag_raw WHERE tag = any(empty_tag_ids); - DELETE FROM release_group_tag_raw WHERE tag = any(empty_tag_ids); - DELETE FROM series_tag_raw WHERE tag = any(empty_tag_ids); - DELETE FROM work_tag_raw WHERE tag = any(empty_tag_ids); - - DELETE FROM area_tag WHERE tag = any(empty_tag_ids); - DELETE FROM artist_tag WHERE tag = any(empty_tag_ids); - DELETE FROM event_tag WHERE tag = any(empty_tag_ids); - DELETE FROM instrument_tag WHERE tag = any(empty_tag_ids); - DELETE FROM label_tag WHERE tag = any(empty_tag_ids); - DELETE FROM place_tag WHERE tag = any(empty_tag_ids); - DELETE FROM recording_tag WHERE tag = any(empty_tag_ids); - DELETE FROM release_tag WHERE tag = any(empty_tag_ids); - DELETE FROM release_group_tag WHERE tag = any(empty_tag_ids); - DELETE FROM series_tag WHERE tag = any(empty_tag_ids); - DELETE FROM work_tag WHERE tag = any(empty_tag_ids); - - -- delete_unused_tag would normally kick in to delete these, but not if - -- they were completely unreferenced prior to running this script. - DELETE FROM tag WHERE id = any(empty_tag_ids); - - -- Find tags with uncontrolled whitespace and clean them up. - -- - -- We may find that for any unclean tag, an existing tag with the - -- "cleaned up" name already exists. In that case, we update all - -- *_tag_raw and *_tag rows to use the existing clean tag, and delete - -- the unclean one. - FOR ufw_tag IN ( - SELECT * FROM tag WHERE NOT controlled_for_whitespace(name) - ) LOOP - RAISE NOTICE 'Tag with uncontrolled whitespace found: id=%, name=%', - ufw_tag.id, to_json(ufw_tag.name); - - SELECT t2.id - FROM tag t1 - JOIN tag t2 - ON (t1.id = ufw_tag.id - AND t2.id != ufw_tag.id - AND t2.name = regexp_replace(btrim(t1.name), E'\\s{2,}', ' ', 'g')) - INTO existing_cfw_tag_id; - - IF existing_cfw_tag_id IS NULL THEN - UPDATE tag - SET name = regexp_replace(btrim(name), E'\\s{2,}', ' ', 'g') - WHERE id = ufw_tag.id; - ELSE - RAISE NOTICE 'Conflicting tag with controlled whitespace found: id=%', - existing_cfw_tag_id; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM area_tag_raw WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE area_tag_raw SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM area_tag_raw WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM area_tag WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE area_tag SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM area_tag WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM artist_tag_raw WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE artist_tag_raw SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM artist_tag_raw WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM artist_tag WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE artist_tag SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM artist_tag WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM event_tag_raw WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE event_tag_raw SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM event_tag_raw WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM event_tag WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE event_tag SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM event_tag WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM instrument_tag_raw WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE instrument_tag_raw SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM instrument_tag_raw WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM instrument_tag WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE instrument_tag SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM instrument_tag WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM label_tag_raw WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE label_tag_raw SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM label_tag_raw WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM label_tag WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE label_tag SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM label_tag WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM place_tag_raw WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE place_tag_raw SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM place_tag_raw WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM place_tag WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE place_tag SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM place_tag WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM recording_tag_raw WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE recording_tag_raw SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM recording_tag_raw WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM recording_tag WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE recording_tag SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM recording_tag WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM release_tag_raw WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE release_tag_raw SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM release_tag_raw WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM release_tag WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE release_tag SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM release_tag WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM release_group_tag_raw WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE release_group_tag_raw SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM release_group_tag_raw WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM release_group_tag WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE release_group_tag SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM release_group_tag WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM series_tag_raw WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE series_tag_raw SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM series_tag_raw WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM series_tag WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE series_tag SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM series_tag WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM work_tag_raw WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE work_tag_raw SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM work_tag_raw WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - OPEN tag_cursor NO SCROLL FOR SELECT * FROM work_tag WHERE tag = ufw_tag.id FOR UPDATE; - LOOP - MOVE tag_cursor; - IF FOUND THEN - BEGIN - UPDATE work_tag SET tag = existing_cfw_tag_id WHERE CURRENT OF tag_cursor; - EXCEPTION WHEN unique_violation THEN - DELETE FROM work_tag WHERE CURRENT OF tag_cursor; - END; - ELSE - CLOSE tag_cursor; - EXIT; - END IF; - END LOOP; - - DELETE FROM tag WHERE id = ufw_tag.id; - END IF; - END LOOP; -END -$$; - -ALTER TABLE tag DROP CONSTRAINT IF EXISTS control_for_whitespace; -ALTER TABLE tag DROP CONSTRAINT IF EXISTS only_non_empty; - -ALTER TABLE tag - ADD CONSTRAINT control_for_whitespace CHECK (controlled_for_whitespace(name)), - ADD CONSTRAINT only_non_empty CHECK (name != ''); - --------------------------------------------------------------------------------- -SELECT '20220207-mbs-12224-standalone.sql'; - - -CREATE TRIGGER update_counts_for_insert AFTER INSERT ON area_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_insert('area'); - -CREATE TRIGGER update_counts_for_update AFTER UPDATE ON area_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_update('area'); - -CREATE TRIGGER update_counts_for_delete AFTER DELETE ON area_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_delete('area'); - -CREATE TRIGGER update_counts_for_insert AFTER INSERT ON artist_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_insert('artist'); - -CREATE TRIGGER update_counts_for_update AFTER UPDATE ON artist_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_update('artist'); - -CREATE TRIGGER update_counts_for_delete AFTER DELETE ON artist_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_delete('artist'); - -CREATE TRIGGER update_counts_for_insert AFTER INSERT ON event_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_insert('event'); - -CREATE TRIGGER update_counts_for_update AFTER UPDATE ON event_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_update('event'); - -CREATE TRIGGER update_counts_for_delete AFTER DELETE ON event_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_delete('event'); - -CREATE TRIGGER update_counts_for_insert AFTER INSERT ON instrument_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_insert('instrument'); - -CREATE TRIGGER update_counts_for_update AFTER UPDATE ON instrument_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_update('instrument'); - -CREATE TRIGGER update_counts_for_delete AFTER DELETE ON instrument_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_delete('instrument'); - -CREATE TRIGGER update_counts_for_insert AFTER INSERT ON label_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_insert('label'); - -CREATE TRIGGER update_counts_for_update AFTER UPDATE ON label_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_update('label'); - -CREATE TRIGGER update_counts_for_delete AFTER DELETE ON label_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_delete('label'); - -CREATE TRIGGER update_counts_for_insert AFTER INSERT ON place_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_insert('place'); - -CREATE TRIGGER update_counts_for_update AFTER UPDATE ON place_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_update('place'); - -CREATE TRIGGER update_counts_for_delete AFTER DELETE ON place_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_delete('place'); - -CREATE TRIGGER update_counts_for_insert AFTER INSERT ON recording_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_insert('recording'); - -CREATE TRIGGER update_counts_for_update AFTER UPDATE ON recording_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_update('recording'); - -CREATE TRIGGER update_counts_for_delete AFTER DELETE ON recording_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_delete('recording'); - -CREATE TRIGGER update_counts_for_insert AFTER INSERT ON release_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_insert('release'); - -CREATE TRIGGER update_counts_for_update AFTER UPDATE ON release_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_update('release'); - -CREATE TRIGGER update_counts_for_delete AFTER DELETE ON release_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_delete('release'); - -CREATE TRIGGER update_counts_for_insert AFTER INSERT ON release_group_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_insert('release_group'); - -CREATE TRIGGER update_counts_for_update AFTER UPDATE ON release_group_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_update('release_group'); - -CREATE TRIGGER update_counts_for_delete AFTER DELETE ON release_group_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_delete('release_group'); - -CREATE TRIGGER update_counts_for_insert AFTER INSERT ON series_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_insert('series'); - -CREATE TRIGGER update_counts_for_update AFTER UPDATE ON series_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_update('series'); - -CREATE TRIGGER update_counts_for_delete AFTER DELETE ON series_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_delete('series'); - -CREATE TRIGGER update_counts_for_insert AFTER INSERT ON work_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_insert('work'); - -CREATE TRIGGER update_counts_for_update AFTER UPDATE ON work_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_update('work'); - -CREATE TRIGGER update_counts_for_delete AFTER DELETE ON work_tag_raw - FOR EACH ROW EXECUTE PROCEDURE update_tag_counts_for_raw_delete('work'); - --------------------------------------------------------------------------------- -SELECT '20220309-mbs-12241.sql'; - - -CREATE OR REPLACE FUNCTION controlled_for_whitespace(TEXT) RETURNS boolean AS $$ - SELECT NOT padded_by_whitespace($1); -$$ LANGUAGE SQL IMMUTABLE SET search_path = musicbrainz, public; - -DROP FUNCTION IF EXISTS whitespace_collapsed(TEXT); - --------------------------------------------------------------------------------- -SELECT '20220314-mbs-12252-standalone.sql'; - - -ALTER TABLE edit_genre - ADD CONSTRAINT edit_genre_fk_edit - FOREIGN KEY (edit) - REFERENCES edit(id); - -ALTER TABLE edit_genre - ADD CONSTRAINT edit_genre_fk_genre - FOREIGN KEY (genre) - REFERENCES genre(id) - ON DELETE CASCADE; - --------------------------------------------------------------------------------- -SELECT '20220314-mbs-12253-standalone.sql'; - - -ALTER TABLE l_area_genre ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_area_genre ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_artist_genre ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_artist_genre ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_event_genre ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_event_genre ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_genre_genre ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_genre_genre ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); -ALTER TABLE l_genre_genre ADD CONSTRAINT non_loop_relationship CHECK (entity0 != entity1); - -ALTER TABLE l_genre_instrument ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_genre_instrument ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_genre_label ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_genre_label ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_genre_place ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_genre_place ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_genre_recording ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_genre_recording ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_genre_release ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_genre_release ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_genre_release_group ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_genre_release_group ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_genre_series ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_genre_series ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_genre_url ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_genre_url ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_genre_work ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_genre_work ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - - -ALTER TABLE l_area_genre - ADD CONSTRAINT l_area_genre_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_area_genre - ADD CONSTRAINT l_area_genre_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES area(id); - -ALTER TABLE l_area_genre - ADD CONSTRAINT l_area_genre_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES genre(id); - -ALTER TABLE l_artist_genre - ADD CONSTRAINT l_artist_genre_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_artist_genre - ADD CONSTRAINT l_artist_genre_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES artist(id); - -ALTER TABLE l_artist_genre - ADD CONSTRAINT l_artist_genre_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES genre(id); - -ALTER TABLE l_event_genre - ADD CONSTRAINT l_event_genre_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_event_genre - ADD CONSTRAINT l_event_genre_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES event(id); - -ALTER TABLE l_event_genre - ADD CONSTRAINT l_event_genre_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES genre(id); - -ALTER TABLE l_genre_genre - ADD CONSTRAINT l_genre_genre_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_genre_genre - ADD CONSTRAINT l_genre_genre_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES genre(id); - -ALTER TABLE l_genre_genre - ADD CONSTRAINT l_genre_genre_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES genre(id); - -ALTER TABLE l_genre_instrument - ADD CONSTRAINT l_genre_instrument_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_genre_instrument - ADD CONSTRAINT l_genre_instrument_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES genre(id); - -ALTER TABLE l_genre_instrument - ADD CONSTRAINT l_genre_instrument_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES instrument(id); - -ALTER TABLE l_genre_label - ADD CONSTRAINT l_genre_label_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_genre_label - ADD CONSTRAINT l_genre_label_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES genre(id); - -ALTER TABLE l_genre_label - ADD CONSTRAINT l_genre_label_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES label(id); - -ALTER TABLE l_genre_place - ADD CONSTRAINT l_genre_place_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_genre_place - ADD CONSTRAINT l_genre_place_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES genre(id); - -ALTER TABLE l_genre_place - ADD CONSTRAINT l_genre_place_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES place(id); - -ALTER TABLE l_genre_recording - ADD CONSTRAINT l_genre_recording_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_genre_recording - ADD CONSTRAINT l_genre_recording_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES genre(id); - -ALTER TABLE l_genre_recording - ADD CONSTRAINT l_genre_recording_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES recording(id); - -ALTER TABLE l_genre_release - ADD CONSTRAINT l_genre_release_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_genre_release - ADD CONSTRAINT l_genre_release_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES genre(id); - -ALTER TABLE l_genre_release - ADD CONSTRAINT l_genre_release_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES release(id); - -ALTER TABLE l_genre_release_group - ADD CONSTRAINT l_genre_release_group_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_genre_release_group - ADD CONSTRAINT l_genre_release_group_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES genre(id); - -ALTER TABLE l_genre_release_group - ADD CONSTRAINT l_genre_release_group_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES release_group(id); - -ALTER TABLE l_genre_series - ADD CONSTRAINT l_genre_series_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_genre_series - ADD CONSTRAINT l_genre_series_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES genre(id); - -ALTER TABLE l_genre_series - ADD CONSTRAINT l_genre_series_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES series(id); - -ALTER TABLE l_genre_url - ADD CONSTRAINT l_genre_url_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_genre_url - ADD CONSTRAINT l_genre_url_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES genre(id); - -ALTER TABLE l_genre_url - ADD CONSTRAINT l_genre_url_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES url(id); - -ALTER TABLE l_genre_work - ADD CONSTRAINT l_genre_work_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_genre_work - ADD CONSTRAINT l_genre_work_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES genre(id); - -ALTER TABLE l_genre_work - ADD CONSTRAINT l_genre_work_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES work(id); - - -CREATE TRIGGER b_upd_l_area_genre BEFORE UPDATE ON l_area_genre - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_artist_genre BEFORE UPDATE ON l_artist_genre - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_event_genre BEFORE UPDATE ON l_event_genre - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_genre_genre BEFORE UPDATE ON l_genre_genre - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_genre_instrument BEFORE UPDATE ON l_genre_instrument - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_genre_label BEFORE UPDATE ON l_genre_label - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_genre_place BEFORE UPDATE ON l_genre_place - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_genre_recording BEFORE UPDATE ON l_genre_recording - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_genre_release BEFORE UPDATE ON l_genre_release - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_genre_release_group BEFORE UPDATE ON l_genre_release_group - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_genre_url BEFORE UPDATE ON l_genre_url - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_genre_work BEFORE UPDATE ON l_genre_work - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_area_genre DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_artist_genre DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_event_genre DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_genre_genre DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_genre_instrument DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_genre_label DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_genre_place DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_genre_recording DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_genre_release DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_genre_release_group DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_genre_url DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_genre_work DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER url_gc_a_upd_l_genre_url -AFTER UPDATE ON l_genre_url DEFERRABLE INITIALLY DEFERRED -FOR EACH ROW EXECUTE PROCEDURE remove_unused_url(); - -CREATE CONSTRAINT TRIGGER url_gc_a_del_l_genre_url -AFTER DELETE ON l_genre_url DEFERRABLE INITIALLY DEFERRED -FOR EACH ROW EXECUTE PROCEDURE remove_unused_url(); - - -ALTER TABLE documentation.l_area_genre_example - ADD CONSTRAINT l_area_genre_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_area_genre(id); - -ALTER TABLE documentation.l_artist_genre_example - ADD CONSTRAINT l_artist_genre_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_artist_genre(id); - -ALTER TABLE documentation.l_event_genre_example - ADD CONSTRAINT l_event_genre_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_event_genre(id); - -ALTER TABLE documentation.l_genre_genre_example - ADD CONSTRAINT l_genre_genre_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_genre_genre(id); - -ALTER TABLE documentation.l_genre_instrument_example - ADD CONSTRAINT l_genre_instrument_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_genre_instrument(id); - -ALTER TABLE documentation.l_genre_label_example - ADD CONSTRAINT l_genre_label_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_genre_label(id); - -ALTER TABLE documentation.l_genre_place_example - ADD CONSTRAINT l_genre_place_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_genre_place(id); - -ALTER TABLE documentation.l_genre_recording_example - ADD CONSTRAINT l_genre_recording_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_genre_recording(id); - -ALTER TABLE documentation.l_genre_release_example - ADD CONSTRAINT l_genre_release_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_genre_release(id); - -ALTER TABLE documentation.l_genre_release_group_example - ADD CONSTRAINT l_genre_release_group_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_genre_release_group(id); - -ALTER TABLE documentation.l_genre_series_example - ADD CONSTRAINT l_genre_series_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_genre_series(id); - -ALTER TABLE documentation.l_genre_url_example - ADD CONSTRAINT l_genre_url_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_genre_url(id); - -ALTER TABLE documentation.l_genre_work_example - ADD CONSTRAINT l_genre_work_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_genre_work(id); - --------------------------------------------------------------------------------- -SELECT '20220314-mbs-12254-standalone.sql'; - - -ALTER TABLE genre_annotation - ADD CONSTRAINT genre_annotation_fk_genre - FOREIGN KEY (genre) - REFERENCES genre(id); - -ALTER TABLE genre_annotation - ADD CONSTRAINT genre_annotation_fk_annotation - FOREIGN KEY (annotation) - REFERENCES annotation(id); - --------------------------------------------------------------------------------- -SELECT '20220314-mbs-12255-standalone.sql'; - - -ALTER TABLE genre_alias - ADD CONSTRAINT genre_alias_fk_type - FOREIGN KEY (type) - REFERENCES genre_alias_type(id); - -ALTER TABLE genre_alias - ADD CONSTRAINT genre_alias_fk_genre - FOREIGN KEY (genre) - REFERENCES genre(id); - -ALTER TABLE genre_alias_type - ADD CONSTRAINT genre_alias_type_fk_parent - FOREIGN KEY (parent) - REFERENCES genre_alias_type(id); - -CREATE TRIGGER end_date_implies_ended BEFORE UPDATE OR INSERT ON genre_alias - FOR EACH ROW EXECUTE PROCEDURE end_date_implies_ended(); - -CREATE TRIGGER b_upd_genre_alias BEFORE UPDATE ON genre_alias - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER search_hint BEFORE UPDATE OR INSERT ON genre_alias - FOR EACH ROW EXECUTE PROCEDURE simplify_search_hints(2); - --------------------------------------------------------------------------------- -SELECT '20220322-mbs-12256-standalone.sql'; - - -CREATE TRIGGER update_aggregate_rating_for_insert AFTER INSERT ON artist_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_insert('artist'); - -CREATE TRIGGER update_aggregate_rating_for_update AFTER UPDATE ON artist_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_update('artist'); - -CREATE TRIGGER update_aggregate_rating_for_delete AFTER DELETE ON artist_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_delete('artist'); - -CREATE TRIGGER update_aggregate_rating_for_insert AFTER INSERT ON event_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_insert('event'); - -CREATE TRIGGER update_aggregate_rating_for_update AFTER UPDATE ON event_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_update('event'); - -CREATE TRIGGER update_aggregate_rating_for_delete AFTER DELETE ON event_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_delete('event'); - -CREATE TRIGGER update_aggregate_rating_for_insert AFTER INSERT ON label_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_insert('label'); - -CREATE TRIGGER update_aggregate_rating_for_update AFTER UPDATE ON label_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_update('label'); - -CREATE TRIGGER update_aggregate_rating_for_delete AFTER DELETE ON label_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_delete('label'); - -CREATE TRIGGER update_aggregate_rating_for_insert AFTER INSERT ON place_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_insert('place'); - -CREATE TRIGGER update_aggregate_rating_for_update AFTER UPDATE ON place_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_update('place'); - -CREATE TRIGGER update_aggregate_rating_for_delete AFTER DELETE ON place_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_delete('place'); - -CREATE TRIGGER update_aggregate_rating_for_insert AFTER INSERT ON recording_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_insert('recording'); - -CREATE TRIGGER update_aggregate_rating_for_update AFTER UPDATE ON recording_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_update('recording'); - -CREATE TRIGGER update_aggregate_rating_for_delete AFTER DELETE ON recording_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_delete('recording'); - -CREATE TRIGGER update_aggregate_rating_for_insert AFTER INSERT ON release_group_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_insert('release_group'); - -CREATE TRIGGER update_aggregate_rating_for_update AFTER UPDATE ON release_group_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_update('release_group'); - -CREATE TRIGGER update_aggregate_rating_for_delete AFTER DELETE ON release_group_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_delete('release_group'); - -CREATE TRIGGER update_aggregate_rating_for_insert AFTER INSERT ON work_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_insert('work'); - -CREATE TRIGGER update_aggregate_rating_for_update AFTER UPDATE ON work_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_update('work'); - -CREATE TRIGGER update_aggregate_rating_for_delete AFTER DELETE ON work_rating_raw - FOR EACH ROW EXECUTE PROCEDURE update_aggregate_rating_for_raw_delete('work'); - --------------------------------------------------------------------------------- -SELECT '20220408-immutable-link-tables-standalone.sql'; - - -DROP TRIGGER IF EXISTS deny_deprecated ON link; - -CREATE TRIGGER deny_deprecated BEFORE INSERT ON link - FOR EACH ROW EXECUTE PROCEDURE deny_deprecated_links(); - -DROP TRIGGER IF EXISTS b_upd_link ON link; - -CREATE TRIGGER b_upd_link BEFORE UPDATE ON link - FOR EACH ROW EXECUTE PROCEDURE b_upd_link(); - -DROP TRIGGER IF EXISTS b_ins_link_attribute ON link_attribute; - -CREATE TRIGGER b_ins_link_attribute BEFORE INSERT ON link_attribute - FOR EACH ROW EXECUTE PROCEDURE prevent_invalid_attributes(); - -DROP TRIGGER IF EXISTS b_upd_link_attribute ON link_attribute; - -CREATE TRIGGER b_upd_link_attribute BEFORE UPDATE ON link_attribute - FOR EACH ROW EXECUTE PROCEDURE b_upd_link_attribute(); - -DROP TRIGGER IF EXISTS b_upd_link_attribute_credit ON link_attribute_credit; - -CREATE TRIGGER b_upd_link_attribute_credit BEFORE UPDATE ON link_attribute_credit - FOR EACH ROW EXECUTE PROCEDURE b_upd_link_attribute_credit(); - -DROP TRIGGER IF EXISTS b_upd_link_attribute_text_value ON link_attribute_text_value; - -CREATE TRIGGER b_upd_link_attribute_text_value BEFORE UPDATE ON link_attribute_text_value - FOR EACH ROW EXECUTE PROCEDURE b_upd_link_attribute_text_value(); - --------------------------------------------------------------------------------- -SELECT '20220408-mbs-12249-standalone.sql'; - - -ALTER TABLE area_containment - ADD CONSTRAINT area_containment_fk_descendant - FOREIGN KEY (descendant) - REFERENCES area(id); - -ALTER TABLE area_containment - ADD CONSTRAINT area_containment_fk_parent - FOREIGN KEY (parent) - REFERENCES area(id); - -DROP TRIGGER IF EXISTS a_ins_l_area_area ON l_area_area; - -CREATE TRIGGER a_ins_l_area_area AFTER INSERT ON l_area_area - FOR EACH ROW EXECUTE PROCEDURE a_ins_l_area_area_mirror(); - -DROP TRIGGER IF EXISTS a_upd_l_area_area ON l_area_area; - -CREATE TRIGGER a_upd_l_area_area AFTER UPDATE ON l_area_area - FOR EACH ROW EXECUTE PROCEDURE a_upd_l_area_area_mirror(); - -DROP TRIGGER IF EXISTS a_del_l_area_area ON l_area_area; - -CREATE TRIGGER a_del_l_area_area AFTER DELETE ON l_area_area - FOR EACH ROW EXECUTE PROCEDURE a_del_l_area_area_mirror(); - --------------------------------------------------------------------------------- -SELECT '20220412-mbs-12190-fks.sql'; - - --- FKs - -ALTER TABLE edit_mood - ADD CONSTRAINT edit_mood_fk_edit - FOREIGN KEY (edit) - REFERENCES edit(id); - -ALTER TABLE edit_mood - ADD CONSTRAINT edit_mood_fk_mood - FOREIGN KEY (mood) - REFERENCES mood(id) - ON DELETE CASCADE; - -ALTER TABLE l_area_mood - ADD CONSTRAINT l_area_mood_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_area_mood - ADD CONSTRAINT l_area_mood_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES area(id); - -ALTER TABLE l_area_mood - ADD CONSTRAINT l_area_mood_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES mood(id); - -ALTER TABLE l_artist_mood - ADD CONSTRAINT l_artist_mood_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_artist_mood - ADD CONSTRAINT l_artist_mood_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES artist(id); - -ALTER TABLE l_artist_mood - ADD CONSTRAINT l_artist_mood_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES mood(id); - -ALTER TABLE l_event_mood - ADD CONSTRAINT l_event_mood_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_event_mood - ADD CONSTRAINT l_event_mood_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES event(id); - -ALTER TABLE l_event_mood - ADD CONSTRAINT l_event_mood_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES mood(id); - -ALTER TABLE l_genre_mood - ADD CONSTRAINT l_genre_mood_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_genre_mood - ADD CONSTRAINT l_genre_mood_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES genre(id); - -ALTER TABLE l_genre_mood - ADD CONSTRAINT l_genre_mood_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES mood(id); - -ALTER TABLE l_instrument_mood - ADD CONSTRAINT l_instrument_mood_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_instrument_mood - ADD CONSTRAINT l_instrument_mood_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES instrument(id); - -ALTER TABLE l_instrument_mood - ADD CONSTRAINT l_instrument_mood_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES mood(id); - -ALTER TABLE l_label_mood - ADD CONSTRAINT l_label_mood_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_label_mood - ADD CONSTRAINT l_label_mood_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES label(id); - -ALTER TABLE l_label_mood - ADD CONSTRAINT l_label_mood_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES mood(id); - -ALTER TABLE l_mood_mood - ADD CONSTRAINT l_mood_mood_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_mood_mood - ADD CONSTRAINT l_mood_mood_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES mood(id); - -ALTER TABLE l_mood_mood - ADD CONSTRAINT l_mood_mood_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES mood(id); - -ALTER TABLE l_mood_place - ADD CONSTRAINT l_mood_place_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_mood_place - ADD CONSTRAINT l_mood_place_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES mood(id); - -ALTER TABLE l_mood_place - ADD CONSTRAINT l_mood_place_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES place(id); - -ALTER TABLE l_mood_recording - ADD CONSTRAINT l_mood_recording_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_mood_recording - ADD CONSTRAINT l_mood_recording_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES mood(id); - -ALTER TABLE l_mood_recording - ADD CONSTRAINT l_mood_recording_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES recording(id); - -ALTER TABLE l_mood_release - ADD CONSTRAINT l_mood_release_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_mood_release - ADD CONSTRAINT l_mood_release_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES mood(id); - -ALTER TABLE l_mood_release - ADD CONSTRAINT l_mood_release_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES release(id); - -ALTER TABLE l_mood_release_group - ADD CONSTRAINT l_mood_release_group_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_mood_release_group - ADD CONSTRAINT l_mood_release_group_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES mood(id); - -ALTER TABLE l_mood_release_group - ADD CONSTRAINT l_mood_release_group_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES release_group(id); - -ALTER TABLE l_mood_series - ADD CONSTRAINT l_mood_series_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_mood_series - ADD CONSTRAINT l_mood_series_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES mood(id); - -ALTER TABLE l_mood_series - ADD CONSTRAINT l_mood_series_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES series(id); - -ALTER TABLE l_mood_url - ADD CONSTRAINT l_mood_url_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_mood_url - ADD CONSTRAINT l_mood_url_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES mood(id); - -ALTER TABLE l_mood_url - ADD CONSTRAINT l_mood_url_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES url(id); - -ALTER TABLE l_mood_work - ADD CONSTRAINT l_mood_work_fk_link - FOREIGN KEY (link) - REFERENCES link(id); - -ALTER TABLE l_mood_work - ADD CONSTRAINT l_mood_work_fk_entity0 - FOREIGN KEY (entity0) - REFERENCES mood(id); - -ALTER TABLE l_mood_work - ADD CONSTRAINT l_mood_work_fk_entity1 - FOREIGN KEY (entity1) - REFERENCES work(id); - -ALTER TABLE mood_alias - ADD CONSTRAINT mood_alias_fk_mood - FOREIGN KEY (mood) - REFERENCES mood(id); - -ALTER TABLE mood_alias - ADD CONSTRAINT mood_alias_fk_type - FOREIGN KEY (type) - REFERENCES mood_alias_type(id); - -ALTER TABLE mood_alias_type - ADD CONSTRAINT mood_alias_type_fk_parent - FOREIGN KEY (parent) - REFERENCES mood_alias_type(id); - -ALTER TABLE mood_annotation - ADD CONSTRAINT mood_annotation_fk_mood - FOREIGN KEY (mood) - REFERENCES mood(id); - -ALTER TABLE mood_annotation - ADD CONSTRAINT mood_annotation_fk_annotation - FOREIGN KEY (annotation) - REFERENCES annotation(id); - -ALTER TABLE documentation.l_area_mood_example - ADD CONSTRAINT l_area_mood_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_area_mood(id); - -ALTER TABLE documentation.l_artist_mood_example - ADD CONSTRAINT l_artist_mood_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_artist_mood(id); - -ALTER TABLE documentation.l_event_mood_example - ADD CONSTRAINT l_event_mood_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_event_mood(id); - -ALTER TABLE documentation.l_genre_mood_example - ADD CONSTRAINT l_genre_mood_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_genre_mood(id); - -ALTER TABLE documentation.l_instrument_mood_example - ADD CONSTRAINT l_instrument_mood_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_instrument_mood(id); - -ALTER TABLE documentation.l_label_mood_example - ADD CONSTRAINT l_label_mood_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_label_mood(id); - -ALTER TABLE documentation.l_mood_mood_example - ADD CONSTRAINT l_mood_mood_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_mood_mood(id); - -ALTER TABLE documentation.l_mood_place_example - ADD CONSTRAINT l_mood_place_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_mood_place(id); - -ALTER TABLE documentation.l_mood_recording_example - ADD CONSTRAINT l_mood_recording_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_mood_recording(id); - -ALTER TABLE documentation.l_mood_release_example - ADD CONSTRAINT l_mood_release_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_mood_release(id); - -ALTER TABLE documentation.l_mood_release_group_example - ADD CONSTRAINT l_mood_release_group_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_mood_release_group(id); - -ALTER TABLE documentation.l_mood_series_example - ADD CONSTRAINT l_mood_series_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_mood_series(id); - -ALTER TABLE documentation.l_mood_url_example - ADD CONSTRAINT l_mood_url_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_mood_url(id); - -ALTER TABLE documentation.l_mood_work_example - ADD CONSTRAINT l_mood_work_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_mood_work(id); - - --- Constraints - -ALTER TABLE l_area_mood ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_area_mood ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_artist_mood ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_artist_mood ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_event_mood ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_event_mood ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_genre_mood ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_genre_mood ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_instrument_mood ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_instrument_mood ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_label_mood ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_label_mood ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_mood_mood ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_mood_mood ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); -ALTER TABLE l_mood_mood ADD CONSTRAINT non_loop_relationship CHECK (entity0 != entity1); - -ALTER TABLE l_mood_place ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_mood_place ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_mood_recording ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_mood_recording ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_mood_release ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_mood_release ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_mood_release_group ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_mood_release_group ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_mood_series ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_mood_series ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_mood_url ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_mood_url ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - -ALTER TABLE l_mood_work ADD CONSTRAINT control_for_whitespace_entity0_credit CHECK (controlled_for_whitespace(entity0_credit)); -ALTER TABLE l_mood_work ADD CONSTRAINT control_for_whitespace_entity1_credit CHECK (controlled_for_whitespace(entity1_credit)); - --- Triggers - -CREATE TRIGGER b_upd_l_area_mood BEFORE UPDATE ON l_area_mood - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_artist_mood BEFORE UPDATE ON l_artist_mood - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_event_mood BEFORE UPDATE ON l_event_mood - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_genre_mood BEFORE UPDATE ON l_genre_mood - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_instrument_mood BEFORE UPDATE ON l_instrument_mood - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_label_mood BEFORE UPDATE ON l_label_mood - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_mood_mood BEFORE UPDATE ON l_mood_mood - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_mood_place BEFORE UPDATE ON l_mood_place - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_mood_recording BEFORE UPDATE ON l_mood_recording - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_mood_release BEFORE UPDATE ON l_mood_release - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_mood_release_group BEFORE UPDATE ON l_mood_release_group - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_mood_url BEFORE UPDATE ON l_mood_url - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_l_mood_work BEFORE UPDATE ON l_mood_work - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER b_upd_mood BEFORE UPDATE ON mood - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER end_date_implies_ended BEFORE UPDATE OR INSERT ON mood_alias - FOR EACH ROW EXECUTE PROCEDURE end_date_implies_ended(); - -CREATE TRIGGER b_upd_mood_alias BEFORE UPDATE ON mood_alias - FOR EACH ROW EXECUTE PROCEDURE b_upd_last_updated_table(); - -CREATE TRIGGER search_hint BEFORE UPDATE OR INSERT ON mood_alias - FOR EACH ROW EXECUTE PROCEDURE simplify_search_hints(2); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_area_mood DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_artist_mood DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_event_mood DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_genre_mood DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_instrument_mood DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_label_mood DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_mood_mood DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_mood_place DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_mood_recording DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_mood_release DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_mood_release_group DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_mood_url DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER remove_unused_links - AFTER DELETE OR UPDATE ON l_mood_work DEFERRABLE INITIALLY DEFERRED - FOR EACH ROW EXECUTE PROCEDURE remove_unused_links(); - -CREATE CONSTRAINT TRIGGER url_gc_a_upd_l_mood_url -AFTER UPDATE ON l_mood_url DEFERRABLE INITIALLY DEFERRED -FOR EACH ROW EXECUTE PROCEDURE remove_unused_url(); - -CREATE CONSTRAINT TRIGGER url_gc_a_del_l_mood_url -AFTER DELETE ON l_mood_url DEFERRABLE INITIALLY DEFERRED -FOR EACH ROW EXECUTE PROCEDURE remove_unused_url(); - --------------------------------------------------------------------------------- -SELECT '20220512-mbs-12369.sql'; - - --- This excludes genre & mood FKs, since those are already being created in --- separate schema-27 upgrade scripts. - -ALTER TABLE documentation.l_area_area_example DROP CONSTRAINT IF EXISTS l_area_area_example_fk_id; -ALTER TABLE documentation.l_area_artist_example DROP CONSTRAINT IF EXISTS l_area_artist_example_fk_id; -ALTER TABLE documentation.l_area_event_example DROP CONSTRAINT IF EXISTS l_area_event_example_fk_id; -ALTER TABLE documentation.l_area_instrument_example DROP CONSTRAINT IF EXISTS l_area_instrument_example_fk_id; -ALTER TABLE documentation.l_area_label_example DROP CONSTRAINT IF EXISTS l_area_label_example_fk_id; -ALTER TABLE documentation.l_area_place_example DROP CONSTRAINT IF EXISTS l_area_place_example_fk_id; -ALTER TABLE documentation.l_area_recording_example DROP CONSTRAINT IF EXISTS l_area_recording_example_fk_id; -ALTER TABLE documentation.l_area_release_example DROP CONSTRAINT IF EXISTS l_area_release_example_fk_id; -ALTER TABLE documentation.l_area_release_group_example DROP CONSTRAINT IF EXISTS l_area_release_group_example_fk_id; -ALTER TABLE documentation.l_area_series_example DROP CONSTRAINT IF EXISTS l_area_series_example_fk_id; -ALTER TABLE documentation.l_area_url_example DROP CONSTRAINT IF EXISTS l_area_url_example_fk_id; -ALTER TABLE documentation.l_area_work_example DROP CONSTRAINT IF EXISTS l_area_work_example_fk_id; -ALTER TABLE documentation.l_artist_artist_example DROP CONSTRAINT IF EXISTS l_artist_artist_example_fk_id; -ALTER TABLE documentation.l_artist_event_example DROP CONSTRAINT IF EXISTS l_artist_event_example_fk_id; -ALTER TABLE documentation.l_artist_instrument_example DROP CONSTRAINT IF EXISTS l_artist_instrument_example_fk_id; -ALTER TABLE documentation.l_artist_label_example DROP CONSTRAINT IF EXISTS l_artist_label_example_fk_id; -ALTER TABLE documentation.l_artist_place_example DROP CONSTRAINT IF EXISTS l_artist_place_example_fk_id; -ALTER TABLE documentation.l_artist_recording_example DROP CONSTRAINT IF EXISTS l_artist_recording_example_fk_id; -ALTER TABLE documentation.l_artist_release_example DROP CONSTRAINT IF EXISTS l_artist_release_example_fk_id; -ALTER TABLE documentation.l_artist_release_group_example DROP CONSTRAINT IF EXISTS l_artist_release_group_example_fk_id; -ALTER TABLE documentation.l_artist_series_example DROP CONSTRAINT IF EXISTS l_artist_series_example_fk_id; -ALTER TABLE documentation.l_artist_url_example DROP CONSTRAINT IF EXISTS l_artist_url_example_fk_id; -ALTER TABLE documentation.l_artist_work_example DROP CONSTRAINT IF EXISTS l_artist_work_example_fk_id; -ALTER TABLE documentation.l_event_event_example DROP CONSTRAINT IF EXISTS l_event_event_example_fk_id; -ALTER TABLE documentation.l_event_instrument_example DROP CONSTRAINT IF EXISTS l_event_instrument_example_fk_id; -ALTER TABLE documentation.l_event_label_example DROP CONSTRAINT IF EXISTS l_event_label_example_fk_id; -ALTER TABLE documentation.l_event_place_example DROP CONSTRAINT IF EXISTS l_event_place_example_fk_id; -ALTER TABLE documentation.l_event_recording_example DROP CONSTRAINT IF EXISTS l_event_recording_example_fk_id; -ALTER TABLE documentation.l_event_release_example DROP CONSTRAINT IF EXISTS l_event_release_example_fk_id; -ALTER TABLE documentation.l_event_release_group_example DROP CONSTRAINT IF EXISTS l_event_release_group_example_fk_id; -ALTER TABLE documentation.l_event_series_example DROP CONSTRAINT IF EXISTS l_event_series_example_fk_id; -ALTER TABLE documentation.l_event_url_example DROP CONSTRAINT IF EXISTS l_event_url_example_fk_id; -ALTER TABLE documentation.l_event_work_example DROP CONSTRAINT IF EXISTS l_event_work_example_fk_id; -ALTER TABLE documentation.l_instrument_instrument_example DROP CONSTRAINT IF EXISTS l_instrument_instrument_example_fk_id; -ALTER TABLE documentation.l_instrument_label_example DROP CONSTRAINT IF EXISTS l_instrument_label_example_fk_id; -ALTER TABLE documentation.l_instrument_place_example DROP CONSTRAINT IF EXISTS l_instrument_place_example_fk_id; -ALTER TABLE documentation.l_instrument_recording_example DROP CONSTRAINT IF EXISTS l_instrument_recording_example_fk_id; -ALTER TABLE documentation.l_instrument_release_example DROP CONSTRAINT IF EXISTS l_instrument_release_example_fk_id; -ALTER TABLE documentation.l_instrument_release_group_example DROP CONSTRAINT IF EXISTS l_instrument_release_group_example_fk_id; -ALTER TABLE documentation.l_instrument_series_example DROP CONSTRAINT IF EXISTS l_instrument_series_example_fk_id; -ALTER TABLE documentation.l_instrument_url_example DROP CONSTRAINT IF EXISTS l_instrument_url_example_fk_id; -ALTER TABLE documentation.l_instrument_work_example DROP CONSTRAINT IF EXISTS l_instrument_work_example_fk_id; -ALTER TABLE documentation.l_label_label_example DROP CONSTRAINT IF EXISTS l_label_label_example_fk_id; -ALTER TABLE documentation.l_label_place_example DROP CONSTRAINT IF EXISTS l_label_place_example_fk_id; -ALTER TABLE documentation.l_label_recording_example DROP CONSTRAINT IF EXISTS l_label_recording_example_fk_id; -ALTER TABLE documentation.l_label_release_example DROP CONSTRAINT IF EXISTS l_label_release_example_fk_id; -ALTER TABLE documentation.l_label_release_group_example DROP CONSTRAINT IF EXISTS l_label_release_group_example_fk_id; -ALTER TABLE documentation.l_label_series_example DROP CONSTRAINT IF EXISTS l_label_series_example_fk_id; -ALTER TABLE documentation.l_label_url_example DROP CONSTRAINT IF EXISTS l_label_url_example_fk_id; -ALTER TABLE documentation.l_label_work_example DROP CONSTRAINT IF EXISTS l_label_work_example_fk_id; -ALTER TABLE documentation.l_place_place_example DROP CONSTRAINT IF EXISTS l_place_place_example_fk_id; -ALTER TABLE documentation.l_place_recording_example DROP CONSTRAINT IF EXISTS l_place_recording_example_fk_id; -ALTER TABLE documentation.l_place_release_example DROP CONSTRAINT IF EXISTS l_place_release_example_fk_id; -ALTER TABLE documentation.l_place_release_group_example DROP CONSTRAINT IF EXISTS l_place_release_group_example_fk_id; -ALTER TABLE documentation.l_place_series_example DROP CONSTRAINT IF EXISTS l_place_series_example_fk_id; -ALTER TABLE documentation.l_place_url_example DROP CONSTRAINT IF EXISTS l_place_url_example_fk_id; -ALTER TABLE documentation.l_place_work_example DROP CONSTRAINT IF EXISTS l_place_work_example_fk_id; -ALTER TABLE documentation.l_recording_recording_example DROP CONSTRAINT IF EXISTS l_recording_recording_example_fk_id; -ALTER TABLE documentation.l_recording_release_example DROP CONSTRAINT IF EXISTS l_recording_release_example_fk_id; -ALTER TABLE documentation.l_recording_release_group_example DROP CONSTRAINT IF EXISTS l_recording_release_group_example_fk_id; -ALTER TABLE documentation.l_recording_series_example DROP CONSTRAINT IF EXISTS l_recording_series_example_fk_id; -ALTER TABLE documentation.l_recording_url_example DROP CONSTRAINT IF EXISTS l_recording_url_example_fk_id; -ALTER TABLE documentation.l_recording_work_example DROP CONSTRAINT IF EXISTS l_recording_work_example_fk_id; -ALTER TABLE documentation.l_release_group_release_group_example DROP CONSTRAINT IF EXISTS l_release_group_release_group_example_fk_id; -ALTER TABLE documentation.l_release_group_series_example DROP CONSTRAINT IF EXISTS l_release_group_series_example_fk_id; -ALTER TABLE documentation.l_release_group_url_example DROP CONSTRAINT IF EXISTS l_release_group_url_example_fk_id; -ALTER TABLE documentation.l_release_group_work_example DROP CONSTRAINT IF EXISTS l_release_group_work_example_fk_id; -ALTER TABLE documentation.l_release_release_example DROP CONSTRAINT IF EXISTS l_release_release_example_fk_id; -ALTER TABLE documentation.l_release_release_group_example DROP CONSTRAINT IF EXISTS l_release_release_group_example_fk_id; -ALTER TABLE documentation.l_release_series_example DROP CONSTRAINT IF EXISTS l_release_series_example_fk_id; -ALTER TABLE documentation.l_release_url_example DROP CONSTRAINT IF EXISTS l_release_url_example_fk_id; -ALTER TABLE documentation.l_release_work_example DROP CONSTRAINT IF EXISTS l_release_work_example_fk_id; -ALTER TABLE documentation.l_series_series_example DROP CONSTRAINT IF EXISTS l_series_series_example_fk_id; -ALTER TABLE documentation.l_series_url_example DROP CONSTRAINT IF EXISTS l_series_url_example_fk_id; -ALTER TABLE documentation.l_series_work_example DROP CONSTRAINT IF EXISTS l_series_work_example_fk_id; -ALTER TABLE documentation.l_url_url_example DROP CONSTRAINT IF EXISTS l_url_url_example_fk_id; -ALTER TABLE documentation.l_url_work_example DROP CONSTRAINT IF EXISTS l_url_work_example_fk_id; -ALTER TABLE documentation.l_work_work_example DROP CONSTRAINT IF EXISTS l_work_work_example_fk_id; -ALTER TABLE documentation.link_type_documentation DROP CONSTRAINT IF EXISTS link_type_documentation_fk_id; - -DELETE FROM documentation.l_area_area_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_area_area); -DELETE FROM documentation.l_area_artist_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_area_artist); -DELETE FROM documentation.l_area_event_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_area_event); -DELETE FROM documentation.l_area_instrument_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_area_instrument); -DELETE FROM documentation.l_area_label_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_area_label); -DELETE FROM documentation.l_area_place_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_area_place); -DELETE FROM documentation.l_area_recording_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_area_recording); -DELETE FROM documentation.l_area_release_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_area_release); -DELETE FROM documentation.l_area_release_group_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_area_release_group); -DELETE FROM documentation.l_area_series_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_area_series); -DELETE FROM documentation.l_area_url_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_area_url); -DELETE FROM documentation.l_area_work_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_area_work); -DELETE FROM documentation.l_artist_artist_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_artist_artist); -DELETE FROM documentation.l_artist_event_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_artist_event); -DELETE FROM documentation.l_artist_instrument_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_artist_instrument); -DELETE FROM documentation.l_artist_label_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_artist_label); -DELETE FROM documentation.l_artist_place_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_artist_place); -DELETE FROM documentation.l_artist_recording_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_artist_recording); -DELETE FROM documentation.l_artist_release_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_artist_release); -DELETE FROM documentation.l_artist_release_group_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_artist_release_group); -DELETE FROM documentation.l_artist_series_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_artist_series); -DELETE FROM documentation.l_artist_url_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_artist_url); -DELETE FROM documentation.l_artist_work_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_artist_work); -DELETE FROM documentation.l_event_event_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_event_event); -DELETE FROM documentation.l_event_instrument_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_event_instrument); -DELETE FROM documentation.l_event_label_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_event_label); -DELETE FROM documentation.l_event_place_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_event_place); -DELETE FROM documentation.l_event_recording_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_event_recording); -DELETE FROM documentation.l_event_release_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_event_release); -DELETE FROM documentation.l_event_release_group_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_event_release_group); -DELETE FROM documentation.l_event_series_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_event_series); -DELETE FROM documentation.l_event_url_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_event_url); -DELETE FROM documentation.l_event_work_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_event_work); -DELETE FROM documentation.l_instrument_instrument_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_instrument_instrument); -DELETE FROM documentation.l_instrument_label_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_instrument_label); -DELETE FROM documentation.l_instrument_place_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_instrument_place); -DELETE FROM documentation.l_instrument_recording_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_instrument_recording); -DELETE FROM documentation.l_instrument_release_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_instrument_release); -DELETE FROM documentation.l_instrument_release_group_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_instrument_release_group); -DELETE FROM documentation.l_instrument_series_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_instrument_series); -DELETE FROM documentation.l_instrument_url_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_instrument_url); -DELETE FROM documentation.l_instrument_work_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_instrument_work); -DELETE FROM documentation.l_label_label_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_label_label); -DELETE FROM documentation.l_label_place_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_label_place); -DELETE FROM documentation.l_label_recording_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_label_recording); -DELETE FROM documentation.l_label_release_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_label_release); -DELETE FROM documentation.l_label_release_group_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_label_release_group); -DELETE FROM documentation.l_label_series_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_label_series); -DELETE FROM documentation.l_label_url_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_label_url); -DELETE FROM documentation.l_label_work_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_label_work); -DELETE FROM documentation.l_place_place_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_place_place); -DELETE FROM documentation.l_place_recording_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_place_recording); -DELETE FROM documentation.l_place_release_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_place_release); -DELETE FROM documentation.l_place_release_group_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_place_release_group); -DELETE FROM documentation.l_place_series_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_place_series); -DELETE FROM documentation.l_place_url_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_place_url); -DELETE FROM documentation.l_place_work_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_place_work); -DELETE FROM documentation.l_recording_recording_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_recording_recording); -DELETE FROM documentation.l_recording_release_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_recording_release); -DELETE FROM documentation.l_recording_release_group_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_recording_release_group); -DELETE FROM documentation.l_recording_series_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_recording_series); -DELETE FROM documentation.l_recording_url_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_recording_url); -DELETE FROM documentation.l_recording_work_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_recording_work); -DELETE FROM documentation.l_release_group_release_group_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_release_group_release_group); -DELETE FROM documentation.l_release_group_series_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_release_group_series); -DELETE FROM documentation.l_release_group_url_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_release_group_url); -DELETE FROM documentation.l_release_group_work_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_release_group_work); -DELETE FROM documentation.l_release_release_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_release_release); -DELETE FROM documentation.l_release_release_group_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_release_release_group); -DELETE FROM documentation.l_release_series_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_release_series); -DELETE FROM documentation.l_release_url_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_release_url); -DELETE FROM documentation.l_release_work_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_release_work); -DELETE FROM documentation.l_series_series_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_series_series); -DELETE FROM documentation.l_series_url_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_series_url); -DELETE FROM documentation.l_series_work_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_series_work); -DELETE FROM documentation.l_url_url_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_url_url); -DELETE FROM documentation.l_url_work_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_url_work); -DELETE FROM documentation.l_work_work_example WHERE id NOT IN (SELECT id FROM musicbrainz.l_work_work); -DELETE FROM documentation.link_type_documentation WHERE id NOT IN (SELECT id FROM musicbrainz.link_type); - -ALTER TABLE documentation.l_area_area_example - ADD CONSTRAINT l_area_area_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_area_area(id); - -ALTER TABLE documentation.l_area_artist_example - ADD CONSTRAINT l_area_artist_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_area_artist(id); - -ALTER TABLE documentation.l_area_event_example - ADD CONSTRAINT l_area_event_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_area_event(id); - -ALTER TABLE documentation.l_area_instrument_example - ADD CONSTRAINT l_area_instrument_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_area_instrument(id); - -ALTER TABLE documentation.l_area_label_example - ADD CONSTRAINT l_area_label_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_area_label(id); - -ALTER TABLE documentation.l_area_place_example - ADD CONSTRAINT l_area_place_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_area_place(id); - -ALTER TABLE documentation.l_area_recording_example - ADD CONSTRAINT l_area_recording_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_area_recording(id); - -ALTER TABLE documentation.l_area_release_example - ADD CONSTRAINT l_area_release_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_area_release(id); - -ALTER TABLE documentation.l_area_release_group_example - ADD CONSTRAINT l_area_release_group_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_area_release_group(id); - -ALTER TABLE documentation.l_area_series_example - ADD CONSTRAINT l_area_series_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_area_series(id); - -ALTER TABLE documentation.l_area_url_example - ADD CONSTRAINT l_area_url_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_area_url(id); - -ALTER TABLE documentation.l_area_work_example - ADD CONSTRAINT l_area_work_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_area_work(id); - -ALTER TABLE documentation.l_artist_artist_example - ADD CONSTRAINT l_artist_artist_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_artist_artist(id); - -ALTER TABLE documentation.l_artist_event_example - ADD CONSTRAINT l_artist_event_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_artist_event(id); - -ALTER TABLE documentation.l_artist_instrument_example - ADD CONSTRAINT l_artist_instrument_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_artist_instrument(id); - -ALTER TABLE documentation.l_artist_label_example - ADD CONSTRAINT l_artist_label_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_artist_label(id); - -ALTER TABLE documentation.l_artist_place_example - ADD CONSTRAINT l_artist_place_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_artist_place(id); - -ALTER TABLE documentation.l_artist_recording_example - ADD CONSTRAINT l_artist_recording_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_artist_recording(id); - -ALTER TABLE documentation.l_artist_release_example - ADD CONSTRAINT l_artist_release_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_artist_release(id); - -ALTER TABLE documentation.l_artist_release_group_example - ADD CONSTRAINT l_artist_release_group_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_artist_release_group(id); - -ALTER TABLE documentation.l_artist_series_example - ADD CONSTRAINT l_artist_series_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_artist_series(id); - -ALTER TABLE documentation.l_artist_url_example - ADD CONSTRAINT l_artist_url_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_artist_url(id); - -ALTER TABLE documentation.l_artist_work_example - ADD CONSTRAINT l_artist_work_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_artist_work(id); - -ALTER TABLE documentation.l_event_event_example - ADD CONSTRAINT l_event_event_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_event_event(id); - -ALTER TABLE documentation.l_event_instrument_example - ADD CONSTRAINT l_event_instrument_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_event_instrument(id); - -ALTER TABLE documentation.l_event_label_example - ADD CONSTRAINT l_event_label_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_event_label(id); - -ALTER TABLE documentation.l_event_place_example - ADD CONSTRAINT l_event_place_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_event_place(id); - -ALTER TABLE documentation.l_event_recording_example - ADD CONSTRAINT l_event_recording_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_event_recording(id); - -ALTER TABLE documentation.l_event_release_example - ADD CONSTRAINT l_event_release_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_event_release(id); - -ALTER TABLE documentation.l_event_release_group_example - ADD CONSTRAINT l_event_release_group_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_event_release_group(id); - -ALTER TABLE documentation.l_event_series_example - ADD CONSTRAINT l_event_series_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_event_series(id); - -ALTER TABLE documentation.l_event_url_example - ADD CONSTRAINT l_event_url_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_event_url(id); - -ALTER TABLE documentation.l_event_work_example - ADD CONSTRAINT l_event_work_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_event_work(id); - -ALTER TABLE documentation.l_instrument_instrument_example - ADD CONSTRAINT l_instrument_instrument_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_instrument_instrument(id); - -ALTER TABLE documentation.l_instrument_label_example - ADD CONSTRAINT l_instrument_label_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_instrument_label(id); - -ALTER TABLE documentation.l_instrument_place_example - ADD CONSTRAINT l_instrument_place_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_instrument_place(id); - -ALTER TABLE documentation.l_instrument_recording_example - ADD CONSTRAINT l_instrument_recording_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_instrument_recording(id); - -ALTER TABLE documentation.l_instrument_release_example - ADD CONSTRAINT l_instrument_release_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_instrument_release(id); - -ALTER TABLE documentation.l_instrument_release_group_example - ADD CONSTRAINT l_instrument_release_group_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_instrument_release_group(id); - -ALTER TABLE documentation.l_instrument_series_example - ADD CONSTRAINT l_instrument_series_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_instrument_series(id); - -ALTER TABLE documentation.l_instrument_url_example - ADD CONSTRAINT l_instrument_url_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_instrument_url(id); - -ALTER TABLE documentation.l_instrument_work_example - ADD CONSTRAINT l_instrument_work_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_instrument_work(id); - -ALTER TABLE documentation.l_label_label_example - ADD CONSTRAINT l_label_label_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_label_label(id); - -ALTER TABLE documentation.l_label_place_example - ADD CONSTRAINT l_label_place_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_label_place(id); - -ALTER TABLE documentation.l_label_recording_example - ADD CONSTRAINT l_label_recording_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_label_recording(id); - -ALTER TABLE documentation.l_label_release_example - ADD CONSTRAINT l_label_release_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_label_release(id); - -ALTER TABLE documentation.l_label_release_group_example - ADD CONSTRAINT l_label_release_group_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_label_release_group(id); - -ALTER TABLE documentation.l_label_series_example - ADD CONSTRAINT l_label_series_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_label_series(id); - -ALTER TABLE documentation.l_label_url_example - ADD CONSTRAINT l_label_url_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_label_url(id); - -ALTER TABLE documentation.l_label_work_example - ADD CONSTRAINT l_label_work_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_label_work(id); - -ALTER TABLE documentation.l_place_place_example - ADD CONSTRAINT l_place_place_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_place_place(id); - -ALTER TABLE documentation.l_place_recording_example - ADD CONSTRAINT l_place_recording_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_place_recording(id); - -ALTER TABLE documentation.l_place_release_example - ADD CONSTRAINT l_place_release_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_place_release(id); - -ALTER TABLE documentation.l_place_release_group_example - ADD CONSTRAINT l_place_release_group_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_place_release_group(id); - -ALTER TABLE documentation.l_place_series_example - ADD CONSTRAINT l_place_series_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_place_series(id); - -ALTER TABLE documentation.l_place_url_example - ADD CONSTRAINT l_place_url_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_place_url(id); - -ALTER TABLE documentation.l_place_work_example - ADD CONSTRAINT l_place_work_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_place_work(id); - -ALTER TABLE documentation.l_recording_recording_example - ADD CONSTRAINT l_recording_recording_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_recording_recording(id); - -ALTER TABLE documentation.l_recording_release_example - ADD CONSTRAINT l_recording_release_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_recording_release(id); - -ALTER TABLE documentation.l_recording_release_group_example - ADD CONSTRAINT l_recording_release_group_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_recording_release_group(id); - -ALTER TABLE documentation.l_recording_series_example - ADD CONSTRAINT l_recording_series_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_recording_series(id); - -ALTER TABLE documentation.l_recording_url_example - ADD CONSTRAINT l_recording_url_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_recording_url(id); - -ALTER TABLE documentation.l_recording_work_example - ADD CONSTRAINT l_recording_work_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_recording_work(id); - -ALTER TABLE documentation.l_release_group_release_group_example - ADD CONSTRAINT l_release_group_release_group_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_release_group_release_group(id); - -ALTER TABLE documentation.l_release_group_series_example - ADD CONSTRAINT l_release_group_series_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_release_group_series(id); - -ALTER TABLE documentation.l_release_group_url_example - ADD CONSTRAINT l_release_group_url_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_release_group_url(id); - -ALTER TABLE documentation.l_release_group_work_example - ADD CONSTRAINT l_release_group_work_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_release_group_work(id); - -ALTER TABLE documentation.l_release_release_example - ADD CONSTRAINT l_release_release_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_release_release(id); - -ALTER TABLE documentation.l_release_release_group_example - ADD CONSTRAINT l_release_release_group_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_release_release_group(id); - -ALTER TABLE documentation.l_release_series_example - ADD CONSTRAINT l_release_series_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_release_series(id); - -ALTER TABLE documentation.l_release_url_example - ADD CONSTRAINT l_release_url_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_release_url(id); - -ALTER TABLE documentation.l_release_work_example - ADD CONSTRAINT l_release_work_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_release_work(id); - -ALTER TABLE documentation.l_series_series_example - ADD CONSTRAINT l_series_series_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_series_series(id); - -ALTER TABLE documentation.l_series_url_example - ADD CONSTRAINT l_series_url_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_series_url(id); - -ALTER TABLE documentation.l_series_work_example - ADD CONSTRAINT l_series_work_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_series_work(id); - -ALTER TABLE documentation.l_url_url_example - ADD CONSTRAINT l_url_url_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_url_url(id); - -ALTER TABLE documentation.l_url_work_example - ADD CONSTRAINT l_url_work_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_url_work(id); - -ALTER TABLE documentation.l_work_work_example - ADD CONSTRAINT l_work_work_example_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.l_work_work(id); - -ALTER TABLE documentation.link_type_documentation - ADD CONSTRAINT link_type_documentation_fk_id - FOREIGN KEY (id) - REFERENCES musicbrainz.link_type(id); - -COMMIT; diff --git a/poetry.lock b/poetry.lock index 3b22658..b8a6c87 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,10 +1,9 @@ -# This file is automatically @generated by Poetry and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "attrs" version = "22.1.0" description = "Classes Without Boilerplate" -category = "dev" optional = false python-versions = ">=3.5" files = [ @@ -22,7 +21,6 @@ tests-no-zope = ["cloudpickle", "coverage[toml] (>=5.0.2)", "hypothesis", "mypy name = "colorama" version = "0.4.6" description = "Cross-platform colored terminal text." -category = "dev" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" files = [ @@ -34,7 +32,6 @@ files = [ name = "exceptiongroup" version = "1.0.2" description = "Backport of PEP 654 (exception groups)" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -49,7 +46,6 @@ test = ["pytest (>=6)"] name = "flake8" version = "5.0.4" description = "the modular source code checker: pep8 pyflakes and co" -category = "dev" optional = false python-versions = ">=3.6.1" files = [ @@ -67,7 +63,6 @@ pyflakes = ">=2.5.0,<2.6.0" name = "greenlet" version = "1.1.2" description = "Lightweight in-process concurrent programming" -category = "main" optional = true python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*" files = [ @@ -135,7 +130,6 @@ docs = ["Sphinx"] name = "importlib-metadata" version = "4.2.0" description = "Read metadata from Python packages" -category = "main" optional = false python-versions = ">=3.6" files = [ @@ -155,7 +149,6 @@ testing = ["flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pep517", name = "iniconfig" version = "1.1.1" description = "iniconfig: brain-dead simple config-ini parsing" -category = "dev" optional = false python-versions = "*" files = [ @@ -167,7 +160,6 @@ files = [ name = "lxml" version = "4.9.1" description = "Powerful and Pythonic XML processing library combining libxml2/libxslt with the ElementTree API." -category = "main" optional = true python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, != 3.4.*" files = [ @@ -253,7 +245,6 @@ source = ["Cython (>=0.29.7)"] name = "mccabe" version = "0.7.0" description = "McCabe checker, plugin for flake8" -category = "dev" optional = false python-versions = ">=3.6" files = [ @@ -265,7 +256,6 @@ files = [ name = "mypy" version = "0.991" description = "Optional static typing for Python" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -317,7 +307,6 @@ reports = ["lxml"] name = "mypy-extensions" version = "0.4.3" description = "Experimental type system extensions for programs checked with the mypy typechecker." -category = "dev" optional = false python-versions = "*" files = [ @@ -329,7 +318,6 @@ files = [ name = "packaging" version = "21.3" description = "Core utilities for Python packages" -category = "dev" optional = false python-versions = ">=3.6" files = [ @@ -344,7 +332,6 @@ pyparsing = ">=2.0.2,<3.0.5 || >3.0.5" name = "pluggy" version = "1.0.0" description = "plugin and hook calling mechanisms for python" -category = "dev" optional = false python-versions = ">=3.6" files = [ @@ -363,7 +350,6 @@ testing = ["pytest", "pytest-benchmark"] name = "psycopg2" version = "2.9.3" description = "psycopg2 - Python-PostgreSQL Database Adapter" -category = "main" optional = false python-versions = ">=3.6" files = [ @@ -384,7 +370,6 @@ files = [ name = "pycodestyle" version = "2.9.1" description = "Python style guide checker" -category = "dev" optional = false python-versions = ">=3.6" files = [ @@ -396,7 +381,6 @@ files = [ name = "pyflakes" version = "2.5.0" description = "passive checker of Python programs" -category = "dev" optional = false python-versions = ">=3.6" files = [ @@ -408,7 +392,6 @@ files = [ name = "pyparsing" version = "3.0.9" description = "pyparsing module - Classes and methods to define and execute parsing grammars" -category = "dev" optional = false python-versions = ">=3.6.8" files = [ @@ -423,7 +406,6 @@ diagrams = ["jinja2", "railroad-diagrams"] name = "pytest" version = "7.2.0" description = "pytest: simple powerful testing with Python" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -448,7 +430,6 @@ testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2. name = "six" version = "1.16.0" description = "Python 2 and 3 compatibility utilities" -category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" files = [ @@ -460,7 +441,6 @@ files = [ name = "sqlalchemy" version = "1.4.36" description = "Database Abstraction Library" -category = "main" optional = true python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,>=2.7" files = [ @@ -531,7 +511,6 @@ sqlcipher = ["sqlcipher3-binary"] name = "sqlparse" version = "0.4.4" description = "A non-validating SQL parser." -category = "dev" optional = false python-versions = ">=3.5" files = [ @@ -548,7 +527,6 @@ test = ["pytest", "pytest-cov"] name = "tomli" version = "2.0.1" description = "A lil' TOML parser" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -560,7 +538,6 @@ files = [ name = "typed-ast" version = "1.5.4" description = "a fork of Python 2 and 3 ast modules with type comment support" -category = "dev" optional = false python-versions = ">=3.6" files = [ @@ -594,7 +571,6 @@ files = [ name = "types-psycopg2" version = "2.9.21.2" description = "Typing stubs for psycopg2" -category = "dev" optional = false python-versions = "*" files = [ @@ -606,7 +582,6 @@ files = [ name = "types-six" version = "1.16.21.4" description = "Typing stubs for six" -category = "dev" optional = false python-versions = "*" files = [ @@ -618,7 +593,6 @@ files = [ name = "typing-extensions" version = "4.1.1" description = "Backported and Experimental Type Hints for Python 3.6+" -category = "main" optional = false python-versions = ">=3.6" files = [ @@ -630,7 +604,6 @@ files = [ name = "zipp" version = "3.6.0" description = "Backport of pathlib-compatible object wrapper for zip files" -category = "main" optional = false python-versions = ">=3.6" files = [ @@ -644,10 +617,9 @@ testing = ["func-timeout", "jaraco.itertools", "pytest (>=4.6)", "pytest-black ( [extras] models = ["SQLAlchemy"] -replication = ["psycopg2"] search = ["lxml"] [metadata] lock-version = "2.0" python-versions = "^3.7" -content-hash = "9b9ce36e87d5112fed61144caebc2fb8c2885e3f404179f9f45e037665d5fd2e" +content-hash = "dfeb38a20fc3902d06af167f5fe6d8da0c1e919d311977180e28bb64b91372d8"