-- DROP SCHEMA "nacos_sit";

CREATE SCHEMA "nacos_sit" AUTHORIZATION "itc_dne";
-- "nacos_sit"."config_info" definition

-- Drop table

-- DROP TABLE "config_info";

CREATE TABLE "config_info" (
	"id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY,
	"data_id" character varying(255 char) NOT NULL DEFAULT NULL::varchar,
	"group_id" character varying(128 char) NULL,
	"content" text NOT NULL DEFAULT NULL::varchar,
	"md5" character varying(32 char) NULL,
	"gmt_create" timestamp without time zone NOT NULL DEFAULT LOCALTIMESTAMP,
	"gmt_modified" timestamp without time zone NOT NULL DEFAULT LOCALTIMESTAMP,
	"src_user" text NULL DEFAULT NULL::varchar,
	"src_ip" character varying(50 char) NULL,
	"app_name" character varying(128 char) NULL,
	"tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
	"c_desc" character varying(256 char) NULL,
	"c_use" character varying(64 char) NULL,
	"effect" character varying(64 char) NULL,
	"type" character varying(64 char) NULL,
	"c_schema" text NULL,
	"encrypted_data_key" text NULL,
	CONSTRAINT "config_info_pkey" PRIMARY KEY (id)
);
CREATE UNIQUE INDEX uk_configinfo_1 ON nacos_sit.config_info USING btree (data_id, group_id, tenant_id);

-- Table Triggers

CREATE OR REPLACE TRIGGER trg_config_info_id BEFORE INSERT ON nacos_sit.config_info FOR EACH ROW 
BEGIN
  IF :NEW.id IS NULL THEN
    SELECT seq_config_info.NEXTVAL INTO :NEW.id FROM dual;
  END IF;
END;
CREATE OR REPLACE TRIGGER trg_config_info_time BEFORE INSERT OR UPDATE ON nacos_sit.config_info FOR EACH ROW 
BEGIN
  IF INSERTING THEN
    :NEW.gmt_create := SYSDATE;  -- 插入时自动生成创建时间
  END IF;
  :NEW.gmt_modified := SYSDATE;  -- 插入/更新时自动更新修改时间
END;


-- "nacos_sit"."config_info_aggr" definition

-- Drop table

-- DROP TABLE "config_info_aggr";

CREATE TABLE "config_info_aggr" (
	"id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY,
	"data_id" character varying(255 char) NOT NULL,
	"group_id" character varying(128 char) NOT NULL,
	"datum_id" character varying(255 char) NOT NULL,
	"content" text NOT NULL,
	"gmt_modified" timestamp without time zone NOT NULL,
	"app_name" character varying(128 char) NULL,
	"tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
	CONSTRAINT "config_info_aggr_pkey" PRIMARY KEY (id)
);
CREATE UNIQUE INDEX uk_configinfoaggr_1 ON nacos_sit.config_info_aggr USING btree (data_id, group_id, tenant_id, datum_id);


-- "nacos_sit"."config_info_beta" definition

-- Drop table

-- DROP TABLE "config_info_beta";

CREATE TABLE "config_info_beta" (
	"id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY,
	"data_id" character varying(255 char) NOT NULL,
	"group_id" character varying(128 char) NOT NULL,
	"app_name" character varying(128 char) NULL,
	"content" text NOT NULL,
	"beta_ips" character varying(1024 char) NULL,
	"md5" character varying(32 char) NULL,
	"gmt_create" timestamp without time zone NOT NULL DEFAULT LOCALTIMESTAMP,
	"gmt_modified" timestamp without time zone NOT NULL DEFAULT LOCALTIMESTAMP,
	"src_user" text NULL,
	"src_ip" character varying(50 char) NULL,
	"tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
	"encrypted_data_key" text NULL,
	CONSTRAINT "config_info_beta_pkey" PRIMARY KEY (id)
);
CREATE UNIQUE INDEX uk_configinfobeta_1 ON nacos_sit.config_info_beta USING btree (data_id, group_id, tenant_id);


-- "nacos_sit"."config_info_gray" definition

-- Drop table

-- DROP TABLE "config_info_gray";

CREATE TABLE "config_info_gray" (
	"id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY,
	"data_id" character varying(255 char) NOT NULL,
	"group_id" character varying(128 char) NOT NULL,
	"content" text NOT NULL,
	"md5" character varying(32 char) NULL,
	"src_user" text NULL,
	"src_ip" character varying(100 char) NULL,
	"gmt_create" timestamp without time zone NOT NULL DEFAULT LOCALTIMESTAMP,
	"gmt_modified" timestamp without time zone NOT NULL DEFAULT LOCALTIMESTAMP,
	"app_name" character varying(128 char) NULL,
	"tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
	"gray_name" character varying(128 char) NOT NULL,
	"gray_rule" text NOT NULL,
	"encrypted_data_key" character varying(256 char) NOT NULL DEFAULT NULL::varchar,
	CONSTRAINT "config_info_gray_pkey" PRIMARY KEY (id)
);
CREATE INDEX idx_config_info_gray_1 ON nacos_sit.config_info_gray USING btree (data_id, gmt_modified);
CREATE INDEX idx_config_info_gray_2 ON nacos_sit.config_info_gray USING btree (gmt_modified);
CREATE UNIQUE INDEX uk_config_info_gray_1 ON nacos_sit.config_info_gray USING btree (data_id, group_id, tenant_id, gray_name);


-- "nacos_sit"."config_info_tag" definition

-- Drop table

-- DROP TABLE "config_info_tag";

CREATE TABLE "config_info_tag" (
	"id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY,
	"data_id" character varying(255 char) NOT NULL,
	"group_id" character varying(128 char) NOT NULL,
	"tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
	"tag_id" character varying(128 char) NOT NULL,
	"app_name" character varying(128 char) NULL,
	"content" text NOT NULL,
	"md5" character varying(32 char) NULL,
	"gmt_create" timestamp without time zone NOT NULL DEFAULT LOCALTIMESTAMP,
	"gmt_modified" timestamp without time zone NOT NULL DEFAULT LOCALTIMESTAMP,
	"src_user" text NULL,
	"src_ip" character varying(50 char) NULL,
	CONSTRAINT "config_info_tag_pkey" PRIMARY KEY (id)
);
CREATE UNIQUE INDEX uk_configinfotag_1 ON nacos_sit.config_info_tag USING btree (data_id, group_id, tenant_id, tag_id);


-- "nacos_sit"."config_tags_relation" definition

-- Drop table

-- DROP TABLE "config_tags_relation";

CREATE TABLE "config_tags_relation" (
	"id" bigint NOT NULL,
	"tag_name" character varying(128 char) NOT NULL,
	"tag_type" character varying(64 char) NULL,
	"data_id" character varying(255 char) NOT NULL,
	"group_id" character varying(128 char) NOT NULL,
	"tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
	"nid" bigint NOT NULL GENERATED ALWAYS AS IDENTITY,
	CONSTRAINT "config_tags_relation_pkey" PRIMARY KEY (nid)
);
CREATE INDEX idx_tenant_id ON nacos_sit.config_tags_relation USING btree (tenant_id);
CREATE UNIQUE INDEX uk_configtagrelation_1 ON nacos_sit.config_tags_relation USING btree (id, tag_name, tag_type);


-- "nacos_sit"."group_capacity" definition

-- Drop table

-- DROP TABLE "group_capacity";

CREATE TABLE "group_capacity" (
	"id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY,
	"group_id" character varying(128 char) NOT NULL DEFAULT NULL::varchar,
	"quota" integer NOT NULL DEFAULT 0,
	"usage" integer NOT NULL DEFAULT 0,
	"max_size" integer NOT NULL DEFAULT 0,
	"max_aggr_count" integer NOT NULL DEFAULT 0,
	"max_aggr_size" integer NOT NULL DEFAULT 0,
	"max_history_count" integer NOT NULL DEFAULT 0,
	"gmt_create" timestamp without time zone NOT NULL DEFAULT LOCALTIMESTAMP,
	"gmt_modified" timestamp without time zone NOT NULL DEFAULT LOCALTIMESTAMP,
	CONSTRAINT "group_capacity_pkey" PRIMARY KEY (id)
);
CREATE UNIQUE INDEX uk_groupcapacity_1 ON nacos_sit.group_capacity USING btree (group_id);


-- "nacos_sit"."his_config_info" definition

-- Drop table

-- DROP TABLE "his_config_info";

CREATE TABLE "his_config_info" (
	"id" bigint NOT NULL,
	"nid" bigint NOT NULL GENERATED ALWAYS AS IDENTITY,
	"data_id" character varying(255 char) NOT NULL DEFAULT NULL::varchar,
	"group_id" character varying(128 char) NOT NULL DEFAULT NULL::varchar,
	"app_name" character varying(128 char) NULL,
	"content" text NOT NULL DEFAULT NULL::varchar,
	"md5" character varying(32 char) NULL,
	"gmt_create" timestamp without time zone NOT NULL DEFAULT LOCALTIMESTAMP,
	"gmt_modified" timestamp without time zone NOT NULL DEFAULT LOCALTIMESTAMP,
	"src_user" text NULL,
	"src_ip" character varying(50 char) NULL,
	"op_type" character(10 char) NULL,
	"tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
	"encrypted_data_key" text NULL DEFAULT NULL::varchar,
	"publish_type" character varying(50 char) NULL DEFAULT 'formal'::varchar,
	"gray_name" character varying(50 char) NULL,
	"ext_info" text NULL,
	CONSTRAINT "his_config_info_pkey" PRIMARY KEY (nid)
);
CREATE INDEX idx_hisconfiginfo_1 ON nacos_sit.his_config_info USING btree (gmt_create);
CREATE INDEX idx_hisconfiginfo_2 ON nacos_sit.his_config_info USING btree (gmt_modified);
CREATE INDEX idx_hisconfiginfo_3 ON nacos_sit.his_config_info USING btree (data_id);

-- Table Triggers

CREATE OR REPLACE TRIGGER trg_his_config_info_nid BEFORE INSERT ON nacos_sit.his_config_info FOR EACH ROW 
BEGIN
  IF :NEW.nid IS NULL THEN
    SELECT seq_his_config_info.NEXTVAL INTO :NEW.nid FROM dual;
  END IF;
END;


-- "nacos_sit"."permissions" definition

-- Drop table

-- DROP TABLE "permissions";

CREATE TABLE "permissions" (
	"role" character varying(50 char) NOT NULL,
	"resource" character varying(255 char) NOT NULL,
	"action" character varying(8 char) NOT NULL
);
CREATE UNIQUE INDEX uk_permissions_1 ON nacos_sit.permissions USING btree (role, resource, action);


-- "nacos_sit"."roles" definition

-- Drop table

-- DROP TABLE "roles";

CREATE TABLE "roles" (
	"username" character varying(50 char) NOT NULL,
	"role" character varying(50 char) NOT NULL
);
CREATE UNIQUE INDEX uk_roles_1 ON nacos_sit.roles USING btree (username, role);


-- "nacos_sit"."tenant_capacity" definition

-- Drop table

-- DROP TABLE "tenant_capacity";

CREATE TABLE "tenant_capacity" (
	"id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY,
	"tenant_id" character varying(128 char) NOT NULL DEFAULT NULL::varchar,
	"quota" integer NOT NULL DEFAULT 0,
	"usage" integer NOT NULL DEFAULT 0,
	"max_size" integer NOT NULL DEFAULT 0,
	"max_aggr_count" integer NOT NULL DEFAULT 0,
	"max_aggr_size" integer NOT NULL DEFAULT 0,
	"max_history_count" integer NOT NULL DEFAULT 0,
	"gmt_create" timestamp without time zone NOT NULL DEFAULT LOCALTIMESTAMP,
	"gmt_modified" timestamp without time zone NOT NULL DEFAULT LOCALTIMESTAMP,
	CONSTRAINT "tenant_capacity_pkey" PRIMARY KEY (id)
);
CREATE UNIQUE INDEX uk_tenantcapacity_1 ON nacos_sit.tenant_capacity USING btree (tenant_id);


-- "nacos_sit"."tenant_info" definition

-- Drop table

-- DROP TABLE "tenant_info";

CREATE TABLE "tenant_info" (
	"id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY,
	"kp" character varying(128 char) NOT NULL,
	"tenant_id" character varying(128 char) NOT NULL DEFAULT NULL::varchar,
	"tenant_name" character varying(128 char) NULL DEFAULT NULL::varchar,
	"tenant_desc" character varying(256 char) NULL,
	"create_source" character varying(32 char) NULL,
	"gmt_create" bigint NOT NULL,
	"gmt_modified" bigint NOT NULL,
	CONSTRAINT "tenant_info_pkey" PRIMARY KEY (id)
);
CREATE INDEX idx_tenantinfo_1 ON nacos_sit.tenant_info USING btree (tenant_id);
CREATE UNIQUE INDEX uk_tenantinfo_1 ON nacos_sit.tenant_info USING btree (kp, tenant_id);


-- "nacos_sit"."users" definition

-- Drop table

-- DROP TABLE "users";

CREATE TABLE "users" (
	"username" character varying(50 char) NOT NULL,
	"password" character varying(500 char) NOT NULL,
	"enabled" smallint NOT NULL,
	CONSTRAINT "users_pkey" PRIMARY KEY (username)
);


INSERT INTO users (username, password, enabled) VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', 1);

INSERT INTO roles (username, role) VALUES ('nacos', 'ROLE_ADMIN');

INSERT INTO config_info( data_id, group_id, content, md5, gmt_create, gmt_modified, src_user, src_ip, app_name, tenant_id, c_desc, c_use, effect, type, c_schema, encrypted_data_key) VALUES ( 'seataServer.properties', 'SEATA_GROUP', '#For details about configuration items, see https://seata.io/zh-cn/docs/user/configurations.html\n#Transport configuration, for client and server\ntransport.type=TCP\ntransport.server=NIO\ntransport.heartbeat=true\ntransport.enableTmClientBatchSendRequest=false\ntransport.enableRmClientBatchSendRequest=true\ntransport.enableTcServerBatchSendResponse=false\ntransport.rpcRmRequestTimeout=30000\ntransport.rpcTmRequestTimeout=30000\ntransport.rpcTcRequestTimeout=30000\ntransport.threadFactory.bossThreadPrefix=NettyBoss\ntransport.threadFactory.workerThreadPrefix=NettyServerNIOWorker\ntransport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler\ntransport.threadFactory.shareBossWorker=false\ntransport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector\ntransport.threadFactory.clientSelectorThreadSize=1\ntransport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread\ntransport.threadFactory.bossThreadSize=1\ntransport.threadFactory.workerThreadSize=default\ntransport.shutdown.wait=3\ntransport.serialization=seata\ntransport.compressor=none\n\n#Transaction routing rules configuration, only for the client\nservice.vgroupMapping.default_tx_group=default\n#If you use a registry, you can ignore it\nservice.default.grouplist=127.0.0.1:8091\nservice.enableDegrade=false\nservice.disableGlobalTransaction=false\n\n#Transaction rule configuration, only for the client\nclient.rm.asyncCommitBufferLimit=10000\nclient.rm.lock.retryInterval=10\nclient.rm.lock.retryTimes=30\nclient.rm.lock.retryPolicyBranchRollbackOnConflict=true\nclient.rm.reportRetryCount=5\nclient.rm.tableMetaCheckEnable=false\nclient.rm.tableMetaCheckerInterval=60000\nclient.rm.sqlParserType=druid\nclient.rm.reportSuccessEnable=false\nclient.rm.sagaBranchRegisterEnable=false\nclient.rm.sagaJsonParser=fastjson\nclient.rm.tccActionInterceptorOrder=-2147482648\nclient.rm.sqlParserType=druid\nclient.tm.commitRetryCount=5\nclient.tm.rollbackRetryCount=5\nclient.tm.defaultGlobalTransactionTimeout=60000\nclient.tm.degradeCheck=false\nclient.tm.degradeCheckAllowTimes=10\nclient.tm.degradeCheckPeriod=2000\nclient.tm.interceptorOrder=-2147482648\nclient.undo.dataValidation=true\nclient.undo.logSerialization=jackson\nclient.undo.onlyCareUpdateColumns=true\nserver.undo.logSaveDays=7\nserver.undo.logDeletePeriod=86400000\nclient.undo.logTable=undo_log\nclient.undo.compress.enable=true\nclient.undo.compress.type=zip\nclient.undo.compress.threshold=64k\n#For TCC transaction mode\ntcc.fence.logTableName=tcc_fence_log\ntcc.fence.cleanPeriod=1h\n\n#Log rule configuration, for client and server\nlog.exceptionRate=100\n\n#Transaction storage configuration, only for the server. The file, DB, and redis configuration values are optional.\nstore.mode=db\nstore.lock.mode=db\nstore.session.mode=db\n#Used for password encryption\n#store.publicKey=\n\n#These configurations are required if the store mode is db. If store.mode,store.lock.mode,store.session.mode are not equal to db, you can remove the configuration block.\nstore.db.datasource=druid\nstore.db.dbType=mysql\nstore.db.driverClassName=com.mysql.cj.jdbc.Driver\nstore.db.url=jdbc:mysql://127.0.0.1:3306/nacos?useUnicode=true&rewriteBatchedStatements=true\nstore.db.user=root\nstore.db.password=root\nstore.db.minConn=5\nstore.db.maxConn=30\nstore.db.globalTable=global_table\nstore.db.branchTable=branch_table\nstore.db.distributedLockTable=distributed_lock\nstore.db.queryLimit=100\nstore.db.lockTable=lock_table\nstore.db.maxWait=5000\n\n#Transaction rule configuration, only for the server\nserver.recovery.committingRetryPeriod=1000\nserver.recovery.asynCommittingRetryPeriod=1000\nserver.recovery.rollbackingRetryPeriod=1000\nserver.recovery.timeoutRetryPeriod=1000\nserver.maxCommitRetryTimeout=-1\nserver.maxRollbackRetryTimeout=-1\nserver.rollbackRetryTimeoutUnlockEnable=false\nserver.distributedLockExpireTime=10000\nserver.session.branchAsyncQueueSize=5000\nserver.session.enableBranchAsyncRemove=true\n\n#Metrics configuration, only for the server\nmetrics.enabled=false\nmetrics.registryType=compact\nmetrics.exporterList=prometheus\nmetrics.exporterPrometheusPort=9898', '85090deb6ac0fc19cd8033f5b3cd8eed', '2025-09-08 10:21:51', '2025-09-08 10:21:51', NULL, '172.20.0.1', '', 'platform', '', NULL, NULL, 'properties', NULL, '');

