Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ services:
- 'MYSQL_ROOT_PASSWORD=verysecret'
- 'MYSQL_USER=user'
ports:
- '3306'
- '3306:3306'
7 changes: 1 addition & 6 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
spring.application.name=23-5-team2-server

# Database Connection
spring.datasource.url=jdbc:mysql:8.0://localhost:3306/${DB_NAME:mydatabase}
spring.datasource.url=jdbc:mysql://localhost:3306/${DB_NAME:mydatabase}
spring.datasource.username=${DB_USER:user}
spring.datasource.password=${DB_PASSWORD:secret}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

# Flyway Settings
spring.flyway.enabled=true
# Important: Flyway needs to find your migration scripts here
spring.flyway.locations=classpath:db/migration
89 changes: 89 additions & 0 deletions src/main/resources/db/migration/V1__init_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
START TRANSACTION;

CREATE TABLE users (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
local_id VARCHAR(255) UNIQUE,
password VARCHAR(255),
oauth_id VARCHAR(255) UNIQUE,
oauth_provider VARCHAR(50),
role INT NOT NULL DEFAULT 0,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

CREATE TABLE boards (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
source_url VARCHAR(500),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

CREATE TABLE articles (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
board_id BIGINT NOT NULL,
content TEXT NOT NULL,
author VARCHAR(255) NOT NULL,
origin_link VARCHAR(500),
published_at TIMESTAMP NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (board_id) REFERENCES boards(id) ON UPDATE CASCADE ON DELETE RESTRICT
);

CREATE TABLE subscriptions (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
user_id BIGINT NOT NULL,
board_id BIGINT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE (user_id, board_id),
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (board_id) REFERENCES boards(id) ON UPDATE CASCADE ON DELETE CASCADE
);

CREATE TABLE inboxes (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
user_id BIGINT NOT NULL,
article_id BIGINT NOT NULL,
is_read BOOLEAN NOT NULL DEFAULT FALSE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (article_id) REFERENCES articles(id) ON UPDATE CASCADE ON DELETE CASCADE
);

CREATE TABLE image_metadata (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
article_id BIGINT NOT NULL,
url VARCHAR(500) NOT NULL,
original_filename VARCHAR(255) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (article_id) REFERENCES articles(id) ON UPDATE CASCADE ON DELETE CASCADE
);

CREATE TABLE crawlers (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
board_id BIGINT NOT NULL,
next_update_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (board_id) REFERENCES boards(id) ON UPDATE CASCADE ON DELETE CASCADE
);

CREATE TABLE bookmarks (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
user_id BIGINT NOT NULL,
article_id BIGINT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (article_id) REFERENCES articles(id) ON UPDATE CASCADE ON DELETE CASCADE
);

CREATE TABLE emails (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
user_id BIGINT NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE
);

COMMIT;
21 changes: 17 additions & 4 deletions src/test/kotlin/com/wafflestudio/team2server/ApplicationTests.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
package com.wafflestudio.team2server

import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc
import org.springframework.test.context.ActiveProfiles
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import org.testcontainers.junit.jupiter.Testcontainers

@SpringBootTest
@ActiveProfiles("test")
@Testcontainers
@AutoConfigureMockMvc
class ApplicationTests {
@Test
fun contextLoads() {
class ApplicationTests
@Autowired
constructor(
private val mvc: MockMvc,
) {
@Test
fun swagger() {
// swagger 정상 작동한다
mvc
.perform(
get("/swagger-ui/index.html"),
).andExpect(status().isOk)
}
}
}
4 changes: 1 addition & 3 deletions src/test/resources/application-test.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
spring.config.activate.on-profile=test
spring.datasource.url=jdbc:tc:mysql:8.0:///${DB_NAME:mydatabase}
spring.datasource.url=jdbc:tc:mysql:///${DB_NAME:mydatabase}
spring.datasource.driver-class-name= org.testcontainers.jdbc.ContainerDatabaseDriver
spring.flyway.enabled=true