-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmyblog.sql
59 lines (52 loc) · 1.64 KB
/
myblog.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
## create database myblog;
## use myblog;
create table categories (
id bigint not null auto_increment,
description varchar(255),
name varchar(255),
primary key (id)
) engine=InnoDB DEFAULT CHARSET=utf8mb4;
create table comments (
id bigint not null auto_increment,
body varchar(255),
email varchar(255),
name varchar(255),
post_id bigint not null,
primary key (id),
foreign key (post_id) references posts (id) on delete cascade
) engine=InnoDB DEFAULT CHARSET=utf8mb4;
create table posts (
id bigint not null auto_increment,
content varchar(255) not null,
description varchar(255) not null,
title varchar(255) not null,
category_id bigint,
primary key (id),
unique key (title),
foreign key (category_id) references categories (id) on delete set null
) engine=InnoDB DEFAULT CHARSET=utf8mb4;
create table roles (
id bigint not null auto_increment,
name varchar(255),
primary key (id)
) engine=InnoDB DEFAULT CHARSET=utf8mb4;
create table users (
id bigint not null auto_increment,
email varchar(255) not null,
name varchar(255),
password varchar(255) not null,
username varchar(255) not null,
primary key (id),
unique key (email),
unique key (username)
) engine=InnoDB DEFAULT CHARSET=utf8mb4;
create table users_roles (
user_id bigint not null,
role_id bigint not null,
primary key (user_id, role_id),
foreign key (user_id) references users (id) on delete cascade,
foreign key (role_id) references roles (id) on delete cascade
) engine=InnoDB DEFAULT CHARSET=utf8mb4;
insert into roles values
(1, "ROLE_USER"),
(2, "ROLE_ADMIN");