Skip to content

Commit

Permalink
fix: fix flyway
Browse files Browse the repository at this point in the history
  • Loading branch information
aiaiaiai1 committed Sep 30, 2024
1 parent aed4d60 commit 3c0d768
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 8 deletions.
7 changes: 2 additions & 5 deletions src/main/resources/db/migration/V240930__init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;

Expand Down
37 changes: 37 additions & 0 deletions src/test/java/gymmi/containerTest.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
36 changes: 36 additions & 0 deletions src/test/java/gymmi/withspringbootTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
18 changes: 18 additions & 0 deletions src/test/resources/application-flyway.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ spring:
hibernate:
ddl-auto: create-drop

flyway:
enabled: false

h2:
console:
enabled: true
Expand Down
3 changes: 0 additions & 3 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ spring:
format_sql: true
show-sql: true

flyway:
enabled: false

jwt:
token:
secret-key: asdasdasdasdasdsadsasdadsadasdsadsa
Expand Down

0 comments on commit 3c0d768

Please sign in to comment.