-- Licensed Materials - Property of IBM
-- IBM Cognos Products: ccllogging
-- (C) Copyright IBM Corp. 2005, 2010
-- US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 

sp_rename 'COGIPF_ACTION', 'COGIPF_ACTION_OLD'

CREATE TABLE COGIPF_ACTION (
	COGIPF_HOST_IPADDR 	varchar (128) NULL ,
	COGIPF_HOST_PORT 	int NULL ,
	COGIPF_PROC_ID 		int NULL ,
	COGIPF_LOCALTIMESTAMP 	datetime NULL ,
	COGIPF_TIMEZONE_OFFSET 	int NULL ,
	COGIPF_SESSIONID 	varchar (255) NULL ,
	COGIPF_REQUESTID 	nvarchar (255) NOT NULL ,
	COGIPF_STEPID 		nvarchar (255) NULL ,
	COGIPF_SUBREQUESTID 	nvarchar (255) NULL ,
	COGIPF_THREADID 	varchar (255) NULL ,
	COGIPF_COMPONENTID 	varchar (64) NULL ,
	COGIPF_BUILDNUMBER 	int NULL ,
	COGIPF_LOG_LEVEL 	int NULL ,
	COGIPF_OPERATION 	varchar (255) NULL ,
	COGIPF_TARGET_TYPE 	varchar (255) NULL ,
	COGIPF_TARGET_PATH 	varchar (1024) NULL ,
	COGIPF_STATUS 		varchar (255) NULL ,
	COGIPF_ERRORDETAILS 	varchar (2000) NULL 
)

insert into COGIPF_ACTION select * from COGIPF_ACTION_OLD

drop table COGIPF_ACTION_OLD

drop index COGIPF_NATIVEQUERY.COGIPF_NATQRY_IDX

sp_rename 'COGIPF_NATIVEQUERY', 'COGIPF_NATIVEQUERY_OLD'

CREATE TABLE COGIPF_NATIVEQUERY (
	COGIPF_HOST_IPADDR 	varchar (128) NULL ,
	COGIPF_HOST_PORT 	int NULL ,
	COGIPF_PROC_ID 		int NULL ,
	COGIPF_LOCALTIMESTAMP 	datetime NULL ,
	COGIPF_TIMEZONE_OFFSET 	int NULL ,
	COGIPF_SESSIONID 	varchar (255) NULL ,
	COGIPF_REQUESTID 	nvarchar (255) NOT NULL ,
	COGIPF_STEPID 		nvarchar (255) NULL ,
	COGIPF_SUBREQUESTID 	nvarchar (255) NULL ,
	COGIPF_THREADID 	varchar (255) NULL ,
	COGIPF_COMPONENTID 	varchar (64) NULL ,
	COGIPF_BUILDNUMBER 	int NULL ,
	COGIPF_LOG_LEVEL 	int NULL ,
	COGIPF_REQUESTSTRING 	ntext NULL 
)

CREATE INDEX COGIPF_NATQRY_IDX ON COGIPF_NATIVEQUERY (COGIPF_REQUESTID, COGIPF_STEPID)

insert into COGIPF_NATIVEQUERY select * from COGIPF_NATIVEQUERY_OLD

drop table COGIPF_NATIVEQUERY_OLD

drop index COGIPF_RUNJOB.COGIPF_RUNJOB_IDX

sp_rename 'COGIPF_RUNJOB', 'COGIPF_RUNJOB_OLD'

CREATE TABLE COGIPF_RUNJOB (
	COGIPF_HOST_IPADDR 	varchar (128) NULL ,
	COGIPF_HOST_PORT 	int NULL ,
	COGIPF_PROC_ID 		int NULL ,
	COGIPF_LOCALTIMESTAMP 	datetime NULL ,
	COGIPF_TIMEZONE_OFFSET 	int NULL ,
	COGIPF_SESSIONID 	varchar (255) NULL ,
	COGIPF_REQUESTID 	nvarchar (255) NOT NULL ,
	COGIPF_STEPID 		nvarchar (255) NULL ,
	COGIPF_SUBREQUESTID 	nvarchar (255) NULL ,
	COGIPF_THREADID 	varchar (255) NULL ,
	COGIPF_COMPONENTID 	varchar (64) NULL ,
	COGIPF_BUILDNUMBER 	int NULL ,
	COGIPF_LOG_LEVEL 	int NULL ,
	COGIPF_TARGET_TYPE 	varchar (255) NULL ,
	COGIPF_JOBPATH 		varchar (512) NULL ,
	COGIPF_STATUS 		varchar (255) NULL ,
	COGIPF_ERRORDETAILS 	varchar (2000) NULL ,
	COGIPF_RUNTIME 		int NULL 
)

create index COGIPF_RUNJOB_IDX on COGIPF_RUNJOB (COGIPF_REQUESTID, COGIPF_STEPID)

insert into COGIPF_RUNJOB select * from COGIPF_RUNJOB_OLD

drop table COGIPF_RUNJOB_OLD

drop index COGIPF_RUNJOBSTEP.COGIPF_RUNJSTP_IDX

sp_rename 'COGIPF_RUNJOBSTEP', 'COGIPF_RUNJOBSTEP_OLD'

CREATE TABLE COGIPF_RUNJOBSTEP (
	COGIPF_HOST_IPADDR 	varchar (128) NULL ,
	COGIPF_HOST_PORT 	int NULL ,
	COGIPF_PROC_ID 		int NULL ,
	COGIPF_LOCALTIMESTAMP 	datetime NULL ,
	COGIPF_TIMEZONE_OFFSET 	int NULL ,
	COGIPF_SESSIONID 	varchar (255) NULL ,
	COGIPF_REQUESTID 	nvarchar (255) NOT NULL ,
	COGIPF_STEPID 		nvarchar (255) NULL ,
	COGIPF_SUBREQUESTID 	nvarchar (255) NULL ,
	COGIPF_THREADID 	varchar (255) NULL ,
	COGIPF_COMPONENTID 	varchar (64) NULL ,
	COGIPF_BUILDNUMBER 	int NULL ,
	COGIPF_LOG_LEVEL 	int NULL ,
	COGIPF_TARGET_TYPE 	varchar (255) NULL ,
	COGIPF_JOBSTEPPATH 	varchar (512) NULL ,
	COGIPF_STATUS 		varchar (255) NULL ,
	COGIPF_ERRORDETAILS 	varchar (2000) NULL ,
	COGIPF_RUNTIME 		int NULL 
)

create index COGIPF_RUNJSTP_IDX on COGIPF_RUNJOBSTEP (COGIPF_REQUESTID, COGIPF_STEPID)

insert into COGIPF_RUNJOBSTEP select * from COGIPF_RUNJOBSTEP_OLD

drop table COGIPF_RUNJOBSTEP_OLD

drop index COGIPF_RUNREPORT.COGIPF_RUNREP_IDX

sp_rename 'COGIPF_RUNREPORT', 'COGIPF_RUNREPORT_OLD'

CREATE TABLE COGIPF_RUNREPORT (
	COGIPF_HOST_IPADDR 	varchar (128) NULL ,
	COGIPF_HOST_PORT 	int NULL ,
	COGIPF_PROC_ID 		int NULL ,
	COGIPF_LOCALTIMESTAMP 	datetime NULL ,
	COGIPF_TIMEZONE_OFFSET 	int NULL ,
	COGIPF_SESSIONID 	varchar (255) NULL ,
	COGIPF_REQUESTID 	nvarchar (255) NOT NULL ,
	COGIPF_STEPID 		nvarchar (255) NULL ,
	COGIPF_SUBREQUESTID 	nvarchar (255) NULL ,
	COGIPF_THREADID 	varchar (255) NULL ,
	COGIPF_COMPONENTID 	varchar (64) NULL ,
	COGIPF_BUILDNUMBER 	int NULL ,
	COGIPF_LOG_LEVEL 	int NULL ,
	COGIPF_TARGET_TYPE 	varchar (255) NULL ,
	COGIPF_REPORTPATH 	nvarchar (512) NULL ,
	COGIPF_STATUS 		varchar (255) NULL ,
	COGIPF_ERRORDETAILS 	varchar (2000) NULL ,
	COGIPF_RUNTIME 		int NULL ,
	COGIPF_REPORTNAME 	nvarchar (255) NULL ,
	COGIPF_PACKAGE 		nvarchar (512) NULL ,
	COGIPF_MODEL 		nvarchar (255) NULL 
)

create index COGIPF_RUNREP_IDX on COGIPF_RUNREPORT (COGIPF_REQUESTID, COGIPF_STEPID)

insert into COGIPF_RUNREPORT select * from COGIPF_RUNREPORT_OLD

drop table COGIPF_RUNREPORT_OLD

drop index COGIPF_EDITQUERY.COGIPF_EDTQRY_IDX

sp_rename 'COGIPF_EDITQUERY', 'COGIPF_EDITQUERY_OLD'

CREATE TABLE COGIPF_EDITQUERY (
	COGIPF_HOST_IPADDR 	varchar (128) NULL ,
	COGIPF_HOST_PORT 	int NULL ,
	COGIPF_PROC_ID 		int NULL ,
	COGIPF_LOCALTIMESTAMP 	datetime NULL ,
	COGIPF_TIMEZONE_OFFSET 	int NULL ,
	COGIPF_SESSIONID 	varchar (255) NULL ,
	COGIPF_REQUESTID 	nvarchar (255) NOT NULL ,
	COGIPF_STEPID 		nvarchar (255) NULL ,
	COGIPF_SUBREQUESTID 	nvarchar (255) NULL ,
	COGIPF_THREADID 	varchar (255) NULL ,
	COGIPF_COMPONENTID 	varchar (64) NULL ,
	COGIPF_BUILDNUMBER 	int NULL ,
	COGIPF_LOG_LEVEL 	int NULL ,
	COGIPF_TARGET_TYPE 	varchar (255) NULL ,
	COGIPF_QUERYPATH 	nvarchar (512) NULL ,
	COGIPF_STATUS 		varchar (255) NULL ,
	COGIPF_ERRORDETAILS 	varchar (2000) NULL ,
	COGIPF_RUNTIME 		int NULL ,
	COGIPF_QUERYNAME 	nvarchar (255) NULL ,
	COGIPF_PACKAGE 		nvarchar (512) NULL ,
	COGIPF_MODEL 		nvarchar (255) NULL 
)

create index COGIPF_EDTQRY_IDX on COGIPF_EDITQUERY (COGIPF_REQUESTID, COGIPF_STEPID)

insert into COGIPF_EDITQUERY select * from COGIPF_EDITQUERY_OLD

drop table COGIPF_EDITQUERY_OLD

sp_rename 'COGIPF_USERLOGON', 'COGIPF_USERLOGON_OLD'

CREATE TABLE COGIPF_USERLOGON (
	COGIPF_HOST_IPADDR 	varchar (128) NULL ,
	COGIPF_HOST_PORT 	int NULL ,
	COGIPF_PROC_ID 		int NULL ,
	COGIPF_LOCALTIMESTAMP 	datetime NULL ,
	COGIPF_TIMEZONE_OFFSET 	int NULL ,
	COGIPF_SESSIONID 	varchar (255) NULL ,
	COGIPF_REQUESTID 	nvarchar (255) NOT NULL ,
	COGIPF_STEPID 		nvarchar (255) NULL ,
	COGIPF_SUBREQUESTID 	nvarchar (255) NULL ,
	COGIPF_THREADID 	varchar (255) NULL ,
	COGIPF_COMPONENTID 	varchar (64) NULL ,
	COGIPF_BUILDNUMBER 	int NULL ,
	COGIPF_LOG_LEVEL 	int NULL ,
	COGIPF_STATUS 		varchar (255) NULL ,
	COGIPF_ERRORDETAILS 	varchar (2000) NULL ,
	COGIPF_LOGON_OPERATION 	varchar (255) NULL ,
	COGIPF_USERNAME 	varchar (255) NULL ,
	COGIPF_USERID 		varchar (255) NULL ,
	COGIPF_NAMESPACE 	varchar (255) NULL 
)

insert into COGIPF_USERLOGON select * from COGIPF_USERLOGON_OLD

drop table COGIPF_USERLOGON_OLD

sp_rename 'COGIPF_VIEWREPORT', 'COGIPF_VIEWREPORT_OLD'

CREATE TABLE COGIPF_VIEWREPORT (
	COGIPF_HOST_IPADDR 	varchar (128) NULL ,
	COGIPF_HOST_PORT 	int NULL ,
	COGIPF_PROC_ID 		int NULL ,
	COGIPF_LOCALTIMESTAMP 	datetime NULL ,
	COGIPF_TIMEZONE_OFFSET 	int NULL ,
	COGIPF_SESSIONID 	varchar (255) NULL ,
	COGIPF_REQUESTID 	nvarchar (255) NOT NULL ,
	COGIPF_STEPID 		nvarchar (255) NULL ,
	COGIPF_SUBREQUESTID 	nvarchar (255) NULL ,
	COGIPF_THREADID 	varchar (255) NULL ,
	COGIPF_COMPONENTID 	varchar (64) NULL ,
	COGIPF_BUILDNUMBER 	int NULL ,
	COGIPF_LOG_LEVEL 	int NULL ,
	COGIPF_TARGET_TYPE 	varchar (255) NULL ,
	COGIPF_REPORTPATH 	nvarchar (512) NULL ,
	COGIPF_STATUS 		varchar (255) NULL ,
	COGIPF_ERRORDETAILS 	varchar (2000) NULL ,
	COGIPF_REPORTNAME 	nvarchar (255) NULL ,
	COGIPF_PACKAGE 		nvarchar (512) NULL ,
	COGIPF_MODEL 		nvarchar (255) NULL ,
	COGIPF_REPORTFORMAT 	varchar (255) NULL 
)

insert into COGIPF_VIEWREPORT select * from COGIPF_VIEWREPORT_OLD

drop table COGIPF_VIEWREPORT_OLD

sp_rename 'COGIPF_AGENTRUN', 'COGIPF_AGENTRUN_OLD'

CREATE TABLE COGIPF_AGENTRUN (
	COGIPF_HOST_IPADDR 	varchar (128) NULL ,
	COGIPF_HOST_PORT 	int NULL ,
	COGIPF_PROC_ID 		int NULL ,
	COGIPF_LOCALTIMESTAMP 	datetime NULL ,
	COGIPF_TIMEZONE_OFFSET 	int NULL ,
	COGIPF_SESSIONID 	varchar (255) NULL ,
	COGIPF_REQUESTID 	nvarchar (255) NOT NULL ,
	COGIPF_STEPID 		nvarchar (255) NULL ,
	COGIPF_SUBREQUESTID 	nvarchar (255) NULL ,
	COGIPF_THREADID 	varchar (255) NULL ,
	COGIPF_COMPONENTID 	varchar (64) NULL ,
	COGIPF_BUILDNUMBER 	int NULL ,
	COGIPF_LOG_LEVEL 	int NULL ,
	COGIPF_OPERATION	varchar (64) NULL,
	COGIPF_TARGET_TYPE    	varchar (255) NULL,
	COGIPF_TARGET_PATH     	nvarchar (1024) NULL,
	COGIPF_TARGET_NAME     	nvarchar (255) NULL,
	COGIPF_STATUS 		varchar (255) NULL ,
	COGIPF_ERRORDETAILS 	varchar (2000) NULL ,
	COGIPF_AGENT_PATH     	nvarchar (512) NULL,
	COGIPF_SCHEDULETIME	int NULL,
	COGIPF_USER		nvarchar (255) NULL,
	COGIPF_EMAIL		nvarchar (255) NULL,
	COGIPF_MESSAGEID	varchar  (255) NULL
)

insert into COGIPF_AGENTRUN select * from COGIPF_AGENTRUN_OLD

drop table COGIPF_AGENTRUN_OLD

sp_rename 'COGIPF_AGENTBUILD', 'COGIPF_AGENTBUILD_OLD'

CREATE TABLE COGIPF_AGENTBUILD (
	COGIPF_HOST_IPADDR 	varchar (128) NULL ,
	COGIPF_HOST_PORT 	int NULL ,
	COGIPF_PROC_ID 		int NULL ,
	COGIPF_LOCALTIMESTAMP 	datetime NULL ,
	COGIPF_TIMEZONE_OFFSET 	int NULL ,
	COGIPF_SESSIONID 	varchar (255) NULL ,
	COGIPF_REQUESTID 	nvarchar (255) NOT NULL ,
	COGIPF_STEPID 		nvarchar (255) NULL ,
	COGIPF_SUBREQUESTID 	nvarchar (255) NULL ,
	COGIPF_THREADID 	varchar (255) NULL ,
	COGIPF_COMPONENTID 	varchar (64) NULL ,
	COGIPF_BUILDNUMBER 	int NULL ,
	COGIPF_LOG_LEVEL 	int NULL ,
	COGIPF_OPERATION	varchar (64) NULL,
	COGIPF_TARGET_TYPE    	varchar (255) NULL,
	COGIPF_TARGET_PATH     	nvarchar (1024) NULL,
	COGIPF_TARGET_NAME     	nvarchar (255) NULL,
	COGIPF_STATUS 		varchar (255) NULL ,
	COGIPF_ERRORDETAILS 	varchar (2000) NULL ,
	COGIPF_AGENT_PATH     	nvarchar (512) NULL,
	COGIPF_SCHEDULETIME	int NULL,
	COGIPF_USER		nvarchar (255) NULL,
	COGIPF_EMAIL		nvarchar (255) NULL
)

insert into COGIPF_AGENTBUILD select * from COGIPF_AGENTBUILD_OLD

drop table COGIPF_AGENTBUILD_OLD

sp_rename 'COGIPF_MIGRATION', 'COGIPF_MIGRATION_OLD'

CREATE TABLE COGIPF_MIGRATION (
	COGIPF_HOST_IPADDR 	varchar (128) NULL ,
	COGIPF_HOST_PORT 	int NULL ,
	COGIPF_PROC_ID 		int NULL ,
	COGIPF_LOCALTIMESTAMP 	datetime NULL ,
	COGIPF_TIMEZONE_OFFSET 	int NULL ,
	COGIPF_SESSIONID 	varchar (255) NULL ,
	COGIPF_REQUESTID 	nvarchar (255) NOT NULL ,
	COGIPF_STEPID 		nvarchar (255) NULL ,
	COGIPF_SUBREQUESTID 	nvarchar (255) NULL ,
	COGIPF_THREADID 	varchar (255) NULL ,
	COGIPF_COMPONENTID 	varchar (64) NULL ,
	COGIPF_BUILDNUMBER 	int NULL ,
	COGIPF_LOG_LEVEL 	int NULL ,
	COGIPF_OPERATION	varchar (64) NULL,
	COGIPF_TARGET_TYPE    	varchar (255) NULL,
	COGIPF_TARGET_PATH     	nvarchar (1024) NULL,
	COGIPF_TARGET_NAME     	nvarchar (255) NULL,
	COGIPF_STATUS 		varchar (255) NULL ,
	COGIPF_DETAILS	 	varchar (2000) NULL ,
	COGIPF_PACKAGE 		nvarchar (512) NULL ,
	COGIPF_MODEL 		nvarchar (255) NULL 
)

insert into COGIPF_MIGRATION select * from COGIPF_MIGRATION_OLD

drop table COGIPF_MIGRATION_OLD

sp_rename 'COGIPF_THRESHOLD_VIOLATIONS', 'COGIPF_THRESHOLD_VIOLATIONS_OLD'

CREATE TABLE COGIPF_THRESHOLD_VIOLATIONS (
	COGIPF_HOST_IPADDR    			varchar (128) NULL,
	COGIPF_HOST_PORT      			int NULL,
	COGIPF_PROC_ID        			int NULL,
	COGIPF_LOCALTIMESTAMP         		datetime NULL,
	COGIPF_TIMEZONE_OFFSET        		int NULL,
	COGIPF_COMPONENTID    			varchar (64) NULL,
	COGIPF_BUILDNUMBER    			int NULL,
	COGIPF_LOG_LEVEL  			int NULL,
	COGIPF_OPERATION			varchar (128) NULL,
	COGIPF_TARGET_TYPE    			varchar (255) NULL,
	COGIPF_TARGET_PATH     			nvarchar (1024) NULL,
	COGIPF_TARGET_NAME     			nvarchar (512) NULL,
	COGIPF_RESOURCE_TYPE 			varchar	(128) NULL,
	COGIPF_RESOURCE_PATH			nvarchar (512) NULL,
	COGIPF_METRIC_NAME			varchar	(255) NULL,
	COGIPF_METRIC_VALUE			varchar	(128) NULL,
	COGIPF_METRIC_HEALTH			varchar	(128) NULL,
	COGIPF_LOWER_AVG_THRSHLD		varchar	(128) NULL,
	COGIPF_LOWER_AVG_THRSHLD_EXCL		bit NULL,
	COGIPF_LOWER_POOR_THRSHLD		varchar	(128) NULL,
	COGIPF_LOWER_POOR_THRSHLD_EXCL		bit NULL,
	COGIPF_UPPER_AVG_THRSHLD		varchar	(128) NULL,
	COGIPF_UPPER_AVG_THRSHLD_EXCL		bit NULL,
	COGIPF_UPPER_POOR_THRSHLD		varchar	(128) NULL,
	COGIPF_UPPER_POOR_THRSHLD_EXCL		bit	NULL
)

insert into COGIPF_THRESHOLD_VIOLATIONS select * from COGIPF_THRESHOLD_VIOLATIONS_OLD

drop table COGIPF_THRESHOLD_VIOLATIONS_OLD
