CREATE TABLE asset.copy_alert (
id bigserial primary key,
alert_type int not null references config.copy_alert_type (id) on delete cascade,
- copy bigint not null references asset.copy (id) on delete cascade,
+ copy bigint not null,
temp bool not null default false,
create_time timestamptz not null default now(),
create_staff bigint not null references actor.usr (id) on delete set null,
END;
$f$ LANGUAGE PLPGSQL VOLATILE COST 50;
+CREATE OR REPLACE FUNCTION evergreen.asset_copy_alert_copy_inh_fkey() RETURNS TRIGGER AS $f$
+BEGIN
+ PERFORM 1 FROM asset.copy WHERE id = NEW.copy;
+ IF NOT FOUND THEN
+ RAISE foreign_key_violation USING MESSAGE = FORMAT(
+ $$Referenced asset.copy id not found, copy:%s$$, NEW.copy
+ );
+ END IF;
+ RETURN NEW;
+END;
+$f$ LANGUAGE PLPGSQL VOLATILE COST 50;
+
+CREATE CONSTRAINT TRIGGER inherit_asset_copy_alert_copy_fkey
+ AFTER UPDATE OR INSERT ON asset.copy_alert
+ DEFERRABLE FOR EACH ROW EXECUTE PROCEDURE evergreen.asset_copy_alert_copy_inh_fkey();
+
CREATE CONSTRAINT TRIGGER inherit_asset_copy_tag_copy_map_copy_fkey
AFTER UPDATE OR INSERT ON asset.copy_tag_copy_map
DEFERRABLE FOR EACH ROW EXECUTE PROCEDURE evergreen.asset_copy_tag_copy_map_copy_inh_fkey();
-- staff-usable alert types with no location awareness
INSERT INTO config.copy_alert_type (id, scope_org, active, name, state, event, in_renew)
-VALUES (1, 1, FALSE, 'Normal checkout', 'NORMAL', 'CHECKOUT', FALSE);
+VALUES (1, 1, TRUE, 'Normal checkout', 'NORMAL', 'CHECKOUT', FALSE);
INSERT INTO config.copy_alert_type (id, scope_org, active, name, state, event, in_renew)
-VALUES (2, 1, FALSE, 'Normal checkin', 'NORMAL', 'CHECKIN', FALSE);
+VALUES (2, 1, TRUE, 'Normal checkin', 'NORMAL', 'CHECKIN', FALSE);
INSERT INTO config.copy_alert_type (id, scope_org, active, name, state, event, in_renew)
VALUES (3, 1, FALSE, 'Normal renewal', 'NORMAL', 'CHECKIN', TRUE);
);
SELECT SETVAL('config.copy_alert_type_id_seq'::TEXT, 100);
+CREATE OR REPLACE FUNCTION evergreen.asset_copy_alert_copy_inh_fkey() RETURNS TRIGGER AS $f$
+BEGIN
+ PERFORM 1 FROM asset.copy WHERE id = NEW.copy;
+ IF NOT FOUND THEN
+ RAISE foreign_key_violation USING MESSAGE = FORMAT(
+ $$Referenced asset.copy id not found, copy:%s$$, NEW.copy
+ );
+ END IF;
+ RETURN NEW;
+END;
+$f$ LANGUAGE PLPGSQL VOLATILE COST 50;
+
+CREATE CONSTRAINT TRIGGER inherit_asset_copy_alert_copy_fkey
+ AFTER UPDATE OR INSERT ON asset.copy_alert
+ DEFERRABLE FOR EACH ROW EXECUTE PROCEDURE evergreen.asset_copy_alert_copy_inh_fkey();
+
CREATE TABLE actor.copy_alert_suppress (
id serial primary key,
org int not null references actor.org_unit (id) on delete cascade,
CREATE TABLE asset.copy_alert (
id bigserial primary key,
alert_type int not null references config.copy_alert_type (id) on delete cascade,
- copy bigint not null references asset.copy (id) on delete cascade,
+ copy bigint not null,
temp bool not null default false,
create_time timestamptz not null default now(),
create_staff bigint not null references actor.usr (id) on delete set null,
-- staff-usable alert types with no location awareness
INSERT INTO config.copy_alert_type (id, scope_org, active, name, state, event, in_renew)
-VALUES (1, 1, FALSE, 'Normal checkout', 'NORMAL', 'CHECKOUT', FALSE);
+VALUES (1, 1, TRUE, 'Normal checkout', 'NORMAL', 'CHECKOUT', FALSE);
INSERT INTO config.copy_alert_type (id, scope_org, active, name, state, event, in_renew)
-VALUES (2, 1, FALSE, 'Normal checkin', 'NORMAL', 'CHECKIN', FALSE);
+VALUES (2, 1, TRUE, 'Normal checkin', 'NORMAL', 'CHECKIN', FALSE);
INSERT INTO config.copy_alert_type (id, scope_org, active, name, state, event, in_renew)
VALUES (3, 1, FALSE, 'Normal renewal', 'NORMAL', 'CHECKIN', TRUE);
--- /dev/null
+BEGIN;
+
+--- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+\qecho Copying copy alert messages to normal checkout copy alerts...
+INSERT INTO asset.copy_alert (alert_type, copy, note, create_staff)
+SELECT 1, id, alert_message, 1
+FROM asset.copy
+WHERE alert_message IS NOT NULL
+AND alert_message <> '';
+
+\qecho Copying copy alert messages to normal checkin copy alerts...
+INSERT INTO asset.copy_alert (alert_type, copy, note, create_staff)
+SELECT 2, id, alert_message, 1
+FROM asset.copy
+WHERE alert_message IS NOT NULL
+AND alert_message <> '';
+
+\qecho Clearing legacy copy alert field; this may take a while
+UPDATE asset.copy SET alert_message = NULL
+WHERE alert_message IS NOT NULL;
+
+COMMIT;