3 SELECT evergreen.upgrade_deps_block_check('0779', :eg_version);
5 CREATE TABLE vandelay.import_bib_trash_group(
7 owner INT NOT NULL REFERENCES actor.org_unit(id),
8 label TEXT NOT NULL, --i18n
9 always_apply BOOLEAN NOT NULL DEFAULT FALSE,
10 CONSTRAINT vand_import_bib_trash_grp_owner_label UNIQUE (owner, label)
13 -- otherwise, the ALTER TABLE statement below
14 -- will fail with pending trigger events.
15 SET CONSTRAINTS ALL IMMEDIATE;
17 ALTER TABLE vandelay.import_bib_trash_fields
18 -- allow null-able for now..
19 ADD COLUMN grp INTEGER REFERENCES vandelay.import_bib_trash_group;
21 -- add any existing trash_fields to "Legacy" groups (one per unique field
22 -- owner) as part of the upgrade, since grp is now required.
23 -- note that vandelay.import_bib_trash_fields was never used before,
24 -- so in most cases this should be a no-op.
26 INSERT INTO vandelay.import_bib_trash_group (owner, label)
27 SELECT DISTINCT(owner), 'Legacy' FROM vandelay.import_bib_trash_fields;
29 UPDATE vandelay.import_bib_trash_fields field SET grp = tgroup.id
30 FROM vandelay.import_bib_trash_group tgroup
31 WHERE tgroup.owner = field.owner;
33 ALTER TABLE vandelay.import_bib_trash_fields
34 -- now that have values, we can make this non-null
35 ALTER COLUMN grp SET NOT NULL,
36 -- drop outdated constraint
37 DROP CONSTRAINT vand_import_bib_trash_fields_idx,
38 -- owner is implied by the grp
40 -- make grp+field unique
41 ADD CONSTRAINT vand_import_bib_trash_fields_once_per UNIQUE (grp, field);