Skip to content

[CICD] flyway를 도입한다 #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2023
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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok:1.18.28'

runtimeOnly 'org.mariadb.jdbc:mariadb-java-client:3.1.4'
implementation 'org.flywaydb:flyway-mysql:9.16.3'

implementation 'com.amazonaws:aws-java-sdk-s3:1.12.528'

Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/application-data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ spring:
default_batch_fetch_size: 1000
dialect: org.hibernate.dialect.MariaDBDialect
hibernate:
ddl-auto: update
ddl-auto: validate
flyway:
enabled: true
baseline-on-migrate: true
5 changes: 4 additions & 1 deletion src/main/resources/application-prod-data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ spring:
default_batch_fetch_size: 1000
dialect: org.hibernate.dialect.MariaDBDialect
hibernate:
ddl-auto: update
ddl-auto: validate
flyway:
enabled: true
baseline-on-migrate: true
176 changes: 176 additions & 0 deletions src/main/resources/db/migration/V1__init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
create table `interest`
(
`name` varchar(20) not null,
`identifier` varchar(255) not null,
primary key (`name`)
) engine = InnoDB;

-- User
create table `user`
(
`id` bigint not null auto_increment,
`state` enum ('ADMIN','DELETED','MODERATOR','USER') not null,
`visibility` enum ('PRIVATE','PUBLIC') not null,
`username` varchar(15) not null,
`name` varchar(20) not null,
`email` varchar(30) not null,
`identifier` varchar(255) not null,
primary key (`id`),
unique `USER_UNIQUE_USERNAME` (`username`),
unique `USER_UNIQUE_EMAIL` (`email`)
) engine = InnoDB;

create table `user_interest`
(
`user_id` bigint not null,
`interests` varchar(10),
constraint `USER_INTEREST_FK_USER` foreign key (`user_id`) references `user` (`id`)
) engine = InnoDB;

create table `profile_setting`
(
`user_id` bigint not null,
`badge_list` varchar(255),
primary key (`user_id`)
) engine = InnoDB;

-- Badge

create table `badge`
(
`id` bigint not null auto_increment,
`name` varchar(15) not null,
`identifier` varchar(255) not null,
primary key (`id`)
) engine = InnoDB;

create table `owning`
(
`acquired_at` datetime(6),
`badge_id` bigint not null,
`user_id` bigint not null,
primary key (`badge_id`, `user_id`),
constraint `OWNING_FK_BADGE` foreign key (`badge_id`) references `badge` (`id`)
) engine = InnoDB;

-- Relationship

create table `follow`
(
`target_id` bigint not null,
`user_id` bigint not null,
primary key (`target_id`, `user_id`)
) engine = InnoDB;

create table `block`
(
`target_id` bigint not null,
`user_id` bigint not null,
primary key (`target_id`, `user_id`)
) engine = InnoDB;

-- Group

create table `group`
(
`deleted` bit not null,
`id` bigint not null auto_increment,
`name` varchar(15) not null,
`description` varchar(200),
`identifier` varchar(255) not null,
`interest` varchar(255),
primary key (`id`)
) engine = InnoDB;

create table `group_user`
(
`group_id` bigint not null,
`registered_at` datetime(6),
`user_id` bigint not null,
`role` enum ('MANAGER','MEMBER') not null,
primary key (`group_id`, `user_id`),
constraint `GROUP_USER_FK_GROUP` foreign key (`group_id`) references `group` (`id`)
) engine = InnoDB;

-- Quest

create table `quest`
(
`badge_id` bigint,
`created_at` datetime(6),
`expired_at` datetime(6),
`group_id` bigint,
`id` bigint not null auto_increment,
`reward_count` bigint,
`category` enum ('GROUP','NORMAL') not null,
`state` enum ('ACTIVE','DELETED','LOCKED','NEED_LABEL') not null,
`label` varchar(15),
`title` varchar(30) not null,
`image_description` varchar(100) not null,
`content` varchar(300),
`interest_name` varchar(255),
primary key (`id`)
) engine = InnoDB;

create table `quest_image`
(
`quest_id` bigint not null,
`identifier` varchar(255) not null,
constraint `QUEST_IMAGE_FK_QUEST` foreign key (`quest_id`) references `quest` (`id`)
) engine = InnoDB;

create table `participant`
(
`linked_count` bigint,
`quest_id` bigint not null,
`user_id` bigint not null,
`state` enum ('CONTINUE','DOING','FINISHED','NOT') not null,
primary key (`quest_id`, `user_id`),
constraint `PARTICIPANT_FK_QUEST` foreign key (`quest_id`) references `quest` (`id`)
) engine = InnoDB;

-- Post

create table `post`
(
`id` bigint not null auto_increment,
`quest_id` bigint,
`updated_at` datetime(6),
`user_id` bigint not null,
`state` enum ('DELETED','FAIL','NEED_CHECK','NOT_DECIDED','SUCCESS') not null,
`content` varchar(500),
primary key (`id`)
) engine = InnoDB;

create table `post_image`
(
`order` integer not null,
`post_id` bigint not null,
`identifier` varchar(255) not null,
primary key (`order`, `post_id`),
constraint `POST_IMAGE_FK_POST` foreign key (`post_Id`) references `post` (`id`)
) engine = InnoDB;

create table `comment`
(
`id` bigint not null auto_increment,
`post_id` bigint not null,
`updated_at` datetime(6),
`user_id` bigint not null,
`content` varchar(200) not null,
primary key (`id`)
) engine = InnoDB;

create table `post_like`
(
`post_id` bigint not null,
`user_id` bigint not null,
primary key (`post_id`, `user_id`)
) engine = InnoDB;

create table `post_dislike`
(
`post_id` bigint not null,
`user_id` bigint not null,
primary key (`post_id`, `user_id`)
) engine = InnoDB;
18 changes: 14 additions & 4 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ logging:
root: debug

spring:
datasource:
url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=MYSQL
jpa:
show-sql: true
open-in-view: false
Expand All @@ -14,13 +16,21 @@ spring:
globally_quoted_identifiers: true
format_sql: true
default_batch_fetch_size: 1000

profile:
base-image-url: base.png
dialect: org.hibernate.dialect.MariaDBDialect
flyway:
enabled: true
baseline-on-migrate: true
test:
database:
replace: none

aws:
credentials:
access-key: test-access-key
secret-key: test-secret-key
region: ap-northeast-2
bucket: test-bucket
bucket: test-bucket

image:
base:
user-identifier: base.png