Skip to content

Commit 38e2f6d

Browse files
committed
chore: 添加 Spring Security 测试数据,data.sql
1 parent 212ab3b commit 38e2f6d

2 files changed

Lines changed: 88 additions & 50 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
-- ----------------------------
2+
-- 插入用户
3+
-- 密码使用 BCryptPasswordEncoder 生成
4+
-- ----------------------------
5+
INSERT INTO security_user (username, password, nick_name, enable_flag)
6+
VALUE ('user', '$2a$10$mQJ9z.l0FW.pUSJ0BnrkjeMHrGJs96oGY3mzB1HZGSAvFgHoo2k1O', '用户', '1');
7+
INSERT INTO security_user (username, password, nick_name, enable_flag)
8+
VALUE ('admin', '$2a$10$uSg7P6ESwIbAalJIrPlc1uJ7szowzH/tUZsino2s3Bxz/ieqgCygm', '管理员', '1');
9+
-- ----------------------------
10+
-- 插入角色
11+
-- ----------------------------
12+
INSERT INTO security_role (code, name, description)
13+
VALUE ('user', '用户', '普通用户权限');
14+
INSERT INTO security_role (code, name, description)
15+
VALUE ('admin', '管理员', '管理员限');
16+
-- ----------------------------
17+
-- 插入 API
18+
-- ----------------------------
19+
INSERT INTO security_api(url, description)
20+
VALUE ('/api/demo/admin', '管理员测试接口');
21+
INSERT INTO security_api(url, description)
22+
VALUE ('/api/demo/user', '普通用户测试接口');
23+
-- ----------------------------
24+
-- 插入角色权限关系
25+
-- ----------------------------
26+
INSERT INTO security_role_api (role_id, api_id)
27+
VALUES (1, 2);
28+
INSERT INTO security_role_api (role_id, api_id)
29+
VALUES (2, 1);
30+
INSERT INTO security_role_api (role_id, api_id)
31+
VALUES (2, 2);
32+
-- ----------------------------
33+
-- 插入角色用户关系
34+
-- ----------------------------
35+
INSERT INTO security_role_user (role_id, user_id)
36+
VALUES (1, 1);
37+
INSERT INTO security_role_user (role_id, user_id)
38+
VALUES (2, 2);
Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,70 @@
11
-- ----------------------------
22
-- 系统用户表
33
-- ----------------------------
4-
create table security_user
4+
CREATE TABLE IF NOT EXISTS security_user
55
(
6-
id bigint unsigned auto_increment,
7-
username varchar(50) not null comment '用户名',
8-
password varchar(100) not null comment '密码',
9-
nick_name varchar(50) not null comment '昵称',
10-
enable_flag tinyint unsigned not null comment '是否启用',
11-
token char(36) comment 'token',
12-
token_time datetime comment 'token 时间',
13-
create_time datetime default current_timestamp,
14-
update_time datetime default null on update current_timestamp,
15-
primary key (id),
16-
constraint uk_username unique (username)
17-
) engine = InnoDB
18-
default charset = utf8
19-
comment '系统用户表';
6+
id BIGINT UNSIGNED AUTO_INCREMENT,
7+
username VARCHAR(50) NOT NULL COMMENT '用户名',
8+
password VARCHAR(100) NOT NULL COMMENT '密码',
9+
nick_name VARCHAR(50) NOT NULL COMMENT '昵称',
10+
enable_flag TINYINT UNSIGNED NOT NULL COMMENT '是否启用',
11+
token CHAR(36) COMMENT 'token',
12+
token_time DATETIME COMMENT 'token 时间',
13+
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
14+
update_time DATETIME DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
15+
PRIMARY KEY (id),
16+
CONSTRAINT uk_username UNIQUE (username)
17+
) ENGINE = InnoDB
18+
DEFAULT CHARSET = utf8
19+
COMMENT '系统用户表';
2020
-- ----------------------------
2121
-- 系统角色表
2222
-- ----------------------------
23-
create table security_role
23+
CREATE TABLE IF NOT EXISTS security_role
2424
(
25-
id bigint unsigned auto_increment,
26-
code varchar(50) not null comment '角色代码',
27-
name varchar(50) not null comment '角色名称',
28-
description varchar(100) comment '角色描述',
29-
create_time datetime default current_timestamp,
30-
update_time datetime default null on update current_timestamp,
31-
primary key (id),
32-
constraint uk_code unique (code)
33-
) engine = InnoDB
34-
default charset = utf8
35-
comment '系统角色表';
25+
id BIGINT UNSIGNED AUTO_INCREMENT,
26+
code VARCHAR(50) NOT NULL COMMENT '角色代码',
27+
name VARCHAR(50) NOT NULL COMMENT '角色名称',
28+
description VARCHAR(100) COMMENT '角色描述',
29+
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
30+
update_time DATETIME DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
31+
PRIMARY KEY (id),
32+
CONSTRAINT uk_code UNIQUE (code)
33+
) ENGINE = InnoDB
34+
DEFAULT CHARSET = utf8
35+
COMMENT '系统角色表';
3636
-- ----------------------------
3737
-- 系统权限表
3838
-- ----------------------------
39-
create table security_api
39+
CREATE TABLE IF NOT EXISTS security_api
4040
(
41-
id bigint unsigned auto_increment,
42-
url varchar(50) not null comment '接口路径',
43-
description varchar(100) comment '接口描述',
44-
create_time datetime default current_timestamp,
45-
update_time datetime default null on update current_timestamp,
46-
primary key (id),
47-
constraint uk_url unique (url)
48-
) engine = InnoDB
49-
default charset = utf8
50-
comment '系统权限表';
41+
id BIGINT UNSIGNED AUTO_INCREMENT,
42+
url VARCHAR(50) NOT NULL COMMENT '接口路径',
43+
description VARCHAR(100) COMMENT '接口描述',
44+
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
45+
update_time DATETIME DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
46+
PRIMARY KEY (id),
47+
CONSTRAINT uk_url UNIQUE (url)
48+
) ENGINE = InnoDB
49+
DEFAULT CHARSET = utf8
50+
COMMENT '系统权限表';
5151
-- ----------------------------
5252
-- 角色用户关系表
5353
-- ----------------------------
54-
create table security_role_user
54+
CREATE TABLE IF NOT EXISTS security_role_user
5555
(
56-
role_id bigint unsigned not null,
57-
user_id bigint unsigned not null
58-
) engine = InnoDB
59-
default charset = utf8
60-
comment '角色用户关系表';
56+
role_id BIGINT UNSIGNED NOT NULL,
57+
user_id BIGINT UNSIGNED NOT NULL
58+
) ENGINE = InnoDB
59+
DEFAULT CHARSET = utf8
60+
COMMENT '角色用户关系表';
6161
-- ----------------------------
6262
-- 角色权限关系表
6363
-- ----------------------------
64-
create table security_role_api
64+
CREATE TABLE IF NOT EXISTS security_role_api
6565
(
66-
role_id bigint unsigned not null,
67-
api_id bigint unsigned not null
68-
) engine = InnoDB
69-
default charset = utf8
70-
comment '角色权限关系表';
66+
role_id BIGINT UNSIGNED NOT NULL,
67+
api_id BIGINT UNSIGNED NOT NULL
68+
) ENGINE = InnoDB
69+
DEFAULT CHARSET = utf8
70+
COMMENT '角色权限关系表';

0 commit comments

Comments
 (0)