Skip to content

Commit cc85e7a

Browse files
committed
feat: add database
1 parent 2f7cce9 commit cc85e7a

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

eggnews.sql

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
DROP DATABASE IF EXISTS eggnews;
2+
CREATE DATABASE IF NOT EXISTS eggnews;
3+
USE eggnews;
4+
5+
CREATE TABLE role (
6+
id_role INT AUTO_INCREMENT NOT NULL,
7+
name ENUM('ROLE_USER','ROLE_ADMIN') DEFAULT 'ROLE_USER' NOT NULL,
8+
PRIMARY KEY (id_role)
9+
) ENGINE = INNODB;
10+
11+
INSERT INTO role (name) VALUES ('ROLE_USER');
12+
INSERT INTO role (name) VALUES ('ROLE_ADMIN');
13+
14+
CREATE TABLE image (
15+
id_image INT AUTO_INCREMENT NOT NULL,
16+
name VARCHAR(150) NOT NULL,
17+
url VARCHAR(200) NOT NULL,
18+
PRIMARY KEY (id_image)
19+
) ENGINE = INNODB;
20+
21+
CREATE TABLE user (
22+
id_user BIGINT NOT NULL,
23+
email VARCHAR(150) NOT NULL,
24+
password VARCHAR(300) NOT NULL,
25+
names VARCHAR(100) NOT NULL,
26+
surnames VARCHAR(100) NOT NULL,
27+
is_active BOOLEAN NOT NULL DEFAULT TRUE,
28+
id_role INT NOT NULL,
29+
PRIMARY KEY (id_user),
30+
FOREIGN KEY (id_role) REFERENCES role (id_role)
31+
) ENGINE = INNODB;
32+
33+
CREATE TABLE user_sequence (
34+
next_val BIGINT NOT NULL
35+
) ENGINE = INNODB;
36+
37+
INSERT INTO user_sequence VALUES (1);
38+
39+
CREATE TABLE news (
40+
id_news BIGINT NOT NULL,
41+
title VARCHAR(150) NOT NULL,
42+
body VARCHAR(2500) NOT NULL,
43+
is_active BOOLEAN NOT NULL DEFAULT TRUE,
44+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
45+
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
46+
id_user BIGINT NOT NULL,
47+
id_image INT NOT NULL,
48+
PRIMARY KEY (id_news),
49+
FOREIGN KEY (id_user) REFERENCES user (id_user),
50+
FOREIGN KEY (id_image) REFERENCES image (id_image)
51+
) ENGINE = INNODB;
52+
53+
CREATE TABLE news_sequence (
54+
next_val BIGINT NOT NULL
55+
) ENGINE = INNODB;
56+
57+
INSERT INTO news_sequence VALUES (1);

0 commit comments

Comments
 (0)