/**BEGIN **/
-- EAS模型
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_EASUPGRADE_RECORD') 
CREATE TABLE T_EB_EASUPGRADE_RECORD (
	FID BIGINT DEFAULT 0 NOT NULL,
	FNUMBER NVARCHAR(100)  DEFAULT ' ' NOT NULL,
	FNAME NVARCHAR(100)  DEFAULT ' ' NOT NULL,
	FMODELTYPE CHAR(2)  DEFAULT ' ' NOT NULL,
	FCREATEORG NVARCHAR(50)  DEFAULT ' ' NOT NULL,
	FMEMUPSTATUS CHAR(1)  DEFAULT '1' NOT NULL,
	FDATAUPSTATUS CHAR(1)  DEFAULT '1' NOT NULL,
	FCREATEDATE DATETIME,
	FCREATER BIGINT DEFAULT 0 NOT NULL,
	FBEGINTIME DATETIME,
	FDATACENTER NVARCHAR(50)  DEFAULT ' ' NOT NULL,
	FENDTIME DATETIME,
	FEASDB BIGINT DEFAULT 0 NOT NULL,
	FEASMODELID NVARCHAR(50)  DEFAULT ' ' NOT NULL,
	FREFCUBE NVARCHAR(50)  DEFAULT ' ' NOT NULL,
	FUPGRADEER BIGINT DEFAULT 0 NOT NULL,
	FUPGRADETIME DATETIME,
	FENDUPGRADETIME DATETIME
);
EXEC P_ALTERPK 'PK_EB_EASUPGRADE_RECORD', 'T_EB_EASUPGRADE_RECORD', 'FID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_EASUPGRADE_RECORD')
CREATE INDEX IDX_EB_EASUPGRADE_RECORD ON T_EB_EASUPGRADE_RECORD (FNUMBER ASC);

-- EAS模型多语言
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_EASUPGRADE_RECORD_L') 
CREATE TABLE T_EB_EASUPGRADE_RECORD_L (
	FPKID NVARCHAR(36) DEFAULT 0 NOT NULL,
	FID BIGINT DEFAULT 0 NOT NULL,
	FLOCALEID NVARCHAR(10)  DEFAULT '' NOT NULL,
	FNAME NVARCHAR(100)  DEFAULT ' ' NOT NULL
);
EXEC P_ALTERPK 'PK_EB_EASUPGRADE_RECORD_L', 'T_EB_EASUPGRADE_RECORD_L', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_EASUPGRADE_RECORD_L')
CREATE INDEX IDX_EB_EASUPGRADE_RECORD_L ON T_EB_EASUPGRADE_RECORD_L (FID ASC);

-- EAS同步表映射关系
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_EAS_TABLE') 
CREATE TABLE T_EB_EAS_TABLE (
	FID BIGINT DEFAULT 0 NOT NULL,
	FEASDB BIGINT DEFAULT 0 NOT NULL,
	FEASDBCENTER NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FSRCTABLE NVARCHAR(50)  DEFAULT ' ' NOT NULL,
	FTARTABLE NVARCHAR(50)  DEFAULT ' ' NOT NULL
);
EXEC P_ALTERPK 'PK_EB_EAS_TABLE', 'T_EB_EAS_TABLE', 'FID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_EAS_TABLE')
CREATE INDEX IDX_EB_EAS_TABLE ON T_EB_EAS_TABLE (FEASDB ASC);

-- EAS维度升级日志
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_EAS_UPGRADE_LOG') 
CREATE TABLE T_EB_EAS_UPGRADE_LOG (
	FID BIGINT DEFAULT 0 NOT NULL,
	FUPGRADEMODEL BIGINT DEFAULT 0 NOT NULL,
	FMODEL BIGINT DEFAULT 0 NOT NULL,
	FCREATER BIGINT DEFAULT 0 NOT NULL,
	FMODELLOGINFO NVARCHAR(2000)  DEFAULT ' ' NOT NULL,
	FCREATEDATE DATETIME,
	FSTATUS CHAR(1) DEFAULT ' ' NOT NULL
);
EXEC P_ALTERPK 'PK_EB_EAS_UPGRADE_LOG', 'T_EB_EAS_UPGRADE_LOG', 'FID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_EAS_UPGRADE_LOG')
CREATE INDEX IDX_EB_EAS_UPGRADE_LOG ON T_EB_EAS_UPGRADE_LOG (FUPGRADEMODEL ASC);

-- EAS 同步表日志
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_EAS_TABLE_SYNC_LOG') 
CREATE TABLE T_EB_EAS_TABLE_SYNC_LOG (
	FID BIGINT DEFAULT 0 NOT NULL,
	FSRCTABLE NVARCHAR(50)  DEFAULT ' ' NOT NULL,
	FTARGETTABLE NVARCHAR(50)  DEFAULT ' ' NOT NULL,
	FTOTAL BIGINT DEFAULT 0 NOT NULL,
	FFALI BIGINT DEFAULT 0 NOT NULL,
	FSUCCESS BIGINT DEFAULT 0 NOT NULL,
	FBEGINTIME DATETIME,
	FENDTIME DATETIME,
	FCREATER BIGINT DEFAULT 0 NOT NULL,
	FINFO NVARCHAR(2000)  DEFAULT ' ' NOT NULL,
	FEASDB BIGINT DEFAULT 0 NOT NULL,
	FTRIGGER BIGINT DEFAULT 0 NOT NULL,
	FFAIL BIGINT DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_EB_EAS_TABLE_SYNC_LOG', 'T_EB_EAS_TABLE_SYNC_LOG', 'FID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_EAS_TABLE_SYNC_LOG')
CREATE INDEX IDX_EB_EAS_TABLE_SYNC_LOG ON T_EB_EAS_TABLE_SYNC_LOG (FEASDB ASC);

-- EAS成员升级日志
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_EAS_MEM_UPGRADE_LOG') 
CREATE TABLE T_EB_EAS_MEM_UPGRADE_LOG (
	FID BIGINT DEFAULT 0 NOT NULL,
	FUPGRADEMODEL BIGINT DEFAULT 0 NOT NULL,
	FEASMEMID NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FEASMEMNUMBER NVARCHAR(80)  DEFAULT ' ' NOT NULL,
	FEASMEMNAME NVARCHAR(100)  DEFAULT ' ' NOT NULL,
	FMEMID BIGINT DEFAULT 0 NOT NULL,
	FMEMNUMBER NVARCHAR(50)  DEFAULT ' ' NOT NULL,
	FMEMNAME NVARCHAR(50)  DEFAULT ' ' NOT NULL,
	FMEMLOGINFO NVARCHAR(2000)  DEFAULT ' ' NOT NULL,
	FEASDIMNUMBER NVARCHAR(80)  DEFAULT ' ' NOT NULL,
	FSTATUS NVARCHAR(50)  DEFAULT ' ' NOT NULL,
	FEASUNIONID NVARCHAR(50)  DEFAULT ' ' NOT NULL,
	FVIEWNUMBER NVARCHAR(80)  DEFAULT ' ' NOT NULL
);
EXEC P_ALTERPK 'PK_EB_EAS_MEM_UPGRADE_LOG', 'T_EB_EAS_MEM_UPGRADE_LOG', 'FID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_EAS_MEM_UPGRADE_LOG')
CREATE INDEX IDX_EB_EAS_MEM_UPGRADE_LOG ON T_EB_EAS_MEM_UPGRADE_LOG (FUPGRADEMODEL ASC,FEASDIMNUMBER ASC);

-- EAS数据升级日志
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_EAS_DATA_UPGRADE_LOG') 
CREATE TABLE T_EB_EAS_DATA_UPGRADE_LOG (
	FID BIGINT DEFAULT 0 NOT NULL,
	FUPGRADEMODEL BIGINT DEFAULT 0 NOT NULL,
	FINFO NVARCHAR(2000)  DEFAULT ' ' NOT NULL,
	FCREATER BIGINT DEFAULT 0 NOT NULL,
	FCREATEDATE DATETIME,
	FMODEL BIGINT DEFAULT 0 NOT NULL,
	FSTATUS CHAR(1)  DEFAULT ' ' NOT NULL,
	FSUCCESSCOUNT BIGINT DEFAULT 0 NOT NULL,
	FFAILCOUNT BIGINT DEFAULT 0 NOT NULL,
	FTOTALCOUNT BIGINT DEFAULT 0 NOT NULL,
	FWAITCOUNT BIGINT DEFAULT 0 NOT NULL,
	FPERCENT CHAR(8)  DEFAULT ' ' NOT NULL
);
EXEC P_ALTERPK 'PK_EB_EAS_DATA_UPGRADE_LOG', 'T_EB_EAS_DATA_UPGRADE_LOG', 'FID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_PK_EB_EAS_DATA_UPGRADE_LOG')
CREATE INDEX IDX_PK_EB_EAS_DATA_UPGRADE_LOG ON T_EB_EAS_DATA_UPGRADE_LOG (FUPGRADEMODEL ASC);

-- EAS数据升级日志详情
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_EAS_DATA_UPGRADE_DET') 
CREATE TABLE T_EB_EAS_DATA_UPGRADE_DET (
	FID BIGINT DEFAULT 0 NOT NULL,
	FDATAJSON NVARCHAR(2000)  DEFAULT ' ' NOT NULL,
	FCREATEDATE DATETIME,
	FINFO NVARCHAR(2000)  DEFAULT ' ' NOT NULL,
	FUPGRADEMODEL BIGINT DEFAULT 0 NOT NULL,
	FSTATUS CHAR(1)  DEFAULT ' ' NOT NULL
);
EXEC P_ALTERPK 'PK_EB_EAS_DATA_UPGRADE_DET', 'T_EB_EAS_DATA_UPGRADE_DET', 'FID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_EAS_DATA_UPGRADE_DET')
CREATE INDEX IDX_EB_EAS_DATA_UPGRADE_DET ON T_EB_EAS_DATA_UPGRADE_DET (FUPGRADEMODEL ASC);

-- T_EB_INTEGRATION 数据集成采集增加EAS信息
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_INTEGRATION' AND KSQL_COL_NAME IN ('FEASDBID')) 
ALTER TABLE T_EB_INTEGRATION ADD (FEASDBID BIGINT DEFAULT 0 NOT NULL);
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_INTEGRATION' AND KSQL_COL_NAME IN ('FEASDATACENTER')) 
ALTER TABLE T_EB_INTEGRATION ADD (FEASDATACENTER NVARCHAR(50)  DEFAULT ' ' NOT NULL);
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_INTEGRATION' AND KSQL_COL_NAME IN ('FEASDB')) 
ALTER TABLE T_EB_INTEGRATION ADD (FEASDB BIGINT DEFAULT 0 NOT NULL);

/**END **/