DROP TABLE IF EXISTS ObjectScrips;
CREATE TABLE ObjectScrips (
  id INTEGER NOT NULL  AUTO_INCREMENT,
  Scrip integer NOT NULL  ,
  Stage varchar(32) CHARACTER SET ascii NOT NULL DEFAULT 'TransactionCreate',
  ObjectId integer NOT NULL,
  SortOrder integer NOT NULL DEFAULT 0  ,

  Creator integer NOT NULL DEFAULT 0  ,
  Created DATETIME NULL  ,
  LastUpdatedBy integer NOT NULL DEFAULT 0  ,
  LastUpdated DATETIME NULL  ,
  PRIMARY KEY (id)
) ENGINE=InnoDB CHARACTER SET utf8;
ALTER TABLE Scrips ADD COLUMN Disabled int2 NOT NULL DEFAULT 0;

INSERT INTO ObjectScrips(
    Scrip, Stage, ObjectId,
    Creator, Created, LastUpdatedBy, LastUpdated
)
SELECT id, Stage, Queue, Creator, Created, LastUpdatedBy, LastUpdated
FROM Scrips
;

UPDATE Scrips SET Disabled = 1 WHERE Stage = 'Disabled';
UPDATE ObjectScrips SET Stage = 'TransactionCreate' WHERE Stage = 'Disabled';

CREATE UNIQUE INDEX ObjectScrips1 ON ObjectScrips (ObjectId, Scrip);

ALTER TABLE Scrips
    DROP COLUMN Stage,
    DROP COLUMN Queue;
