IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_privacy_scheme_config') 
CREATE TABLE t_privacy_scheme_config
(
    fid bigint NOT NULL,
    fmasterid bigint,
    fdatalabelid bigint,
    fscheme_status VARCHAR(50)  DEFAULT ' ' NOT NULL ,
    fscheme_code VARCHAR(30)  DEFAULT ' '  NOT NULL,
    fscheme_desc VARCHAR(50)   NOT NULL DEFAULT ' ' ,
    fscheme_name VARCHAR(50)    DEFAULT ' ' NOT NULL ,
    fmessagechannel VARCHAR(50)  DEFAULT ' ' NOT NULL ,
    ftemplate VARCHAR(500)   DEFAULT ' ',
    CONSTRAINT pk_privacy_scheme_config PRIMARY KEY (fid)
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_privacy_decrypt_receive') 
CREATE TABLE t_privacy_decrypt_receive
(
    fpkid bigint NOT NULL,
    fid bigint NOT NULL,
    fbasedataid bigint NOT NULL,
    CONSTRAINT pk_privacy_decrypt_receive PRIMARY KEY (fpkid)
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_privacy_scheme_config_l')
CREATE TABLE t_privacy_scheme_config_l
(
    fpkid VARCHAR(18)  NOT NULL,
    fid bigint NOT NULL,
    flocaleid VARCHAR(10)   NOT NULL,
    fscheme_name VARCHAR(50)  DEFAULT ' '  NOT NULL,
    CONSTRAINT pk_ivacy_scheme_config_l PRIMARY KEY (fpkid)
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_privacy_scheme_confi_r3')
CREATE TABLE t_privacy_scheme_confi_r3
(
    fid bigint NOT NULL DEFAULT 0,
    frefstatus CHAR(1)  DEFAULT '0' NOT NULL ,
    CONSTRAINT pk_privacy_scheme_config_r3 PRIMARY KEY (fid)
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_privacy_scheme_desen')
CREATE TABLE t_privacy_scheme_desen
(
    fid bigint NOT NULL,
    fentryid bigint NOT NULL,
    fseq integer NOT NULL DEFAULT 0,
    fdense_field_ident VARCHAR(50),
    fdense_field_name VARCHAR(50),
    fdense_field_type VARCHAR(50),
    fdesensitize_rule VARCHAR(50)    DEFAULT ' ' NOT NULL,
    fdense_entity_number VARCHAR(50)  DEFAULT ' ' NOT NULL ,
    fdense_app_number VARCHAR(50)   DEFAULT ' ' NOT NULL,
    fdense_cloud_number VARCHAR(50)   DEFAULT ' ' NOT NULL,
    fdense_field_locale VARCHAR(50)   DEFAULT ' ' NOT NULL ,
    fdesensitize_type VARCHAR(50)   DEFAULT ' ' NOT NULL,
    fplugin VARCHAR(50)    DEFAULT ' ' NOT NULL ,
    fdense_table_name VARCHAR(50) DEFAULT ' '  NOT NULL ,
    fdense_field_desc VARCHAR(60)  DEFAULT ' ' NOT NULL ,
    fdense_entity_name VARCHAR(50)   DEFAULT ' ' NOT NULL,
    fdense_app_name VARCHAR(50)   DEFAULT ' ' NOT NULL ,
    fdense_cloud_name VARCHAR(50)    DEFAULT ' ' NOT NULL,
	fdesensitiz_status  VARCHAR(50)    DEFAULT ' ' NOT NULL,
	fdensefieldlocale VARCHAR(50)    DEFAULT ' ',
	flabelid bigint NOT NULL,
    CONSTRAINT pk_privacy_scheme_desen PRIMARY KEY (fentryid)
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_privacy_scheme_encrypt')
CREATE TABLE t_privacy_scheme_encrypt
(
    fid bigint NOT NULL,
    fentryid bigint NOT NULL,
    fseq integer NOT NULL DEFAULT 0,
    fencrypt_field_ident VARCHAR(50) ,
    fencrypt_field_type VARCHAR(50) ,
    fencrypt_cloud_number VARCHAR(50)  DEFAULT ' ' NOT NULL ,
    fencrypt_field_name VARCHAR(50) ,
    fencrypt_algorithm VARCHAR(50)  DEFAULT ' ' NOT NULL ,
    fencrypt_entity_number VARCHAR(50)  DEFAULT ' ' NOT NULL ,
    fencrypt_app_number VARCHAR(50)  DEFAULT ' ' NOT NULL ,
    fversion bigint,
    fencrypt_table_name VARCHAR(50) ,
    fencrypt_field_desc VARCHAR(60) ,
    fencrypt_entity_name VARCHAR(50)  DEFAULT ' ' NOT NULL ,
    fencrypt_app_name VARCHAR(50)  DEFAULT ' ' NOT NULL ,
    fencrypt_cloud_name VARCHAR(50)  DEFAULT ' ' NOT NULL ,
	fencrypt_status VARCHAR(50)  DEFAULT ' ' NOT NULL,
	fapp_route VARCHAR(50)  DEFAULT ' ' NOT NULL,
	flabelid bigint NOT NULL,
    CONSTRAINT pk_privacy_scheme_encrypt PRIMARY KEY (fentryid)
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_privacy_desen_authority')
CREATE TABLE t_privacy_desen_authority
(
    fid bigint NOT NULL,
    fentryid bigint NOT NULL,
    fseq integer NOT NULL DEFAULT 0,
    ffieldident VARCHAR(50) DEFAULT ' ' NOT NULL,
    ffieldname VARCHAR(50) ,
    fentitynumber VARCHAR(50)  DEFAULT ' ' NOT NULL,
    fentityname VARCHAR(50) ,
    fformpolicy VARCHAR(50)  DEFAULT ' '  ,
    fexportpolicy VARCHAR(50)  DEFAULT ' '  ,
    fprintpolicy VARCHAR(50)  DEFAULT ' ',
	flabelid bigint NOT NULL,
    CONSTRAINT pk_privacy_desen_authority PRIMARY KEY (fentryid)
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_privacy_scheme_permuser')
CREATE TABLE t_privacy_scheme_permuser
(
    fpkid bigint NOT NULL,
    fentryid bigint NOT NULL,
    fbasedataid bigint NOT NULL,
    CONSTRAINT pk_privacy_scheme_permuser PRIMARY KEY (fentryid)
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_privacy_scheme_permrole')
CREATE TABLE t_privacy_scheme_permrole
(
    fpkid bigint NOT NULL,
    fentryid bigint NOT NULL,
    fbasedataid bigint NOT NULL,
    CONSTRAINT pk_privacy_scheme_permrole PRIMARY KEY (fentryid)
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_privacy_decrypt_control')
CREATE TABLE t_privacy_decrypt_control
(
    fid bigint NOT NULL,
    fentryid bigint NOT NULL,
    fseq integer NOT NULL DEFAULT 0,
    ffieldident VARCHAR(50) DEFAULT ' ' NOT NULL,
    ffieldname VARCHAR(50) ,
    fentitynumber VARCHAR(50)  DEFAULT ' ' NOT NULL,
    fentityname VARCHAR(50) ,
    fdailylimit integer NOT NULL DEFAULT 0,
    frule VARCHAR(50)  DEFAULT ' '  ,
	flabelid bigint NOT NULL,
    CONSTRAINT pk_privacy_decrypt_control PRIMARY KEY (fentryid)
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_privacy_task')
CREATE TABLE t_privacy_task
(
    fid bigint NOT NULL,
    ftask_type VARCHAR(100) ,
    fstart_date datetime,
    fend_date datetime,
    fcreate_date datetime,
    fversion integer,
    fupgrade integer,
    ftask_status VARCHAR(50)  DEFAULT ' '  NOT NULL ,
    fcreate_by bigint,
    ffield_name VARCHAR(50)  DEFAULT ' '  NOT NULL ,
    ftable_name VARCHAR(50)  DEFAULT ' ' NOT NULL ,
    fpytable_name VARCHAR(50)  DEFAULT ' '  NOT NULL ,
    ffield_type VARCHAR(50)  DEFAULT ' ',
    forderby VARCHAR(50)  DEFAULT ' ',
    fpkname VARCHAR(50)  DEFAULT ' ',
    foldEncrypt VARCHAR(50) ,
	fpkvalue VARCHAR(255) ,
	forderby_value  VARCHAR(255),
    ferrorlogs VARCHAR(2000) DEFAULT ' ',
    fschemeid bigint,
    fentity_number VARCHAR(50) DEFAULT ' ',
    fislocale VARCHAR(50)  DEFAULT ' ',
    fdbrouter VARCHAR(50) DEFAULT ' ',
    foldencrypt_type VARCHAR(50) DEFAULT ' ',
    fpktype integer,
    fiscommonlang VARCHAR(50) DEFAULT ' '  NOT NULL,
    CONSTRAINT t_privacy_task_pkey PRIMARY KEY (fid)
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_privacy_task_r3')
CREATE TABLE t_privacy_task_r3
(
    fid bigint NOT NULL DEFAULT 0,
    frefstatus CHAR(1)  DEFAULT '0' NOT NULL ,
    CONSTRAINT pk_t_privacy_task_r3 PRIMARY KEY (fid)
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_privacy_data_tag')
CREATE TABLE t_privacy_data_tag
(
    fid bigint NOT NULL,
    fnumber VARCHAR(50)   DEFAULT ' ' NOT NULL,
    fname VARCHAR(50)   DEFAULT ' ' NOT NULL ,
    fcreater bigint,
    fcreatedate datetime,
    fstatus VARCHAR(50) DEFAULT ' '  NOT NULL ,
    CONSTRAINT pk_privacy_data_tag PRIMARY KEY (fid)
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_privacy_data_tag_l')
CREATE TABLE t_privacy_data_tag_l
(
    fpkid VARCHAR(18)   NOT NULL,
    fid bigint NOT NULL,
    flocaleid VARCHAR(10)  NOT NULL,
    fname VARCHAR(50)    DEFAULT ' ' NOT NULL,
    CONSTRAINT pk_privacy_data_tag_l PRIMARY KEY (fpkid)
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_privacy_data_tag_r3')
CREATE TABLE  t_privacy_data_tag_r3
(
    fid bigint DEFAULT 0 NOT NULL ,
    frefstatus CHAR(1)   DEFAULT '0' NOT NULL,
    CONSTRAINT pk_t_privacy_data_tag_r3 PRIMARY KEY (fid)
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_privacy_data_tag_fields')
CREATE TABLE t_privacy_data_tag_fields
(
    fid bigint,
    fentity_number VARCHAR(100) ,
    ffield_ident VARCHAR(100) ,
    fdatatagid bigint,
    ffield_type VARCHAR(10) ,
    fapp_number VARCHAR(100) ,
    fcloud_number VARCHAR(100) ,
    fentryid bigint NOT NULL DEFAULT 0,
    fseq integer NOT NULL DEFAULT 0,
    ffield_name VARCHAR(50)  NOT NULL DEFAULT ' ',
    fentity_name VARCHAR(50)  NOT NULL DEFAULT ' ',
    fapp_name VARCHAR(50)  NOT NULL DEFAULT ' ',
    fcloud_name VARCHAR(50)  NOT NULL DEFAULT ' ',
    ffield_desc VARCHAR(60)  NOT NULL DEFAULT ' ',
    ftable_name VARCHAR(50)  NOT NULL DEFAULT ' ',
	fapp_route VARCHAR(50) NOT NULL DEFAULT ' ',
    CONSTRAINT t_privacy_data_tag_fields_pkey PRIMARY KEY (fentryid)
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_privacy_global_control') 
CREATE TABLE t_privacy_global_control
(
    fid bigint NOT NULL,
    fdailytotallimit bigint,
    fcontrolrule VARCHAR(50)  DEFAULT ' ' NOT NULL,
    fmessagechannel VARCHAR(50)  DEFAULT ' ' NOT NULL,
    ftemplate VARCHAR(500)  DEFAULT ' ' NOT NULL,
    fmodifierid bigint,
    fcreatetime datetime,
    fmodifytime datetime,
    CONSTRAINT pk_privacy_global_control PRIMARY KEY (fid)
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_privacy_global_receive') 
CREATE TABLE t_privacy_global_receive
(
    fpkid bigint NOT NULL,
    fid bigint NOT NULL,
    fbasedataid bigint NOT NULL,
    CONSTRAINT pk_privacy_global_receive PRIMARY KEY (fpkid)
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_privacy_encrypt_scheme') 
create table t_privacy_encrypt_scheme
(
    fid           bigint  not null,
    fdatacenterid VARCHAR(200) DEFAULT ' ' not null,
    ftenantid     VARCHAR(200) DEFAULT ' ' not null,
    fworksecretid VARCHAR(200) DEFAULT ' ' not null,
    falgorithm    VARCHAR(200) DEFAULT ' ' not null,
    fname         VARCHAR(200) DEFAULT ' ' not null,
    fdesc         VARCHAR(200),
	CONSTRAINT t_privacy_encrypt_scheme_pkey PRIMARY KEY (fid)
);
