Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / rt / etc / upgrade / 4.1.1 / schema.Pg
1 DROP TABLE IF EXISTS ObjectScrips;
2 DROP SEQUENCE IF EXISTS objectscrips_id_seq;
3
4 CREATE SEQUENCE objectscrips_id_seq;
5 CREATE TABLE ObjectScrips (
6   id INTEGER DEFAULT nextval('objectscrips_id_seq'),
7   Scrip integer NOT NULL,
8   Stage varchar(32) NOT NULL DEFAULT 'TransactionCreate' ,
9   ObjectId integer NOT NULL,
10   SortOrder integer NOT NULL DEFAULT 0  ,
11
12   Creator integer NOT NULL DEFAULT 0  ,
13   Created TIMESTAMP NULL  ,
14   LastUpdatedBy integer NOT NULL DEFAULT 0  ,
15   LastUpdated TIMESTAMP NULL  ,
16   PRIMARY KEY (id)
17
18 );
19 ALTER TABLE Scrips ADD COLUMN Disabled int2 NOT NULL DEFAULT 0;
20
21 INSERT INTO ObjectScrips(
22     Scrip, Stage, ObjectId,
23     Creator, Created, LastUpdatedBy, LastUpdated
24 )
25 SELECT id, Stage, Queue, Creator, Created, LastUpdatedBy, LastUpdated
26 FROM Scrips
27 ;
28
29 UPDATE Scrips SET Disabled = 1 WHERE Stage = 'Disabled';
30 UPDATE ObjectScrips SET Stage = 'TransactionCreate' WHERE Stage = 'Disabled';
31
32 CREATE UNIQUE INDEX ObjectScrips1 ON ObjectScrips (ObjectId, Scrip);
33
34 ALTER TABLE Scrips
35     DROP COLUMN Stage,
36     DROP COLUMN Queue;