-- ----------------------------
-- 表名：config_info
-- ----------------------------
CREATE TABLE config_info(
	id bigint IDENTITY(1, 1) PRIMARY KEY,
	data_id nvarchar(255) NOT NULL,
	group_id nvarchar(128),
	content ntext NOT NULL,
	md5 nvarchar(32),
	gmt_create datetime NOT NULL DEFAULT '2010-05-05 00:00:00',
	gmt_modified datetime NOT NULL DEFAULT '2010-05-05 00:00:00',
	src_user ntext,
	src_ip nvarchar(20),
	app_name nvarchar(128),
	tenant_id nvarchar(128) DEFAULT '',
	c_desc nvarchar(256),
	c_use nvarchar(64),
	effect nvarchar(64),
	type nvarchar(64),
	c_schema ntext,
	encrypted_data_key ntext NOT NULL
);
EXEC sp_addextendedproperty 'MS_Description',N'config_info','SCHEMA',N'dbo','TABLE',N'config_info';
EXEC sp_addextendedproperty 'MS_Description',N'id','SCHEMA',N'dbo','TABLE',N'config_info','COLUMN',N'id';
EXEC sp_addextendedproperty 'MS_Description',N'data_id','SCHEMA',N'dbo','TABLE',N'config_info','COLUMN',N'data_id';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'config_info','COLUMN',N'group_id';
EXEC sp_addextendedproperty 'MS_Description',N'content','SCHEMA',N'dbo','TABLE',N'config_info','COLUMN',N'content';
EXEC sp_addextendedproperty 'MS_Description',N'md5','SCHEMA',N'dbo','TABLE',N'config_info','COLUMN',N'md5';
EXEC sp_addextendedproperty 'MS_Description',N'创建时间','SCHEMA',N'dbo','TABLE',N'config_info','COLUMN',N'gmt_create';
EXEC sp_addextendedproperty 'MS_Description',N'修改时间','SCHEMA',N'dbo','TABLE',N'config_info','COLUMN',N'gmt_modified';
EXEC sp_addextendedproperty 'MS_Description',N'source user','SCHEMA',N'dbo','TABLE',N'config_info','COLUMN',N'src_user';
EXEC sp_addextendedproperty 'MS_Description',N'source ip','SCHEMA',N'dbo','TABLE',N'config_info','COLUMN',N'src_ip';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'config_info','COLUMN',N'app_name';
EXEC sp_addextendedproperty 'MS_Description',N'租户字段','SCHEMA',N'dbo','TABLE',N'config_info','COLUMN',N'tenant_id';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'config_info','COLUMN',N'c_desc';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'config_info','COLUMN',N'c_use';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'config_info','COLUMN',N'effect';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'config_info','COLUMN',N'type';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'config_info','COLUMN',N'c_schema';
EXEC sp_addextendedproperty 'MS_Description',N'秘钥','SCHEMA',N'dbo','TABLE',N'config_info','COLUMN',N'encrypted_data_key';


-- ----------------------------
-- Records of config_info
-- ----------------------------
-- ----------------------------
-- 表名：config_info_aggr
-- ----------------------------
CREATE TABLE config_info_aggr(
	id bigint IDENTITY(1, 1) PRIMARY KEY,
	data_id nvarchar(255) NOT NULL,
	group_id nvarchar(128) NOT NULL,
	datum_id nvarchar(255) NOT NULL,
	content ntext NOT NULL,
	gmt_modified datetime NOT NULL,
	app_name nvarchar(128),
	tenant_id nvarchar(128) DEFAULT ''
);
EXEC sp_addextendedproperty 'MS_Description',N'增加租户字段','SCHEMA',N'dbo','TABLE',N'config_info_aggr';
EXEC sp_addextendedproperty 'MS_Description',N'id','SCHEMA',N'dbo','TABLE',N'config_info_aggr','COLUMN',N'id';
EXEC sp_addextendedproperty 'MS_Description',N'data_id','SCHEMA',N'dbo','TABLE',N'config_info_aggr','COLUMN',N'data_id';
EXEC sp_addextendedproperty 'MS_Description',N'group_id','SCHEMA',N'dbo','TABLE',N'config_info_aggr','COLUMN',N'group_id';
EXEC sp_addextendedproperty 'MS_Description',N'datum_id','SCHEMA',N'dbo','TABLE',N'config_info_aggr','COLUMN',N'datum_id';
EXEC sp_addextendedproperty 'MS_Description',N'内容','SCHEMA',N'dbo','TABLE',N'config_info_aggr','COLUMN',N'content';
EXEC sp_addextendedproperty 'MS_Description',N'修改时间','SCHEMA',N'dbo','TABLE',N'config_info_aggr','COLUMN',N'gmt_modified';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'config_info_aggr','COLUMN',N'app_name';
EXEC sp_addextendedproperty 'MS_Description',N'租户字段','SCHEMA',N'dbo','TABLE',N'config_info_aggr','COLUMN',N'tenant_id';
-- ----------------------------
-- 表名：config_info_beta
-- ----------------------------
CREATE TABLE config_info_beta(
	id bigint IDENTITY(1, 1) PRIMARY KEY,
	data_id nvarchar(255) NOT NULL,
	group_id nvarchar(128) NOT NULL,
	app_name nvarchar(128),
	content ntext NOT NULL,
	beta_ips nvarchar(1024),
	md5 nvarchar(32),
	gmt_create datetime NOT NULL DEFAULT '2010-05-05 00:00:00',
	gmt_modified datetime NOT NULL DEFAULT '2010-05-05 00:00:00',
	src_user ntext,
	src_ip nvarchar(20),
	tenant_id nvarchar(128) DEFAULT '',
	encrypted_data_key ntext NOT NULL
);
EXEC sp_addextendedproperty 'MS_Description',N'config_info_beta','SCHEMA',N'dbo','TABLE',N'config_info_beta';
EXEC sp_addextendedproperty 'MS_Description',N'id','SCHEMA',N'dbo','TABLE',N'config_info_beta','COLUMN',N'id';
EXEC sp_addextendedproperty 'MS_Description',N'data_id','SCHEMA',N'dbo','TABLE',N'config_info_beta','COLUMN',N'data_id';
EXEC sp_addextendedproperty 'MS_Description',N'group_id','SCHEMA',N'dbo','TABLE',N'config_info_beta','COLUMN',N'group_id';
EXEC sp_addextendedproperty 'MS_Description',N'app_name','SCHEMA',N'dbo','TABLE',N'config_info_beta','COLUMN',N'app_name';
EXEC sp_addextendedproperty 'MS_Description',N'content','SCHEMA',N'dbo','TABLE',N'config_info_beta','COLUMN',N'content';
EXEC sp_addextendedproperty 'MS_Description',N'betaIps','SCHEMA',N'dbo','TABLE',N'config_info_beta','COLUMN',N'beta_ips';
EXEC sp_addextendedproperty 'MS_Description',N'md5','SCHEMA',N'dbo','TABLE',N'config_info_beta','COLUMN',N'md5';
EXEC sp_addextendedproperty 'MS_Description',N'创建时间','SCHEMA',N'dbo','TABLE',N'config_info_beta','COLUMN',N'gmt_create';
EXEC sp_addextendedproperty 'MS_Description',N'修改时间','SCHEMA',N'dbo','TABLE',N'config_info_beta','COLUMN',N'gmt_modified';
EXEC sp_addextendedproperty 'MS_Description',N'source user','SCHEMA',N'dbo','TABLE',N'config_info_beta','COLUMN',N'src_user';
EXEC sp_addextendedproperty 'MS_Description',N'source ip','SCHEMA',N'dbo','TABLE',N'config_info_beta','COLUMN',N'src_ip';
EXEC sp_addextendedproperty 'MS_Description',N'租户字段','SCHEMA',N'dbo','TABLE',N'config_info_beta','COLUMN',N'tenant_id';
EXEC sp_addextendedproperty 'MS_Description',N'秘钥','SCHEMA',N'dbo','TABLE',N'config_info_beta','COLUMN',N'encrypted_data_key';
-- ----------------------------
-- 表名：config_info_tag
-- ----------------------------
CREATE TABLE config_info_tag(
	id bigint IDENTITY(1, 1) PRIMARY KEY,
	data_id nvarchar(255) NOT NULL,
	group_id nvarchar(128) NOT NULL,
	tenant_id nvarchar(128) DEFAULT '',
	tag_id nvarchar(128) NOT NULL,
	app_name nvarchar(128),
	content ntext NOT NULL,
	md5 nvarchar(32),
	gmt_create datetime NOT NULL DEFAULT '2010-05-05 00:00:00',
	gmt_modified datetime NOT NULL DEFAULT '2010-05-05 00:00:00',
	src_user ntext,
	src_ip nvarchar(20)
);
EXEC sp_addextendedproperty 'MS_Description',N'config_info_tag','SCHEMA',N'dbo','TABLE',N'config_info_tag';
EXEC sp_addextendedproperty 'MS_Description',N'id','SCHEMA',N'dbo','TABLE',N'config_info_tag','COLUMN',N'id';
EXEC sp_addextendedproperty 'MS_Description',N'data_id','SCHEMA',N'dbo','TABLE',N'config_info_tag','COLUMN',N'data_id';
EXEC sp_addextendedproperty 'MS_Description',N'group_id','SCHEMA',N'dbo','TABLE',N'config_info_tag','COLUMN',N'group_id';
EXEC sp_addextendedproperty 'MS_Description',N'tenant_id','SCHEMA',N'dbo','TABLE',N'config_info_tag','COLUMN',N'tenant_id';
EXEC sp_addextendedproperty 'MS_Description',N'tag_id','SCHEMA',N'dbo','TABLE',N'config_info_tag','COLUMN',N'tag_id';
EXEC sp_addextendedproperty 'MS_Description',N'app_name','SCHEMA',N'dbo','TABLE',N'config_info_tag','COLUMN',N'app_name';
EXEC sp_addextendedproperty 'MS_Description',N'content','SCHEMA',N'dbo','TABLE',N'config_info_tag','COLUMN',N'content';
EXEC sp_addextendedproperty 'MS_Description',N'md5','SCHEMA',N'dbo','TABLE',N'config_info_tag','COLUMN',N'md5';
EXEC sp_addextendedproperty 'MS_Description',N'创建时间','SCHEMA',N'dbo','TABLE',N'config_info_tag','COLUMN',N'gmt_create';
EXEC sp_addextendedproperty 'MS_Description',N'修改时间','SCHEMA',N'dbo','TABLE',N'config_info_tag','COLUMN',N'gmt_modified';
EXEC sp_addextendedproperty 'MS_Description',N'source user','SCHEMA',N'dbo','TABLE',N'config_info_tag','COLUMN',N'src_user';
EXEC sp_addextendedproperty 'MS_Description',N'source ip','SCHEMA',N'dbo','TABLE',N'config_info_tag','COLUMN',N'src_ip';
-- ----------------------------
-- 表名：config_tags_relation
-- ----------------------------
CREATE TABLE config_tags_relation(
	id bigint NOT NULL,
	tag_name nvarchar(128) NOT NULL,
	tag_type nvarchar(64),
	data_id nvarchar(255) NOT NULL,
	group_id nvarchar(128) NOT NULL,
	tenant_id nvarchar(128) DEFAULT '',
	nid bigint IDENTITY(1, 1) PRIMARY KEY
);
EXEC sp_addextendedproperty 'MS_Description',N'config_tag_relation','SCHEMA',N'dbo','TABLE',N'config_tags_relation';
EXEC sp_addextendedproperty 'MS_Description',N'id','SCHEMA',N'dbo','TABLE',N'config_tags_relation','COLUMN',N'id';
EXEC sp_addextendedproperty 'MS_Description',N'tag_name','SCHEMA',N'dbo','TABLE',N'config_tags_relation','COLUMN',N'tag_name';
EXEC sp_addextendedproperty 'MS_Description',N'tag_type','SCHEMA',N'dbo','TABLE',N'config_tags_relation','COLUMN',N'tag_type';
EXEC sp_addextendedproperty 'MS_Description',N'data_id','SCHEMA',N'dbo','TABLE',N'config_tags_relation','COLUMN',N'data_id';
EXEC sp_addextendedproperty 'MS_Description',N'group_id','SCHEMA',N'dbo','TABLE',N'config_tags_relation','COLUMN',N'group_id';
EXEC sp_addextendedproperty 'MS_Description',N'tenant_id','SCHEMA',N'dbo','TABLE',N'config_tags_relation','COLUMN',N'tenant_id';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'config_tags_relation','COLUMN',N'nid';
-- ----------------------------
-- 表名：group_capacity
-- ----------------------------
CREATE TABLE group_capacity(
	id bigint IDENTITY(1, 1) PRIMARY KEY,
	group_id nvarchar(128) NOT NULL DEFAULT '',
	quota int NOT NULL DEFAULT '0',
	usage int NOT NULL DEFAULT '0',
	max_size int NOT NULL DEFAULT '0',
	max_aggr_count int NOT NULL DEFAULT '0',
	max_aggr_size int NOT NULL DEFAULT '0',
	max_history_count int NOT NULL DEFAULT '0',
	gmt_create datetime NOT NULL DEFAULT '2010-05-05 00:00:00',
	gmt_modified datetime NOT NULL DEFAULT '2010-05-05 00:00:00'
);
EXEC sp_addextendedproperty 'MS_Description',N'集群、各Group容量信息表','SCHEMA',N'dbo','TABLE',N'group_capacity';
EXEC sp_addextendedproperty 'MS_Description',N'主键ID','SCHEMA',N'dbo','TABLE',N'group_capacity','COLUMN',N'id';
EXEC sp_addextendedproperty 'MS_Description',N'Group ID，空字符表示整个集群','SCHEMA',N'dbo','TABLE',N'group_capacity','COLUMN',N'group_id';
EXEC sp_addextendedproperty 'MS_Description',N'配额，0表示使用默认值','SCHEMA',N'dbo','TABLE',N'group_capacity','COLUMN',N'quota';
EXEC sp_addextendedproperty 'MS_Description',N'使用量','SCHEMA',N'dbo','TABLE',N'group_capacity','COLUMN',N'usage';
EXEC sp_addextendedproperty 'MS_Description',N'单个配置大小上限，单位为字节，0表示使用默认值','SCHEMA',N'dbo','TABLE',N'group_capacity','COLUMN',N'max_size';
EXEC sp_addextendedproperty 'MS_Description',N'聚合子配置最大个数，，0表示使用默认值','SCHEMA',N'dbo','TABLE',N'group_capacity','COLUMN',N'max_aggr_count';
EXEC sp_addextendedproperty 'MS_Description',N'单个聚合数据的子配置大小上限，单位为字节，0表示使用默认值','SCHEMA',N'dbo','TABLE',N'group_capacity','COLUMN',N'max_aggr_size';
EXEC sp_addextendedproperty 'MS_Description',N'最大变更历史数量','SCHEMA',N'dbo','TABLE',N'group_capacity','COLUMN',N'max_history_count';
EXEC sp_addextendedproperty 'MS_Description',N'创建时间','SCHEMA',N'dbo','TABLE',N'group_capacity','COLUMN',N'gmt_create';
EXEC sp_addextendedproperty 'MS_Description',N'修改时间','SCHEMA',N'dbo','TABLE',N'group_capacity','COLUMN',N'gmt_modified';
-- ----------------------------
-- 表名：his_config_info
-- ----------------------------
CREATE TABLE his_config_info(
	id bigint NOT NULL,
	nid bigint IDENTITY(1, 1) PRIMARY KEY,
	data_id nvarchar(255) NOT NULL,
	group_id nvarchar(128) NOT NULL,
	app_name nvarchar(128),
	content ntext NOT NULL,
	md5 nvarchar(32),
	gmt_create datetime NOT NULL DEFAULT '2010-05-05 00:00:00',
	gmt_modified datetime NOT NULL DEFAULT '2010-05-05 00:00:00',
	src_user ntext,
	src_ip nvarchar(20),
	op_type char(10),
	tenant_id nvarchar(128) DEFAULT '',
	encrypted_data_key ntext NOT NULL
);
EXEC sp_addextendedproperty 'MS_Description',N'多租户改造','SCHEMA',N'dbo','TABLE',N'his_config_info';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'his_config_info','COLUMN',N'id';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'his_config_info','COLUMN',N'nid';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'his_config_info','COLUMN',N'data_id';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'his_config_info','COLUMN',N'group_id';
EXEC sp_addextendedproperty 'MS_Description',N'app_name','SCHEMA',N'dbo','TABLE',N'his_config_info','COLUMN',N'app_name';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'his_config_info','COLUMN',N'content';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'his_config_info','COLUMN',N'md5';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'his_config_info','COLUMN',N'gmt_create';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'his_config_info','COLUMN',N'gmt_modified';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'his_config_info','COLUMN',N'src_user';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'his_config_info','COLUMN',N'src_ip';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'his_config_info','COLUMN',N'op_type';
EXEC sp_addextendedproperty 'MS_Description',N'租户字段','SCHEMA',N'dbo','TABLE',N'his_config_info','COLUMN',N'tenant_id';
EXEC sp_addextendedproperty 'MS_Description',N'秘钥','SCHEMA',N'dbo','TABLE',N'his_config_info','COLUMN',N'encrypted_data_key';
-- ----------------------------
-- 表名：permissions
-- ----------------------------
CREATE TABLE permissions(
	role nvarchar(50) NOT NULL,
	resource nvarchar(512) NOT NULL,
	action nvarchar(8) NOT NULL
);
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'permissions';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'permissions','COLUMN',N'role';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'permissions','COLUMN',N'resource';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'permissions','COLUMN',N'action';
-- ----------------------------
-- 表名：roles
-- ----------------------------
CREATE TABLE roles(
	username nvarchar(50) NOT NULL,
	role nvarchar(50) NOT NULL
);
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'roles';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'roles','COLUMN',N'username';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'roles','COLUMN',N'role';
DELETE FROM roles;
INSERT INTO roles (role,username) VALUES ('ROLE_ADMIN','nacos');
-- ----------------------------
-- 表名：tenant_capacity
-- ----------------------------
CREATE TABLE tenant_capacity(
	id bigint IDENTITY(1, 1) PRIMARY KEY,
	tenant_id nvarchar(128) NOT NULL DEFAULT '',
	quota int NOT NULL DEFAULT '0',
	usage int NOT NULL DEFAULT '0',
	max_size int NOT NULL DEFAULT '0',
	max_aggr_count int NOT NULL DEFAULT '0',
	max_aggr_size int NOT NULL DEFAULT '0',
	max_history_count int NOT NULL DEFAULT '0',
	gmt_create datetime NOT NULL DEFAULT '2010-05-05 00:00:00',
	gmt_modified datetime NOT NULL DEFAULT '2010-05-05 00:00:00'
);
EXEC sp_addextendedproperty 'MS_Description',N'租户容量信息表','SCHEMA',N'dbo','TABLE',N'tenant_capacity';
EXEC sp_addextendedproperty 'MS_Description',N'主键ID','SCHEMA',N'dbo','TABLE',N'tenant_capacity','COLUMN',N'id';
EXEC sp_addextendedproperty 'MS_Description',N'Tenant ID','SCHEMA',N'dbo','TABLE',N'tenant_capacity','COLUMN',N'tenant_id';
EXEC sp_addextendedproperty 'MS_Description',N'配额，0表示使用默认值','SCHEMA',N'dbo','TABLE',N'tenant_capacity','COLUMN',N'quota';
EXEC sp_addextendedproperty 'MS_Description',N'使用量','SCHEMA',N'dbo','TABLE',N'tenant_capacity','COLUMN',N'usage';
EXEC sp_addextendedproperty 'MS_Description',N'单个配置大小上限，单位为字节，0表示使用默认值','SCHEMA',N'dbo','TABLE',N'tenant_capacity','COLUMN',N'max_size';
EXEC sp_addextendedproperty 'MS_Description',N'聚合子配置最大个数','SCHEMA',N'dbo','TABLE',N'tenant_capacity','COLUMN',N'max_aggr_count';
EXEC sp_addextendedproperty 'MS_Description',N'单个聚合数据的子配置大小上限，单位为字节，0表示使用默认值','SCHEMA',N'dbo','TABLE',N'tenant_capacity','COLUMN',N'max_aggr_size';
EXEC sp_addextendedproperty 'MS_Description',N'最大变更历史数量','SCHEMA',N'dbo','TABLE',N'tenant_capacity','COLUMN',N'max_history_count';
EXEC sp_addextendedproperty 'MS_Description',N'创建时间','SCHEMA',N'dbo','TABLE',N'tenant_capacity','COLUMN',N'gmt_create';
EXEC sp_addextendedproperty 'MS_Description',N'修改时间','SCHEMA',N'dbo','TABLE',N'tenant_capacity','COLUMN',N'gmt_modified';
-- ----------------------------
-- 表名：tenant_info
-- ----------------------------
CREATE TABLE tenant_info(
	id bigint IDENTITY(1, 1) PRIMARY KEY,
	kp nvarchar(128) NOT NULL,
	tenant_id nvarchar(128) DEFAULT '',
	tenant_name nvarchar(128) DEFAULT '',
	tenant_desc nvarchar(256),
	create_source nvarchar(32),
	gmt_create bigint NOT NULL,
	gmt_modified bigint NOT NULL
);
EXEC sp_addextendedproperty 'MS_Description',N'tenant_info','SCHEMA',N'dbo','TABLE',N'tenant_info';
EXEC sp_addextendedproperty 'MS_Description',N'id','SCHEMA',N'dbo','TABLE',N'tenant_info','COLUMN',N'id';
EXEC sp_addextendedproperty 'MS_Description',N'kp','SCHEMA',N'dbo','TABLE',N'tenant_info','COLUMN',N'kp';
EXEC sp_addextendedproperty 'MS_Description',N'tenant_id','SCHEMA',N'dbo','TABLE',N'tenant_info','COLUMN',N'tenant_id';
EXEC sp_addextendedproperty 'MS_Description',N'tenant_name','SCHEMA',N'dbo','TABLE',N'tenant_info','COLUMN',N'tenant_name';
EXEC sp_addextendedproperty 'MS_Description',N'tenant_desc','SCHEMA',N'dbo','TABLE',N'tenant_info','COLUMN',N'tenant_desc';
EXEC sp_addextendedproperty 'MS_Description',N'create_source','SCHEMA',N'dbo','TABLE',N'tenant_info','COLUMN',N'create_source';
EXEC sp_addextendedproperty 'MS_Description',N'创建时间','SCHEMA',N'dbo','TABLE',N'tenant_info','COLUMN',N'gmt_create';
EXEC sp_addextendedproperty 'MS_Description',N'修改时间','SCHEMA',N'dbo','TABLE',N'tenant_info','COLUMN',N'gmt_modified';

-- ----------------------------
-- Records of tenant_info
-- ----------------------------
SET IDENTITY_INSERT [dbo].[tenant_info] ON
GO

INSERT INTO [dbo].[tenant_info] ([id], [kp], [tenant_id], [tenant_name], [tenant_desc], [create_source], [gmt_create], [gmt_modified]) VALUES (N'1', N'1', N'69c4eecb-05bd-4041-81fe-1473f95f578c', N'develop', N'开发环境', N'nacos', N'1683356808848', N'1683356808848')
GO

INSERT INTO [dbo].[tenant_info] ([id], [kp], [tenant_id], [tenant_name], [tenant_desc], [create_source], [gmt_create], [gmt_modified]) VALUES (N'3', N'1', N'f50f4948-3ca2-48af-8bb1-1a47950b503d', N'pre', N'预发环境', N'nacos', N'1683356831775', N'1683356831775')
GO

INSERT INTO [dbo].[tenant_info] ([id], [kp], [tenant_id], [tenant_name], [tenant_desc], [create_source], [gmt_create], [gmt_modified]) VALUES (N'4', N'1', N'1e017954-eb52-4d21-a843-0286d9013cf3', N'staging', N'测试环境', N'nacos', N'1683356849309', N'1683356849309')
GO

INSERT INTO [dbo].[tenant_info] ([id], [kp], [tenant_id], [tenant_name], [tenant_desc], [create_source], [gmt_create], [gmt_modified]) VALUES (N'5', N'1', N'3baec428-9669-486c-b359-a76f7a1f1ac7', N'production', N'生产环境', N'nacos', N'1683356861156', N'1683356861156')
GO

SET IDENTITY_INSERT [dbo].[tenant_info] OFF
GO
-- ----------------------------
-- 表名：users
-- ----------------------------
CREATE TABLE users(
	username nvarchar(50) NOT NULL PRIMARY KEY,
	password nvarchar(500) NOT NULL,
	enabled nvarchar(15) NOT NULL
);
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'users';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'users','COLUMN',N'username';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'users','COLUMN',N'password';
EXEC sp_addextendedproperty 'MS_Description',N'','SCHEMA',N'dbo','TABLE',N'users','COLUMN',N'enabled';
DELETE FROM users;
INSERT INTO users (password,enabled,username) VALUES ('$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu','true','nacos');

-- 唯一索引
CREATE UNIQUE INDEX uk_configinfo_datagrouptenant ON config_info(data_id,group_id,tenant_id);
CREATE UNIQUE INDEX uk_configinfoaggr_datagrouptenantdatum ON config_info_aggr(data_id,group_id,tenant_id,datum_id);
CREATE UNIQUE INDEX uk_configinfobeta_datagrouptenant ON config_info_beta(data_id,group_id,tenant_id);
CREATE UNIQUE INDEX uk_configinfotag_datagrouptenanttag ON config_info_tag(data_id,group_id,tenant_id,tag_id);
CREATE UNIQUE INDEX uk_configtagrelation_configidtag ON config_tags_relation(id,tag_name,tag_type);
CREATE UNIQUE INDEX uk_group_id ON group_capacity(group_id);
CREATE UNIQUE INDEX uk_role_permission ON permissions(role,resource,action);
CREATE UNIQUE INDEX uk_username_role ON roles(username,role);
CREATE UNIQUE INDEX uk_tenant_id ON tenant_capacity(tenant_id);
CREATE UNIQUE INDEX uk_tenant_info_kptenantid ON tenant_info(kp,tenant_id);

CREATE TABLE [global_table]
(
    [xid]                       nvarchar(128)  NOT NULL,
    [transaction_id]            bigint        NULL,
    [status]                    tinyint       NOT NULL,
    [application_id]            nvarchar(32)   NULL,
    [transaction_service_group] nvarchar(32)   NULL,
    [transaction_name]          nvarchar(128)  NULL,
    [timeout]                   int           NULL,
    [begin_time]                bigint        NULL,
    [application_data]          nvarchar(2000) NULL,
    [gmt_create]                datetime2      NULL,
    [gmt_modified]              datetime2      NULL,
    PRIMARY KEY CLUSTERED ([xid])
    WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
    )
    GO

CREATE NONCLUSTERED INDEX [idx_gmt_modified_status]
    ON [global_table] (
                       [gmt_modified],
                       [status]
        )
GO

CREATE NONCLUSTERED INDEX [idx_transaction_id]
    ON [global_table] (
                       [transaction_id]
        )
GO

-- the table to store BranchSession data
CREATE TABLE [branch_table]
(
    [branch_id]         bigint        NOT NULL,
    [xid]               nvarchar(128)  NOT NULL,
    [transaction_id]    bigint        NULL,
    [resource_group_id] nvarchar(32)   NULL,
    [resource_id]       nvarchar(256)  NULL,
    [branch_type]       varchar(8)    NULL,
    [status]            tinyint       NULL,
    [client_id]         nvarchar(64)   NULL,
    [application_data]  nvarchar(2000) NULL,
    [gmt_create]        datetime2      NULL,
    [gmt_modified]      datetime2      NULL,
    PRIMARY KEY CLUSTERED ([branch_id])
    WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
    )
    GO

CREATE NONCLUSTERED INDEX [idx_xid]
    ON [branch_table] (
                       [xid]
        )
GO

-- the table to store lock data
CREATE TABLE [lock_table]
(
    [row_key]        nvarchar(128) NOT NULL,
    [xid]            nvarchar(128) NULL,
    [transaction_id] bigint       NULL,
    [branch_id]      bigint       NOT NULL,
    [resource_id]    nvarchar(256) NULL,
    [table_name]     nvarchar(32)  NULL,
    [pk]             nvarchar(128)  NULL,
    [status]            tinyint       NULL,
    [gmt_create]     datetime2     NULL,
    [gmt_modified]   datetime2     NULL,
    PRIMARY KEY CLUSTERED ([row_key])
    WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
    )
    GO

CREATE NONCLUSTERED INDEX [idx_status]
    ON [lock_table] (
                     [status]
        )
GO

CREATE NONCLUSTERED INDEX [idx_branch_id]
    ON [lock_table] (
                     [branch_id]
        )
GO

-- the table to store distributed lock constants
CREATE TABLE [distributed_lock]
(
    [lock_key]   char(20)    not null primary key,
    [lock_value] varchar(20) not null,
    [expire]     bigint
    )
    GO

    INSERT INTO [distributed_lock] (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0);
INSERT INTO [distributed_lock] (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0);
INSERT INTO [distributed_lock] (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0);
INSERT INTO [distributed_lock] (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0);
INSERT INTO [distributed_lock] (lock_key, lock_value, expire) VALUES ('UndologDelete', ' ', 0);

CREATE TABLE [vgroup_table]
(
    [vGroup]    nvarchar(255) NOT NULL,
    [namespace] nvarchar(255) NOT NULL,
    [cluster]   nvarchar(255) NOT NULL,
    PRIMARY KEY CLUSTERED ([vGroup])
    WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
    )