

--
--    Licensed Materials - Property of IBM
--    
--    BI and PM: JSM
--    
--    (c) Copyright IBM Corp. 2003, 2010.
--    
--    US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
--    


-------------------------------------------------------------------------------
-- NC831_UPDATE_SYBASE.SQL	       *DO NOT EDIT*		Data Store Version: 831		 
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
--$100-- backup create begin
-------------------------------------------------------------------------------

CREATE TABLE BC_NC_SCHEDULED_EVENT_OVERRIDE(
    FK_TASKSCHEDULE_ID 		INTEGER NOT NULL,
    EVENT_DATE			    NUMERIC NOT NULL,
    EVENT_STATUS            INTEGER NULL,
    EVENT_PRIORITY          INTEGER NULL,
    FK_SCHEDULE_ID      	INTEGER NULL
)
go

-------------------------------------------------------------------------------
--$110-- backup inserts begin
-------------------------------------------------------------------------------
INSERT INTO BC_NC_SCHEDULED_EVENT_OVERRIDE (FK_TASKSCHEDULE_ID, EVENT_DATE, EVENT_STATUS, EVENT_PRIORITY, FK_SCHEDULE_ID) 
    SELECT FK_TASKSCHEDULE_ID, EVENT_DATE, EVENT_STATUS, EVENT_PRIORITY, FK_SCHEDULE_ID FROM NC_SCHEDULED_EVENT_OVERRIDE
go

-------------------------------------------------------------------------------
--$130-- views drop begin
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
--$140-- tables drop begin
-------------------------------------------------------------------------------

DROP TABLE NC_TSE_STATE_MAP
go

DROP TABLE NC_TASK_HISTORY_DETAIL
go

DROP TABLE NC_TASK_QUEUE
go

DROP TABLE NC_TASK_PROPERTY
go

DROP TABLE NC_JMSQUEUE
go

DROP TABLE NC_SCHEDULED_EVENT_OVERRIDE
go

-------------------------------------------------------------------------------
--$200-- recreate tables begin
-------------------------------------------------------------------------------

CREATE TABLE NC_TSE_STATE_MAP (
	TASK_ID 			CHAR (45) NOT NULL,
	STATUS 				INTEGER NULL,
	SEQ 				INTEGER NULL,
	STEP_COUNT 			INTEGER NULL,
	CUR_SEQ 			INTEGER NULL,
	COUNT_SEQ 			INTEGER NULL,
	STOP_ON_ERROR 		INTEGER NULL,
	RUN_VIA_MS 			INTEGER NULL,
	STEP_FAILED 		INTEGER NULL,
	SEQ_ON_END 			INTEGER NULL,
	WRITE_ALL_HISTORIES INTEGER NULL,
	FAIL_STATUS 		INTEGER NULL,
	PARENT_ID 			CHAR(45) NULL,
	EXECUTING    		INTEGER DEFAULT (0) NOT NULL,
	MODCOUNT                INTEGER DEFAULT (-1) NOT NULL
)
go

CREATE TABLE NC_TASK_HISTORY_DETAIL(
   TASK_ID	CHAR(45) NOT NULL,
   SUB_INDEX    INTEGER NOT NULL,
   SEVERITY     INTEGER NULL,
   CLASSTYPE    CHAR(128) NULL,
   TASK 	IMAGE NULL,
   STATUS 		INTEGER DEFAULT (0) NOT NULL
)
go

CREATE TABLE NC_TASK_QUEUE (
	TASK_ID 			CHAR(45) NOT NULL,
	SERVICE_NAME 		NVARCHAR(40) NULL,
	SERVER_GROUP 		NVARCHAR(40) NULL,
	DATE_ENTERED 		NUMERIC NOT NULL,
	TASK 				IMAGE NULL,
	STATUS 				INTEGER NOT NULL,
	PRIORITY 			INTEGER NOT NULL,
	RESTART_ID              CHAR(45) NULL,
	SDS_INSTANCE_ID 	CHAR (32) NULL,
	HISTORY_STORE_ID 	CHAR (34) NULL,
	ACTUAL_EXECUTION_TIME   NUMERIC NULL,
	ACTUAL_COMPLETION_TIME  NUMERIC NULL,
	DISPATCHER_ID		CHAR(45) NULL,
	SCHEDULE_TRIGGER_NAME   NVARCHAR(255) NULL,
	SCHEDULE_TYPE		CHAR(15) NULL,
	ACCOUNT_PATH		NVARCHAR(1024) NULL,
	STOREID 		CHAR(34) NULL,
	OBJECT_CLASS 		CHAR(64) NULL,
	OWNER_STOREID 		NVARCHAR(256) NULL
)
go

CREATE TABLE NC_TASK_PROPERTY (
	TASK_ID 			CHAR (45) NOT NULL,
	PROP_NAME			CHAR (45) NOT NULL,
	PROP_VALUE			NVARCHAR(2000) NULL
)
go

CREATE TABLE NC_SCHEDULED_EVENT_OVERRIDE(
    FK_TASKSCHEDULE_ID 		INTEGER NOT NULL,
    EVENT_DATE			    NUMERIC NOT NULL,
    EVENT_STATUS            INTEGER NULL,
    EVENT_PRIORITY          INTEGER NULL,
    FK_SCHEDULE_ID      	INTEGER NULL,
    CANCELLED_BY          	NVARCHAR(2000) NULL
)
go

CREATE TABLE NC_JMSQUEUE (
	QUEUE_ENTRY_ID               INTEGER NOT NULL,
	QUEUE_NAME                   NVARCHAR(50) NULL,
	QUEUE_ENTRY                  IMAGE NULL,
	SDS_INSTANCE_ID		         CHAR (32) NULL,
	DATE_ENTERED 		         NUMERIC NOT NULL,
	REDELIVER_DATE 			    NUMERIC NULL,
   	REDELIVER_COUNT 		    INTEGER DEFAULT (0)
) 
go

-------------------------------------------------------------------------------
--$202-- primary keys add begin
-------------------------------------------------------------------------------

ALTER TABLE NC_TSE_STATE_MAP ADD CONSTRAINT PN_TSE_STATE_MAP PRIMARY KEY (TASK_ID)
go

ALTER TABLE NC_TASK_HISTORY_DETAIL ADD CONSTRAINT PN_TASK_HD PRIMARY KEY (TASK_ID,SUB_INDEX)
go

ALTER TABLE NC_TASK_QUEUE ADD CONSTRAINT PN_TASK_QUEUE PRIMARY KEY (TASK_ID)
go

ALTER TABLE NC_JMSQUEUE
   ADD CONSTRAINT PN_NC_JMSQUEUE PRIMARY KEY (QUEUE_ENTRY_ID)
go

ALTER TABLE NC_SCHEDULED_EVENT_OVERRIDE
	ADD CONSTRAINT PN_EVENT_DATES PRIMARY KEY (FK_TASKSCHEDULE_ID, EVENT_DATE)
go

ALTER TABLE NC_TASK_PROPERTY ADD CONSTRAINT PN_TASK_PROPERTY PRIMARY KEY (TASK_ID,PROP_NAME)
go

-------------------------------------------------------------------------------
--$201-- indices create begin
-------------------------------------------------------------------------------

CREATE INDEX IX_NC_TSE_STATE_MAP ON NC_TSE_STATE_MAP (
	PARENT_ID, SEQ)
go

CREATE INDEX IX_NC_TASK_QUEUE_SELECTOR ON NC_TASK_QUEUE (
	STATUS, SERVICE_NAME, SERVER_GROUP, DATE_ENTERED)
go

CREATE INDEX IX_NC_JMSQUEUE ON NC_JMSQUEUE(QUEUE_NAME, DATE_ENTERED, SDS_INSTANCE_ID) 
go

CREATE INDEX IX_NC_JMSQUEUE1 ON NC_JMSQUEUE(QUEUE_NAME, SDS_INSTANCE_ID) 
go

CREATE INDEX I1N_EVENT_DATES ON NC_SCHEDULED_EVENT_OVERRIDE (
   FK_TASKSCHEDULE_ID)
go
-------------------------------------------------------------------------------
--$203-- alter tables begin
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
--$210-- views create begin
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
--$220-- server data inserts begin
-------------------------------------------------------------------------------

INSERT INTO NC_DB_VERSION (DB_VERSION_ID,BUILD) VALUES(831,'build no.')
go

 -------------------------------------------------------------------------------
 --$230-- restore inserts begin
 -------------------------------------------------------------------------------
INSERT INTO NC_SCHEDULED_EVENT_OVERRIDE (FK_TASKSCHEDULE_ID, EVENT_DATE, EVENT_STATUS, EVENT_PRIORITY, FK_SCHEDULE_ID) 
    SELECT FK_TASKSCHEDULE_ID, EVENT_DATE, EVENT_STATUS, EVENT_PRIORITY, FK_SCHEDULE_ID FROM BC_NC_SCHEDULED_EVENT_OVERRIDE
go

 -------------------------------------------------------------------------------
 --$250-- backup drop begin
 -------------------------------------------------------------------------------
DROP TABLE BC_NC_SCHEDULED_EVENT_OVERRIDE
go
-------------------------------------------------------------------------------
--$260-- end sql by function
-------------------------------------------------------------------------------
--	END NC831_UPDATE_SYBASE.SQL			*	DO NOT EDIT	 * 		 
-------------------------------------------------------------------------------
