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
616 changes: 616 additions & 0 deletions .github/flyway/baseline-v8.sql

Large diffs are not rendered by default.

48 changes: 46 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,30 @@ on:

jobs:
build:
name: Build and Docker Image Check
name: Migration, Build and Docker Image Check
runs-on: ubuntu-latest

services:
mysql:
image: mysql:8.4.9
env:
MYSQL_DATABASE: slatto_ci
MYSQL_USER: slatto_ci
MYSQL_PASSWORD: ci-password
MYSQL_ROOT_PASSWORD: ci-root-password
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -h 127.0.0.1 -uroot -pci-root-password"
--health-interval=10s
--health-timeout=5s
--health-retries=10

env:
FLYWAY_URL: jdbc:mysql://127.0.0.1:3306/slatto_ci?serverTimezone=Asia/Seoul&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&useSSL=false
FLYWAY_USER: slatto_ci
FLYWAY_PASSWORD: ci-password

steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -27,8 +48,31 @@ jobs:
- name: Make Gradle Wrapper executable
run: chmod +x ./gradlew

- name: Load V8 baseline schema into CI MySQL
run: |
docker run --rm --network host \
-e MYSQL_PWD="$FLYWAY_PASSWORD" \
-i mysql:8.4.9 \
mysql --host=127.0.0.1 --user="$FLYWAY_USER" slatto_ci \
< .github/flyway/baseline-v8.sql

- name: Baseline and migrate CI MySQL
run: |
./gradlew flywayBaseline --no-daemon
./gradlew flywayInfo --no-daemon
./gradlew flywayMigrate --no-daemon
./gradlew flywayValidate --no-daemon

- name: Validate migrated schema against JPA entities
env:
FLYWAY_SCHEMA_VALIDATION: "true"
run: >-
./gradlew test
--tests com.slatto.global.database.FlywaySchemaValidationTest
--no-daemon

- name: Test and build Spring Boot jar
run: ./gradlew clean test bootJar --no-daemon

- name: Build Docker image
run: docker build -t slatto-api:ci .
run: docker build -t slatto-api:ci .
46 changes: 46 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.flywaydb:flyway-mysql:11.7.2'
classpath 'com.mysql:mysql-connector-j:9.7.0'
}
}

plugins {
id 'java'
id 'org.springframework.boot' version '3.5.15'
id 'io.spring.dependency-management' version '1.1.7'
id 'org.flywaydb.flyway' version '11.7.2'
}

group = 'com.slatto'
Expand All @@ -18,6 +29,41 @@ repositories {
mavenCentral()
}

flyway {
url = providers.environmentVariable('FLYWAY_URL').orNull
user = providers.environmentVariable('FLYWAY_USER').orNull
password = providers.environmentVariable('FLYWAY_PASSWORD').orNull
locations = ['filesystem:src/main/resources/db/migration']
baselineOnMigrate = true
baselineVersion = '8'
baselineDescription = 'legacy-schema'
validateOnMigrate = true
cleanDisabled = true
}

def flywayDatabaseTasks = [
'flywayBaseline',
'flywayClean',
'flywayInfo',
'flywayMigrate',
'flywayRepair',
'flywayUndo',
'flywayValidate'
]

tasks.matching { it.name in flywayDatabaseTasks }.configureEach {
doFirst {
def missingVariables = ['FLYWAY_URL', 'FLYWAY_USER', 'FLYWAY_PASSWORD']
.findAll { !providers.environmentVariable(it).orNull?.trim() }

if (!missingVariables.isEmpty()) {
throw new GradleException(
"Flyway task requires explicit environment variables: ${missingVariables.join(', ')}"
)
}
}
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- 파일 업로드 시 항상 저장되는 실제 파일 크기와 스키마 제약을 일치시킨다.
-- 운영 DB 확인 결과 file_size IS NULL 행은 0건이므로 별도 backfill은 필요하지 않다.

ALTER TABLE project_file
MODIFY COLUMN file_size BIGINT NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.slatto.global.database;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

@SpringBootTest
@ActiveProfiles("flyway-ci")
@EnabledIfEnvironmentVariable(named = "FLYWAY_SCHEMA_VALIDATION", matches = "true")
class FlywaySchemaValidationTest {

@Test
void migratedSchemaMatchesJpaEntities() {
}
}
19 changes: 19 additions & 0 deletions src/test/resources/application-flyway-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
spring:
config:
activate:
on-profile: flyway-ci

datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: ${FLYWAY_URL}
username: ${FLYWAY_USER}
password: ${FLYWAY_PASSWORD}

jpa:
database: mysql
database-platform: org.hibernate.dialect.MySQLDialect
hibernate:
ddl-auto: validate

flyway:
enabled: false
Loading