Skip to content

Commit c9883e6

Browse files
authored
feat: init tables, swagger test, fix: env (#3)
1 parent 6c97017 commit c9883e6

File tree

5 files changed

+109
-14
lines changed

5 files changed

+109
-14
lines changed

compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ services:
77
- 'MYSQL_ROOT_PASSWORD=verysecret'
88
- 'MYSQL_USER=user'
99
ports:
10-
- '3306'
10+
- '3306:3306'
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
spring.application.name=23-5-team2-server
22

33
# Database Connection
4-
spring.datasource.url=jdbc:mysql:8.0://localhost:3306/${DB_NAME:mydatabase}
4+
spring.datasource.url=jdbc:mysql://localhost:3306/${DB_NAME:mydatabase}
55
spring.datasource.username=${DB_USER:user}
66
spring.datasource.password=${DB_PASSWORD:secret}
77
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
8-
9-
# Flyway Settings
10-
spring.flyway.enabled=true
11-
# Important: Flyway needs to find your migration scripts here
12-
spring.flyway.locations=classpath:db/migration
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
START TRANSACTION;
2+
3+
CREATE TABLE users (
4+
id BIGINT AUTO_INCREMENT PRIMARY KEY,
5+
local_id VARCHAR(255) UNIQUE,
6+
password VARCHAR(255),
7+
oauth_id VARCHAR(255) UNIQUE,
8+
oauth_provider VARCHAR(50),
9+
role INT NOT NULL DEFAULT 0,
10+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
11+
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
12+
);
13+
14+
CREATE TABLE boards (
15+
id BIGINT AUTO_INCREMENT PRIMARY KEY,
16+
name VARCHAR(255) NOT NULL,
17+
source_url VARCHAR(500),
18+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
19+
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
20+
);
21+
22+
CREATE TABLE articles (
23+
id BIGINT AUTO_INCREMENT PRIMARY KEY,
24+
board_id BIGINT NOT NULL,
25+
content TEXT NOT NULL,
26+
author VARCHAR(255) NOT NULL,
27+
origin_link VARCHAR(500),
28+
published_at TIMESTAMP NOT NULL,
29+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
30+
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
31+
FOREIGN KEY (board_id) REFERENCES boards(id) ON UPDATE CASCADE ON DELETE RESTRICT
32+
);
33+
34+
CREATE TABLE subscriptions (
35+
id BIGINT AUTO_INCREMENT PRIMARY KEY,
36+
user_id BIGINT NOT NULL,
37+
board_id BIGINT NOT NULL,
38+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
39+
UNIQUE (user_id, board_id),
40+
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE,
41+
FOREIGN KEY (board_id) REFERENCES boards(id) ON UPDATE CASCADE ON DELETE CASCADE
42+
);
43+
44+
CREATE TABLE inboxes (
45+
id BIGINT AUTO_INCREMENT PRIMARY KEY,
46+
user_id BIGINT NOT NULL,
47+
article_id BIGINT NOT NULL,
48+
is_read BOOLEAN NOT NULL DEFAULT FALSE,
49+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
50+
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE,
51+
FOREIGN KEY (article_id) REFERENCES articles(id) ON UPDATE CASCADE ON DELETE CASCADE
52+
);
53+
54+
CREATE TABLE image_metadata (
55+
id BIGINT AUTO_INCREMENT PRIMARY KEY,
56+
article_id BIGINT NOT NULL,
57+
url VARCHAR(500) NOT NULL,
58+
original_filename VARCHAR(255) NOT NULL,
59+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
60+
FOREIGN KEY (article_id) REFERENCES articles(id) ON UPDATE CASCADE ON DELETE CASCADE
61+
);
62+
63+
CREATE TABLE crawlers (
64+
id BIGINT AUTO_INCREMENT PRIMARY KEY,
65+
board_id BIGINT NOT NULL,
66+
next_update_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
67+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
68+
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
69+
FOREIGN KEY (board_id) REFERENCES boards(id) ON UPDATE CASCADE ON DELETE CASCADE
70+
);
71+
72+
CREATE TABLE bookmarks (
73+
id BIGINT AUTO_INCREMENT PRIMARY KEY,
74+
user_id BIGINT NOT NULL,
75+
article_id BIGINT NOT NULL,
76+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
77+
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE,
78+
FOREIGN KEY (article_id) REFERENCES articles(id) ON UPDATE CASCADE ON DELETE CASCADE
79+
);
80+
81+
CREATE TABLE emails (
82+
id BIGINT AUTO_INCREMENT PRIMARY KEY,
83+
user_id BIGINT NOT NULL,
84+
email VARCHAR(255) NOT NULL UNIQUE,
85+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
86+
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE
87+
);
88+
89+
COMMIT;

src/test/kotlin/com/wafflestudio/team2server/ApplicationTests.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
package com.wafflestudio.team2server
22

33
import org.junit.jupiter.api.Test
4+
import org.springframework.beans.factory.annotation.Autowired
45
import org.springframework.boot.test.context.SpringBootTest
56
import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc
67
import org.springframework.test.context.ActiveProfiles
8+
import org.springframework.test.web.servlet.MockMvc
9+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
10+
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
711
import org.testcontainers.junit.jupiter.Testcontainers
812

913
@SpringBootTest
1014
@ActiveProfiles("test")
1115
@Testcontainers
1216
@AutoConfigureMockMvc
13-
class ApplicationTests {
14-
@Test
15-
fun contextLoads() {
17+
class ApplicationTests
18+
@Autowired
19+
constructor(
20+
private val mvc: MockMvc,
21+
) {
22+
@Test
23+
fun swagger() {
24+
// swagger 정상 작동한다
25+
mvc
26+
.perform(
27+
get("/swagger-ui/index.html"),
28+
).andExpect(status().isOk)
29+
}
1630
}
17-
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
spring.config.activate.on-profile=test
2-
spring.datasource.url=jdbc:tc:mysql:8.0:///${DB_NAME:mydatabase}
1+
spring.datasource.url=jdbc:tc:mysql:///${DB_NAME:mydatabase}
32
spring.datasource.driver-class-name= org.testcontainers.jdbc.ContainerDatabaseDriver
4-
spring.flyway.enabled=true

0 commit comments

Comments
 (0)