Skip to content

Commit

Permalink
Merge pull request #202 from kookmin-sw/fork/#125-flyway
Browse files Browse the repository at this point in the history
Fork/#125 flyway
  • Loading branch information
haram8009 authored May 9, 2024
2 parents 141641e + 605644c commit 72a4149
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 31 deletions.
4 changes: 4 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ dependencies {
implementation group: 'org.modelmapper', name: 'modelmapper', version: '2.1.1'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

// flyway
implementation 'org.flywaydb:flyway-core'
implementation 'org.flywaydb:flyway-mysql'

// s3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.modelmapper.convention.MatchingStrategies;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
Expand All @@ -29,6 +30,14 @@ public ModelMapper modelMapper() {
return mapper;
}

@Bean
public FlywayMigrationStrategy cleanMigrateStrategy() {
return flyway -> {
flyway.repair();
flyway.migrate();
};
}

public static void main(String[] args) {
SpringApplication.run(BackendApplication.class, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,4 @@ public class Company {
@ManyToOne
@JoinColumn(name = "logo_file_id")
private UploadFile logo;

// TODO : flyaway 설정 이후 default company로 설정 (company DB에 무소속 회사 정보가 있어야 함)
// public static Company getDefault() {
// return Company.builder().companyId(0L).name("무소속").domain("coffee.com").bno("0").build();
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ public class UserDto {
private String userUUID;
private String introduction;
private String deviceToken;
private Double coffeeBean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,4 @@ public class User {
private String userUUID;
private String introduction;
private String deviceToken;

// TODO : flyaway 설정 이후 default company로 설정 (company DB에 무소속 회사 정보가 있어야 함)
// @PrePersist
// private void prePersist() {
// if (company == null) {
// company = Company.getDefault();
// }
// }
}
15 changes: 9 additions & 6 deletions backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ spring:

jpa:
hibernate:
ddl-auto: update
properties:
hibernate:
dialect: org.hibernate.dialect.MySQL8Dialect
show-sql: true
format_sql: true
ddl-auto: validate
# properties:
# hibernate:
# dialect: org.hibernate.dialect.MySQL8Dialect
# format_sql: true

flyway:
enabled: true
baselineOnMigrate: true

profiles:
include: jwt,db
Expand Down
12 changes: 0 additions & 12 deletions backend/src/main/resources/data.sql

This file was deleted.

89 changes: 89 additions & 0 deletions backend/src/main/resources/db/migration/V1__init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
CREATE TABLE upload_file
(
file_id BIGINT AUTO_INCREMENT,
origin_filename VARCHAR(255),
stored_filename VARCHAR(255),
PRIMARY KEY (file_id)
);

CREATE TABLE company
(
company_id BIGINT AUTO_INCREMENT,
name VARCHAR(255),
domain VARCHAR(255),
bno VARCHAR(255),
logo_file_id BIGINT,
PRIMARY KEY (company_id),
FOREIGN KEY (logo_file_id) REFERENCES upload_file (file_id)
);

CREATE TABLE user
(
user_id BIGINT AUTO_INCREMENT,
login_id VARCHAR(255),
kakao_id BIGINT,
password VARCHAR(255),
coffee_bean double default 46 not null,
position tinyint default 0 null,
email VARCHAR(255),
nickname VARCHAR(255),
phone VARCHAR(255),
useruuid VARCHAR(255),
device_token VARCHAR(255),
introduction VARCHAR(255),
company_id BIGINT,
PRIMARY KEY (user_id),
FOREIGN KEY (company_id) REFERENCES company (company_id)
);

CREATE TABLE company_request
(
company_request_id BIGINT AUTO_INCREMENT,
user_id BIGINT,
name VARCHAR(255),
domain VARCHAR(255),
bno VARCHAR(255),
PRIMARY KEY (company_request_id),
FOREIGN KEY (user_id) REFERENCES user (user_id)
);

CREATE TABLE chatroom
(
chatroom_id BIGINT AUTO_INCREMENT,
PRIMARY KEY (chatroom_id)
);

CREATE TABLE message
(
message_id BIGINT AUTO_INCREMENT,
chatroom_id BIGINT,
sender_id BIGINT,
content VARCHAR(255),
created_at DATETIME(6),
PRIMARY KEY (message_id),
FOREIGN KEY (chatroom_id) REFERENCES chatroom (chatroom_id),
FOREIGN KEY (sender_id) REFERENCES user (user_id)
);

CREATE TABLE user_chatroom
(
user_chatroom_id BIGINT AUTO_INCREMENT,
user_id BIGINT,
chatroom_id BIGINT,
PRIMARY KEY (user_chatroom_id),
FOREIGN KEY (user_id) REFERENCES user (user_id),
FOREIGN KEY (chatroom_id) REFERENCES chatroom (chatroom_id)
);

CREATE TABLE review
(
review_id BIGINT AUTO_INCREMENT,
comment VARCHAR(255),
created_at DATETIME(6),
rating INT,
receiver_id BIGINT,
sender_id BIGINT,
PRIMARY KEY (review_id),
FOREIGN KEY (receiver_id) REFERENCES user (user_id),
FOREIGN KEY (sender_id) REFERENCES user (user_id)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# company 테이블의 seed data (커리어한잔, 구글) insert
INSERT INTO upload_file (file_id, origin_filename, stored_filename)
VALUES (1, 'coffeechat-logo.png', 'coffeechat-logo.png'),
(2, 'google-logo.png', 'google-logo.png');

INSERT INTO company (company_id, logo_file_id, bno, domain, name)
VALUES (1, 1, '00000000000', 'coffeechat.com', '커리어 한잔'),
(2, 2, '00000000000', 'gmail.com', 'google(구글)');

0 comments on commit 72a4149

Please sign in to comment.