-- Generated by CompileSchemaScripts.pl from:
-- 20220302-mbs-12225-mirror_only.sql
-- 20220408-mbs-12249-mirror_only.sql
-- 20220328-mbs-12250-mirror_only.sql
-- 20220426-mbs-12131-master-mirror.sql
\set ON_ERROR_STOP 1
BEGIN;
SET search_path = musicbrainz, public;
SET LOCAL statement_timeout = 0;
--------------------------------------------------------------------------------
SELECT '20220302-mbs-12225-mirror_only.sql';


ALTER TRIGGER apply_artist_release_group_pending_updates_slave ON release RENAME TO apply_artist_release_group_pending_updates_mirror;
ALTER TRIGGER apply_artist_release_group_pending_updates_slave ON release_group RENAME TO apply_artist_release_group_pending_updates_mirror;
ALTER TRIGGER apply_artist_release_group_pending_updates_slave ON release_group_meta RENAME TO apply_artist_release_group_pending_updates_mirror;
ALTER TRIGGER apply_artist_release_group_pending_updates_slave ON release_group_secondary_type_join RENAME TO apply_artist_release_group_pending_updates_mirror;
ALTER TRIGGER apply_artist_release_group_pending_updates_slave ON track RENAME TO apply_artist_release_group_pending_updates_mirror;
ALTER TRIGGER apply_artist_release_pending_updates_slave ON release RENAME TO apply_artist_release_pending_updates_mirror;
ALTER TRIGGER apply_artist_release_pending_updates_slave ON release_country RENAME TO apply_artist_release_pending_updates_mirror;
ALTER TRIGGER apply_artist_release_pending_updates_slave ON release_first_release_date RENAME TO apply_artist_release_pending_updates_mirror;
ALTER TRIGGER apply_artist_release_pending_updates_slave ON release_label RENAME TO apply_artist_release_pending_updates_mirror;
ALTER TRIGGER apply_artist_release_pending_updates_slave ON track RENAME TO apply_artist_release_pending_updates_mirror;

ALTER TRIGGER a_ins_release_slave ON release RENAME TO a_ins_release_mirror;
ALTER TRIGGER a_upd_release_slave ON release RENAME TO a_upd_release_mirror;
ALTER TRIGGER a_del_release_slave ON release RENAME TO a_del_release_mirror;
ALTER TRIGGER a_ins_release_event_slave ON release_country RENAME TO a_ins_release_event_mirror;
ALTER TRIGGER a_upd_release_event_slave ON release_country RENAME TO a_upd_release_event_mirror;
ALTER TRIGGER a_del_release_event_slave ON release_country RENAME TO a_del_release_event_mirror;
ALTER TRIGGER a_ins_release_event_slave ON release_unknown_country RENAME TO a_ins_release_event_mirror;
ALTER TRIGGER a_upd_release_event_slave ON release_unknown_country RENAME TO a_upd_release_event_mirror;
ALTER TRIGGER a_del_release_event_slave ON release_unknown_country RENAME TO a_del_release_event_mirror;
ALTER TRIGGER a_ins_release_group_slave ON release_group RENAME TO a_ins_release_group_mirror;
ALTER TRIGGER a_upd_release_group_slave ON release_group RENAME TO a_upd_release_group_mirror;
ALTER TRIGGER a_del_release_group_slave ON release_group RENAME TO a_del_release_group_mirror;
ALTER TRIGGER a_upd_release_group_meta_slave ON release_group_meta RENAME TO a_upd_release_group_meta_mirror;
ALTER TRIGGER a_ins_release_group_secondary_type_join_slave ON release_group_secondary_type_join RENAME TO a_ins_release_group_secondary_type_join_mirror;
ALTER TRIGGER a_del_release_group_secondary_type_join_slave ON release_group_secondary_type_join RENAME TO a_del_release_group_secondary_type_join_mirror;
ALTER TRIGGER a_ins_release_label_slave ON release_label RENAME TO a_ins_release_label_mirror;
ALTER TRIGGER a_upd_release_label_slave ON release_label RENAME TO a_upd_release_label_mirror;
ALTER TRIGGER a_del_release_label_slave ON release_label RENAME TO a_del_release_label_mirror;
ALTER TRIGGER a_ins_track_slave ON track RENAME TO a_ins_track_mirror;
ALTER TRIGGER a_upd_track_slave ON track RENAME TO a_upd_track_mirror;
ALTER TRIGGER a_del_track_slave ON track RENAME TO a_del_track_mirror;

ALTER FUNCTION a_ins_release_slave() RENAME TO a_ins_release_mirror;
ALTER FUNCTION a_upd_release_slave() RENAME TO a_upd_release_mirror;
ALTER FUNCTION a_del_release_slave() RENAME TO a_del_release_mirror;
ALTER FUNCTION a_ins_release_event_slave() RENAME TO a_ins_release_event_mirror;
ALTER FUNCTION a_upd_release_event_slave() RENAME TO a_upd_release_event_mirror;
ALTER FUNCTION a_del_release_event_slave() RENAME TO a_del_release_event_mirror;
ALTER FUNCTION a_ins_release_group_slave() RENAME TO a_ins_release_group_mirror;
ALTER FUNCTION a_upd_release_group_slave() RENAME TO a_upd_release_group_mirror;
ALTER FUNCTION a_del_release_group_slave() RENAME TO a_del_release_group_mirror;
ALTER FUNCTION a_upd_release_group_meta_slave() RENAME TO a_upd_release_group_meta_mirror;
ALTER FUNCTION a_ins_release_group_secondary_type_join_slave() RENAME TO a_ins_release_group_secondary_type_join_mirror;
ALTER FUNCTION a_del_release_group_secondary_type_join_slave() RENAME TO a_del_release_group_secondary_type_join_mirror;
ALTER FUNCTION a_ins_release_label_slave() RENAME TO a_ins_release_label_mirror;
ALTER FUNCTION a_upd_release_label_slave() RENAME TO a_upd_release_label_mirror;
ALTER FUNCTION a_del_release_label_slave() RENAME TO a_del_release_label_mirror;
ALTER FUNCTION a_ins_track_slave() RENAME TO a_ins_track_mirror;
ALTER FUNCTION a_upd_track_slave() RENAME TO a_upd_track_mirror;
ALTER FUNCTION a_del_track_slave() RENAME TO a_del_track_mirror;

--------------------------------------------------------------------------------
SELECT '20220408-mbs-12249-mirror_only.sql';


DROP TRIGGER IF EXISTS a_ins_l_area_area_mirror ON l_area_area;

CREATE TRIGGER a_ins_l_area_area_mirror 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_mirror ON l_area_area;

CREATE TRIGGER a_upd_l_area_area_mirror 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_mirror ON l_area_area;

CREATE TRIGGER a_del_l_area_area_mirror AFTER DELETE ON l_area_area
    FOR EACH ROW EXECUTE PROCEDURE a_del_l_area_area_mirror();

--------------------------------------------------------------------------------
SELECT '20220328-mbs-12250-mirror_only.sql';


CREATE TABLE dbmirror2.pending_keys (
    tablename   TEXT,
    keys        TEXT[] NOT NULL
);

ALTER TABLE dbmirror2.pending_keys
    ADD CONSTRAINT pending_keys_pkey
    PRIMARY KEY (tablename);

CREATE TABLE dbmirror2.pending_ts (
    xid BIGINT,
    ts TIMESTAMP WITH TIME ZONE NOT NULL
);

ALTER TABLE dbmirror2.pending_ts
    ADD CONSTRAINT pending_ts_pkey
    PRIMARY KEY (xid);

CREATE TABLE dbmirror2.pending_data (
    seqid       BIGSERIAL,
    tablename   TEXT NOT NULL CONSTRAINT tablename_exists CHECK (to_regclass(tablename) IS NOT NULL),
    op          "char" NOT NULL CONSTRAINT op_in_diu CHECK (op IN ('d', 'i', 'u')),
    xid         BIGINT NOT NULL,
    olddata     JSON CONSTRAINT olddata_is_null_for_inserts CHECK ((olddata IS NULL) = (op = 'i')),
    newdata     JSON CONSTRAINT newdata_is_null_for_deletes CHECK ((newdata IS NULL) = (op = 'd')),
    oldctid     TID,
    trgdepth    INTEGER
);

ALTER TABLE dbmirror2.pending_data
    ADD CONSTRAINT pending_data_pkey
    PRIMARY KEY (seqid);

CREATE INDEX pending_data_idx_xid_seqid
    ON dbmirror2.pending_data (xid, seqid);

CREATE INDEX pending_data_idx_oldctid_xid
    ON dbmirror2.pending_data (oldctid, xid);

--------------------------------------------------------------------------------
SELECT '20220426-mbs-12131-master-mirror.sql';


DROP AGGREGATE IF EXISTS array_cat_agg(anyarray);

CREATE OR REPLACE AGGREGATE array_cat_agg(int2[]) (
      sfunc       = array_cat,
      stype       = int2[],
      initcond    = '{}'
);

COMMIT;
