1 -- @tag: acc_trans_without_oid
2 -- @description: Einführen einer ID-Spalte in acc_trans
3 -- @depends: release_2_4_3 cb_ob_transaction
5 -- INFO: Dieses Script hat früher die Spalte acc_trans_id aus der
6 -- impliziten OID gesetzt. PostgreSQL 12 unterstützt aber keine OIDs
7 -- mehr, daher wurde die OID hier entfernt. Das ist insofern auch kein
8 -- Problem, weil dieses Upgrade-Script in Version 2.6.0 benutzt wurde,
9 -- und direkte Updates auf die aktuelle kivitendo-Version von vor 3.0
10 -- eh nicht mehr unterstützt werden.
12 -- Das Script muss aber trotzdem beim Anlegen neuer Datenbanken
13 -- abgearbeitet werden und daher funktionieren.
15 CREATE SEQUENCE acc_trans_id_seq;
17 CREATE TABLE new_acc_trans (
18 acc_trans_id bigint DEFAULT nextval('acc_trans_id_seq'),
22 transdate date DEFAULT date('now'::text),
23 gldate date DEFAULT date('now'::text),
25 cleared boolean DEFAULT false,
26 fx_transaction boolean DEFAULT false,
27 ob_transaction boolean DEFAULT false,
28 cb_transaction boolean DEFAULT false,
32 itime timestamp without time zone DEFAULT now(),
33 mtime timestamp without time zone
36 INSERT INTO new_acc_trans (trans_id, chart_id, amount, transdate, gldate, source, cleared,
37 fx_transaction, ob_transaction, cb_transaction, project_id, memo, taxkey, itime, mtime)
38 SELECT trans_id, chart_id, amount, transdate, gldate, source, cleared,
39 fx_transaction, ob_transaction, cb_transaction, project_id, memo, taxkey, itime, mtime
43 ALTER TABLE new_acc_trans RENAME TO acc_trans;
45 CREATE INDEX acc_trans_trans_id_key ON acc_trans USING btree (trans_id);
46 CREATE INDEX acc_trans_chart_id_key ON acc_trans USING btree (chart_id);
47 CREATE INDEX acc_trans_transdate_key ON acc_trans USING btree (transdate);
48 CREATE INDEX acc_trans_source_key ON acc_trans USING btree (lower(source));
50 ALTER TABLE ONLY acc_trans
51 ADD CONSTRAINT "$1" FOREIGN KEY (chart_id) REFERENCES chart(id);
53 CREATE TRIGGER mtime_acc_trans
54 BEFORE UPDATE ON acc_trans
56 EXECUTE PROCEDURE set_mtime();