

--
--    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.
--    


-------------------------------------------------------------------------------
-- NC313_UPDATE_DB2.SQL	    *DO NOT EDIT*	Data Store Version: 313		 
-------------------------------------------------------------------------------

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

CREATE TABLE BC_TASK_HISTORY_DETAIL(
   TASK_ID	CHAR(20) NOT NULL,
   SUB_INDEX    INTEGER NOT NULL,
   SEVERITY     INTEGER,
   CLASSTYPE    CHAR(128),
   TASK 	BLOB(10M)
);

CREATE TABLE BC_NC_TASK_QUEUE (
	TASK_ID 			CHAR(20) NOT NULL,
	SERVICE_NAME 		VARCHAR(40) ,
	SERVER_GROUP 		VARCHAR(40) ,
	DATE_ENTERED 		NUMERIC(19) NOT NULL,
	TASK 				BLOB(500M),
	STATUS 				INTEGER NOT NULL,
	PRIORITY 			INTEGER NOT NULL,
	RESTART_ID    	    	CHAR (20),
	SDS_INSTANCE_ID 	CHAR (32) ,
	HISTORY_STORE_ID 	CHAR (34) ,
	ACTUAL_EXECUTION_TIME   NUMERIC(19),
	ACTUAL_COMPLETION_TIME  NUMERIC(19),
	DISPATCHER_ID		CHAR(45),
	SCHEDULE_TRIGGER_NAME   VARCHAR(255),
	SCHEDULE_TYPE		CHAR(15),
	ACCOUNT_PATH		VARCHAR(1024),
	STOREID 		CHAR(34),
	OBJECT_CLASS 		CHAR(64)
);

CREATE TABLE BC_NC_TSE_STATE_MAP (
	TASK_ID 			CHAR (20) NOT NULL,
	STATUS 				INTEGER ,
	SEQ 				INTEGER ,
	STEP_COUNT 			INTEGER ,
	CUR_SEQ 			INTEGER ,
	COUNT_SEQ 			INTEGER ,
	STOP_ON_ERROR 		INTEGER ,
	RUN_VIA_MS 			INTEGER ,
	STEP_FAILED 		INTEGER ,
	SEQ_ON_END 			INTEGER ,
	WRITE_ALL_HISTORIES INTEGER ,
	FAIL_STATUS 		INTEGER ,
	PARENT_ID 			CHAR(20) 
);

-------------------------------------------------------------------------------
--$110-- backup inserts begin
-------------------------------------------------------------------------------

INSERT INTO BC_TASK_HISTORY_DETAIL(
   TASK_ID,	
   SUB_INDEX,  
   SEVERITY,    
   CLASSTYPE,    
   TASK)
       SELECT TASK_ID,	
              SUB_INDEX,  
              SEVERITY,    
              CLASSTYPE,    
              TASK
       FROM NC_TASK_HISTORY_DETAIL;

INSERT INTO BC_NC_TASK_QUEUE ( 
	TASK_ID, 
	SERVICE_NAME , 
	SERVER_GROUP , 
	DATE_ENTERED, 
	TASK ,
	STATUS,
	PRIORITY,
	RESTART_ID,
	SDS_INSTANCE_ID,
	HISTORY_STORE_ID,
	ACTUAL_EXECUTION_TIME,
	ACTUAL_COMPLETION_TIME,
	DISPATCHER_ID,
	SCHEDULE_TRIGGER_NAME,
	SCHEDULE_TYPE,
	ACCOUNT_PATH,
	STOREID,
	OBJECT_CLASS)
    		SELECT  TASK_ID,
    			SERVICE_NAME,
    			SERVER_GROUP,
    			DATE_ENTERED,
    			TASK ,
    			STATUS,
    			PRIORITY ,
    			RESTART_ID,
    			SDS_INSTANCE_ID,
    			HISTORY_STORE_ID,
    			ACTUAL_EXECUTION_TIME,
			ACTUAL_COMPLETION_TIME,
			DISPATCHER_ID,
			SCHEDULE_TRIGGER_NAME,
			SCHEDULE_TYPE,
			ACCOUNT_PATH,
			STOREID,
			OBJECT_CLASS
    		FROM NC_TASK_QUEUE;

INSERT INTO BC_NC_TSE_STATE_MAP (
	TASK_ID,
	STATUS,
	SEQ,
	STEP_COUNT,
	CUR_SEQ,
	COUNT_SEQ,
	STOP_ON_ERROR,
	RUN_VIA_MS,
	STEP_FAILED,
	SEQ_ON_END,
	WRITE_ALL_HISTORIES,
	FAIL_STATUS,
	PARENT_ID)
		SELECT  TASK_ID,
			STATUS,
			SEQ,
			STEP_COUNT,
			CUR_SEQ,
			COUNT_SEQ,
			STOP_ON_ERROR,
			RUN_VIA_MS,
			STEP_FAILED,
			SEQ_ON_END,
			WRITE_ALL_HISTORIES,
			FAIL_STATUS,
			PARENT_ID
		FROM NC_TSE_STATE_MAP;

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

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

DROP TABLE NC_TASK_HISTORY_DETAIL;

DROP TABLE NC_TSE_STATE_MAP;

DROP TABLE NC_TASK_QUEUE;

DROP TABLE NC_TASK_PROPERTY;

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

CREATE TABLE NC_TASK_HISTORY_DETAIL(
   TASK_ID	CHAR(45) NOT NULL,
   SUB_INDEX    INTEGER NOT NULL,
   SEVERITY     INTEGER,
   CLASSTYPE    CHAR(128),
   TASK 	BLOB(10M)
);

CREATE TABLE NC_TASK_QUEUE (
	TASK_ID 		CHAR(45) NOT NULL,
	SERVICE_NAME 		VARCHAR(40) ,
	SERVER_GROUP 		VARCHAR(40) ,
	DATE_ENTERED 		NUMERIC(19) NOT NULL,
	TASK 			BLOB(500M),
	STATUS 			INTEGER NOT NULL,
	PRIORITY 		INTEGER NOT NULL,
	RESTART_ID    	    	CHAR (45),
	SDS_INSTANCE_ID 	CHAR (32) ,
	HISTORY_STORE_ID 	CHAR (34) ,
	ACTUAL_EXECUTION_TIME   NUMERIC(19),
	ACTUAL_COMPLETION_TIME  NUMERIC(19),
	DISPATCHER_ID		CHAR(45),
	SCHEDULE_TRIGGER_NAME   VARCHAR(255),
	SCHEDULE_TYPE		CHAR(15),
	ACCOUNT_PATH		VARCHAR(1024),
	STOREID 		CHAR(34),
	OBJECT_CLASS 		CHAR(64)
);

CREATE TABLE NC_TSE_STATE_MAP (
	TASK_ID 		CHAR (45) NOT NULL,
	STATUS 			INTEGER ,
	SEQ 			INTEGER ,
	STEP_COUNT 		INTEGER ,
	CUR_SEQ 		INTEGER ,
	COUNT_SEQ 		INTEGER ,
	STOP_ON_ERROR 		INTEGER ,
	RUN_VIA_MS 		INTEGER ,
	STEP_FAILED 		INTEGER ,
	SEQ_ON_END 		INTEGER ,
	WRITE_ALL_HISTORIES 	INTEGER ,
	FAIL_STATUS 		INTEGER ,
	PARENT_ID 		CHAR(45) 
);

CREATE TABLE NC_TASK_PROPERTY (
	TASK_ID 			CHAR (45) NOT NULL,
	PROP_NAME			CHAR (45) NOT NULL,
	PROP_VALUE			VARCHAR(2000)
);


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

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

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

CREATE INDEX IX_NC_TSE_STE_MAP ON NC_TSE_STATE_MAP (PARENT_ID, SEQ);

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

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

-------------------------------------------------------------------------------
--$203-- alter tables begin
-------------------------------------------------------------------------------

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

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

INSERT INTO NC_DB_VERSION (DB_VERSION_ID,BUILD) VALUES(313,'build no.');

 -------------------------------------------------------------------------------
 --$230-- restore inserts begin
 -------------------------------------------------------------------------------
 
  INSERT INTO NC_TASK_HISTORY_DETAIL(
   TASK_ID,	
   SUB_INDEX,  
   SEVERITY,    
   CLASSTYPE,    
   TASK)
       SELECT TASK_ID,	
              SUB_INDEX,  
              SEVERITY,    
              CLASSTYPE,    
              TASK
       FROM BC_TASK_HISTORY_DETAIL;
 
 INSERT INTO NC_TASK_QUEUE ( 
	TASK_ID, 
	SERVICE_NAME , 
	SERVER_GROUP , 
	DATE_ENTERED, 
	TASK ,
	STATUS,
	PRIORITY,
	RESTART_ID,
	SDS_INSTANCE_ID,
	HISTORY_STORE_ID,
	ACTUAL_EXECUTION_TIME,
	ACTUAL_COMPLETION_TIME,
	DISPATCHER_ID,
	SCHEDULE_TRIGGER_NAME,
	SCHEDULE_TYPE,
	ACCOUNT_PATH,
	STOREID,
	OBJECT_CLASS)
    		SELECT  TASK_ID,
    			SERVICE_NAME,
    			SERVER_GROUP,
    			DATE_ENTERED,
    			TASK ,
    			STATUS,
    			PRIORITY ,
    			RESTART_ID,
    			SDS_INSTANCE_ID,
    			HISTORY_STORE_ID,
    			ACTUAL_EXECUTION_TIME,
			ACTUAL_COMPLETION_TIME,
			DISPATCHER_ID,
			SCHEDULE_TRIGGER_NAME,
			SCHEDULE_TYPE,
			ACCOUNT_PATH,
			STOREID,
			OBJECT_CLASS
    		FROM BC_NC_TASK_QUEUE;

INSERT INTO NC_TSE_STATE_MAP (
	TASK_ID,
	STATUS,
	SEQ,
	STEP_COUNT,
	CUR_SEQ,
	COUNT_SEQ,
	STOP_ON_ERROR,
	RUN_VIA_MS,
	STEP_FAILED,
	SEQ_ON_END,
	WRITE_ALL_HISTORIES,
	FAIL_STATUS,
	PARENT_ID)
		SELECT  TASK_ID,
			STATUS,
			SEQ,
			STEP_COUNT,
			CUR_SEQ,
			COUNT_SEQ,
			STOP_ON_ERROR,
			RUN_VIA_MS,
			STEP_FAILED,
			SEQ_ON_END,
			WRITE_ALL_HISTORIES,
			FAIL_STATUS,
			PARENT_ID
		FROM BC_NC_TSE_STATE_MAP;

 -------------------------------------------------------------------------------
 --$250-- backup drop begin
 -------------------------------------------------------------------------------
 
 DROP TABLE BC_TASK_HISTORY_DETAIL;
 
 DROP TABLE BC_NC_TSE_STATE_MAP;

DROP TABLE BC_NC_TASK_QUEUE;

-------------------------------------------------------------------------------
--$260-- end sql by function
-------------------------------------------------------------------------------
--	END NC313_UPDATE_DB2.SQL			*	DO NOT EDIT	 * 		 
-------------------------------------------------------------------------------
