From 3c0d768c4983a4624a8839ddb54aef3a0cc1fa39 Mon Sep 17 00:00:00 2001 From: aiaiaiai1 Date: Mon, 30 Sep 2024 18:33:34 +0900 Subject: [PATCH] fix: fix flyway --- .../resources/db/migration/V240930__init.sql | 7 +--- src/test/java/gymmi/containerTest.java | 37 +++++++++++++++++++ src/test/java/gymmi/withspringbootTest.java | 36 ++++++++++++++++++ src/test/resources/application-flyway.yml | 18 +++++++++ src/test/resources/application-test.yml | 3 ++ src/test/resources/application.yml | 3 -- 6 files changed, 96 insertions(+), 8 deletions(-) create mode 100644 src/test/java/gymmi/containerTest.java create mode 100644 src/test/java/gymmi/withspringbootTest.java create mode 100644 src/test/resources/application-flyway.yml diff --git a/src/main/resources/db/migration/V240930__init.sql b/src/main/resources/db/migration/V240930__init.sql index d20855a..55b8a11 100644 --- a/src/main/resources/db/migration/V240930__init.sql +++ b/src/main/resources/db/migration/V240930__init.sql @@ -7,7 +7,7 @@ create table uuser email varchar(255) default '' not null, login_id varchar(255) not null, nickname varchar(255) not null, - password varchar(255) not null, + password varchar(255) not null ) engine=InnoDB; create table feedback @@ -70,7 +70,7 @@ create table task ( id bigint not null auto_increment primary key, is_picked bit not null, - name varchar(255) not null, + name varchar(255) not null ) engine=InnoDB; create table worker @@ -90,13 +90,10 @@ create table worker create table worked ( - created_at timestamp(3) not null, id bigint not null auto_increment primary key, last_modified_at timestamp(3) not null, worker_id bigint not null, created_at timestamp(3) not null, - last_modified_at timestamp(3) not null, - primary key (id), foreign key (worker_id) references worker (id) ) engine=InnoDB; diff --git a/src/test/java/gymmi/containerTest.java b/src/test/java/gymmi/containerTest.java new file mode 100644 index 0000000..86eeb71 --- /dev/null +++ b/src/test/java/gymmi/containerTest.java @@ -0,0 +1,37 @@ +package gymmi; + +import org.flywaydb.core.Flyway; +import org.junit.jupiter.api.Test; +import org.springframework.test.context.ActiveProfiles; +import org.testcontainers.containers.MySQLContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.DriverManager; +import java.sql.SQLException; + +//@SpringBootTest +@ActiveProfiles("flyway") +@Testcontainers +public class containerTest { + + @Container + static MySQLContainer mySQLContainer = new MySQLContainer<>("mysql:8.4.0") + .withDatabaseName("flyway") + .withUsername("sa") + .withPassword("sa"); + + @Test + void flyway() throws SQLException { + Connection connection = DriverManager.getConnection(mySQLContainer.getJdbcUrl(), "sa", "sa"); + + DatabaseMetaData metaData = connection.getMetaData(); + System.out.println("metaData.getURL() = " + metaData.getURL()); + Flyway flyway = Flyway.configure() + .dataSource(mySQLContainer.getJdbcUrl(), "sa", "sa") + .load(); + flyway.migrate(); + } +} diff --git a/src/test/java/gymmi/withspringbootTest.java b/src/test/java/gymmi/withspringbootTest.java new file mode 100644 index 0000000..a11315c --- /dev/null +++ b/src/test/java/gymmi/withspringbootTest.java @@ -0,0 +1,36 @@ +package gymmi; + +import org.flywaydb.core.Flyway; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.testcontainers.containers.MySQLContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.DriverManager; +import java.sql.SQLException; + +@SpringBootTest +@ActiveProfiles("flyway") +@Testcontainers +@Disabled +public class withspringbootTest { + + @Container + static MySQLContainer mySQLContainer = new MySQLContainer<>("mysql:8.4.0") + .withDatabaseName("flyway") + .withUsername("sa") + .withPassword("sa"); + + @Test + void flyway() throws SQLException { + Connection connection = DriverManager.getConnection(mySQLContainer.getJdbcUrl(),"sa","sa"); + + DatabaseMetaData metaData = connection.getMetaData(); + System.out.println("metaData.getURL() = " + metaData.getURL()); + } +} diff --git a/src/test/resources/application-flyway.yml b/src/test/resources/application-flyway.yml new file mode 100644 index 0000000..2dccb20 --- /dev/null +++ b/src/test/resources/application-flyway.yml @@ -0,0 +1,18 @@ +spring: + config: + activate: + on-profile: flyway + + jpa: + hibernate: + ddl-auto: none + + flyway: + enabled: true + baseline-on-migrate: true + + h2: + console: + enabled: true + settings: + web-allow-others: true diff --git a/src/test/resources/application-test.yml b/src/test/resources/application-test.yml index b1039da..f0e32cc 100644 --- a/src/test/resources/application-test.yml +++ b/src/test/resources/application-test.yml @@ -7,6 +7,9 @@ spring: hibernate: ddl-auto: create-drop + flyway: + enabled: false + h2: console: enabled: true diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 535ec04..c5acd68 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -8,9 +8,6 @@ spring: format_sql: true show-sql: true - flyway: - enabled: false - jwt: token: secret-key: asdasdasdasdasdsadsasdadsadasdsadsa