CREATE TABLE acq.lineitem_note (
id SERIAL PRIMARY KEY,
- lineitem INT NOT NULL REFERENCES acq.lineitem (id) DEFERRABLE INITIALLY DEFERRED,
+ lineitem INT NOT NULL REFERENCES acq.lineitem (id) ON CASCADE DELETE DEFERRABLE INITIALLY DEFERRED,
creator INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
editor INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
create_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
CREATE TABLE acq.lineitem_detail (
id BIGSERIAL PRIMARY KEY,
- lineitem INT NOT NULL REFERENCES acq.lineitem (id) DEFERRABLE INITIALLY DEFERRED,
+ lineitem INT NOT NULL REFERENCES acq.lineitem (id) ON CASCADE DELETE DEFERRABLE INITIALLY DEFERRED,
fund INT REFERENCES acq.fund (id) DEFERRABLE INITIALLY DEFERRED,
fund_debit INT REFERENCES acq.fund_debit (id) DEFERRABLE INITIALLY DEFERRED,
eg_copy_id BIGINT REFERENCES asset.copy (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED,
CREATE TABLE acq.lineitem_attr (
id BIGSERIAL PRIMARY KEY,
definition BIGINT NOT NULL,
- lineitem BIGINT NOT NULL REFERENCES acq.lineitem (id) DEFERRABLE INITIALLY DEFERRED,
+ lineitem BIGINT NOT NULL REFERENCES acq.lineitem (id) ON CASCADE DELETE DEFERRABLE INITIALLY DEFERRED,
attr_type TEXT NOT NULL,
attr_name TEXT NOT NULL,
attr_value TEXT NOT NULL
formula INT NOT NULL
REFERENCES acq.distribution_formula(id) DEFERRABLE INITIALLY DEFERRED,
lineitem INT NOT NULL
- REFERENCES acq.lineitem(id) DEFERRABLE INITIALLY DEFERRED
+ REFERENCES acq.lineitem(id) ON CASCADE DELETE DEFERRABLE INITIALLY DEFERRED
);
CREATE INDEX acqdfa_df_idx
--- /dev/null
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0186'); -- Scott McKellar
+
+ALTER TABLE acq.distribution_formula_application
+ DROP CONSTRAINT distribution_formula_application_lineitem_fkey;
+
+ALTER TABLE acq.distribution_formula_application
+ ADD FOREIGN KEY (lineitem) REFERENCES acq.lineitem( id )
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED;
+
+ALTER TABLE acq.lineitem_attr
+ DROP CONSTRAINT lineitem_attr_lineitem_fkey;
+
+ALTER TABLE acq.lineitem_attr
+ ADD FOREIGN KEY (lineitem) REFERENCES acq.lineitem( id )
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED;
+
+ALTER TABLE acq.lineitem_detail
+ DROP CONSTRAINT lineitem_detail_lineitem_fkey;
+
+ALTER TABLE acq.lineitem_detail
+ ADD FOREIGN KEY (lineitem) REFERENCES acq.lineitem( id )
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED;
+
+ALTER TABLE acq.lineitem_note
+ DROP CONSTRAINT lineitem_note_lineitem_fkey;
+
+ALTER TABLE acq.lineitem_note
+ ADD FOREIGN KEY (lineitem) REFERENCES acq.lineitem( id )
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED;
+
+COMMIT;