Skip to content

Commit

Permalink
update schema 2024-05-13 SQL files
Browse files Browse the repository at this point in the history
  • Loading branch information
sfussenegger committed May 17, 2024
1 parent d32e188 commit 6024bc6
Show file tree
Hide file tree
Showing 19 changed files with 200 additions and 7 deletions.
5 changes: 3 additions & 2 deletions mbslave/sql/CreateConstraints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
Expand Down Expand Up @@ -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)),
Expand Down
10 changes: 10 additions & 0 deletions mbslave/sql/CreateFKConstraints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -667,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)
Expand Down
2 changes: 1 addition & 1 deletion mbslave/sql/CreateIndexes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);

Expand Down
1 change: 1 addition & 0 deletions mbslave/sql/CreatePrimaryKeys.sql
Original file line number Diff line number Diff line change
Expand Up @@ -70,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);
Expand Down
11 changes: 9 additions & 2 deletions mbslave/sql/CreateTables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2467,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 '',
Expand Down Expand Up @@ -2729,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,
Expand Down Expand Up @@ -2801,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
Expand Down
2 changes: 2 additions & 0 deletions mbslave/sql/DropFKConstraints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -130,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;
Expand Down
1 change: 1 addition & 0 deletions mbslave/sql/DropPrimaryKeys.sql
Original file line number Diff line number Diff line change
Expand Up @@ -70,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;
Expand Down
1 change: 1 addition & 0 deletions mbslave/sql/DropTables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -74,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;
Expand Down
3 changes: 3 additions & 0 deletions mbslave/sql/InsertTestData.sql
Original file line number Diff line number Diff line change
Expand Up @@ -253,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);
Expand Down
1 change: 1 addition & 0 deletions mbslave/sql/TruncateTables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -74,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;
Expand Down
4 changes: 2 additions & 2 deletions mbslave/sql/updates/20220720-mbs-12508.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ then
FTP_DATA_URL='http://ftp.musicbrainz.org/pub/musicbrainz/data'

echo `date`: Retrieving LATEST from FTP
LATEST=$(curl "$FTP_DATA_URL"/fullexport/LATEST)
LATEST=$(curl -sSL "$FTP_DATA_URL"/fullexport/LATEST)

echo `date`: Retrieving mbdump-derived.tar.bz2 from FTP
curl \
curl -L \
-o "$DUMP_FILE" \
"$FTP_DATA_URL"/fullexport/"$LATEST"/mbdump-derived.tar.bz2
fi
Expand Down
17 changes: 17 additions & 0 deletions mbslave/sql/updates/20231005-edit-data-idx-link-type.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
\set ON_ERROR_STOP 1

BEGIN;

DROP INDEX IF EXISTS edit_data_idx_link_type;

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

COMMIT;
7 changes: 7 additions & 0 deletions mbslave/sql/updates/20240220-mbs-13403.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
\set ON_ERROR_STOP 1

BEGIN;

ALTER TABLE link_type DROP COLUMN priority CASCADE;

COMMIT;
17 changes: 17 additions & 0 deletions mbslave/sql/updates/20240223-mbs-13421-fks.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
\set ON_ERROR_STOP 1
BEGIN;

ALTER TABLE editor_collection_type -- Already dropped in mirror update script
ADD CONSTRAINT allowed_collection_entity_type CHECK (
entity_type IN ('area', 'artist', 'event', 'genre', 'instrument', 'label', 'place', 'recording', 'release', 'release_group', 'series', 'work')
);

ALTER TABLE editor_collection_genre
ADD CONSTRAINT editor_collection_genre_fk_collection
FOREIGN KEY (collection)
REFERENCES editor_collection(id),
ADD CONSTRAINT editor_collection_genre_fk_genre
FOREIGN KEY (genre)
REFERENCES genre(id);

COMMIT;
20 changes: 20 additions & 0 deletions mbslave/sql/updates/20240223-mbs-13421.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
\set ON_ERROR_STOP 1
BEGIN;

CREATE TABLE editor_collection_genre (
collection INTEGER NOT NULL,
genre INTEGER NOT NULL,
added TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
position INTEGER NOT NULL DEFAULT 0 CHECK (position >= 0),
comment TEXT DEFAULT '' NOT NULL
);

ALTER TABLE editor_collection_genre ADD CONSTRAINT editor_collection_genre_pkey PRIMARY KEY (collection, genre);

ALTER TABLE editor_collection_type
DROP CONSTRAINT IF EXISTS allowed_collection_entity_type;

INSERT INTO editor_collection_type (id, name, entity_type, parent, child_order, gid)
VALUES (16, 'Genre', 'genre', NULL, 2, generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'editor_collection_type' || 16));

COMMIT;
9 changes: 9 additions & 0 deletions mbslave/sql/updates/20240319-mbs-13514-mirror.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
\set ON_ERROR_STOP 1

BEGIN;

ALTER TABLE label DROP CONSTRAINT IF EXISTS label_label_code_check;

ALTER TABLE label DROP CONSTRAINT IF EXISTS label_code_length;

COMMIT;
7 changes: 7 additions & 0 deletions mbslave/sql/updates/20240319-mbs-13514.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
\set ON_ERROR_STOP 1

BEGIN;

ALTER TABLE label ADD CONSTRAINT label_code_length CHECK (label_code > 0 AND label_code < 1000000);

COMMIT;
59 changes: 59 additions & 0 deletions mbslave/sql/updates/schema-change/29.all.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- Generated by CompileSchemaScripts.pl from:
-- 20231005-edit-data-idx-link-type.sql
-- 20240220-mbs-13403.sql
-- 20240223-mbs-13421.sql
-- 20240319-mbs-13514-mirror.sql
\set ON_ERROR_STOP 1
BEGIN;
SET search_path = musicbrainz, public;
SET LOCAL statement_timeout = 0;
--------------------------------------------------------------------------------
SELECT '20231005-edit-data-idx-link-type.sql';


DROP INDEX IF EXISTS edit_data_idx_link_type;

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 '20240220-mbs-13403.sql';


ALTER TABLE link_type DROP COLUMN priority CASCADE;

--------------------------------------------------------------------------------
SELECT '20240223-mbs-13421.sql';

CREATE TABLE editor_collection_genre (
collection INTEGER NOT NULL,
genre INTEGER NOT NULL,
added TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
position INTEGER NOT NULL DEFAULT 0 CHECK (position >= 0),
comment TEXT DEFAULT '' NOT NULL
);

ALTER TABLE editor_collection_genre ADD CONSTRAINT editor_collection_genre_pkey PRIMARY KEY (collection, genre);

ALTER TABLE editor_collection_type
DROP CONSTRAINT IF EXISTS allowed_collection_entity_type;

INSERT INTO editor_collection_type (id, name, entity_type, parent, child_order, gid)
VALUES (16, 'Genre', 'genre', NULL, 2, generate_uuid_v3('6ba7b8119dad11d180b400c04fd430c8', 'editor_collection_type' || 16));

--------------------------------------------------------------------------------
SELECT '20240319-mbs-13514-mirror.sql';


ALTER TABLE label DROP CONSTRAINT IF EXISTS label_label_code_check;

ALTER TABLE label DROP CONSTRAINT IF EXISTS label_code_length;

COMMIT;
30 changes: 30 additions & 0 deletions mbslave/sql/updates/schema-change/29.master_and_standalone.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- Generated by CompileSchemaScripts.pl from:
-- 20240223-mbs-13421-fks.sql
-- 20240319-mbs-13514.sql
\set ON_ERROR_STOP 1
BEGIN;
SET search_path = musicbrainz, public;
SET LOCAL statement_timeout = 0;
--------------------------------------------------------------------------------
SELECT '20240223-mbs-13421-fks.sql';

ALTER TABLE editor_collection_type -- Already dropped in mirror update script
ADD CONSTRAINT allowed_collection_entity_type CHECK (
entity_type IN ('area', 'artist', 'event', 'genre', 'instrument', 'label', 'place', 'recording', 'release', 'release_group', 'series', 'work')
);

ALTER TABLE editor_collection_genre
ADD CONSTRAINT editor_collection_genre_fk_collection
FOREIGN KEY (collection)
REFERENCES editor_collection(id),
ADD CONSTRAINT editor_collection_genre_fk_genre
FOREIGN KEY (genre)
REFERENCES genre(id);

--------------------------------------------------------------------------------
SELECT '20240319-mbs-13514.sql';


ALTER TABLE label ADD CONSTRAINT label_code_length CHECK (label_code > 0 AND label_code < 1000000);

COMMIT;

0 comments on commit 6024bc6

Please sign in to comment.