setup flyway with separate postgres for history info

This commit is contained in:
Rasmus Neikes 2024-08-26 00:01:58 +02:00
parent 209696539a
commit 0d8f4c63d4
3 changed files with 81 additions and 2 deletions

41
pom.xml
View File

@ -50,6 +50,14 @@
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.flywaydb/flyway-database-postgresql -->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
<version>10.4.1</version>
<!-- <scope>runtime</scope> -->
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
@ -140,7 +148,6 @@
</dependency>
<!-- https://mvnrepository.com/artifact/org.opencypher/util-9.0 -->
<dependency>
<groupId>org.opencypher.gremlin</groupId>
@ -183,6 +190,38 @@
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>10.17.2</version>
<configuration>
<sqlMigrationSeparator>__</sqlMigrationSeparator>
<locations>
<location>filesystem:src/main/resources/db/migration</location>
<location>classpath:com/stktrk/app/db/migrations</location>
</locations>
<url>jdbc:postgresql://192.168.178.50:7654/flyway_db</url>
<user>flyway_user</user>
<password>7e7v55UcYGrY0e3UPYI0qtyMA4YJ1ZkTEaoyZ252GluFkiEMHVT9U5ULS7Rg2rGi</password>
<schemas><schema>flyway_db</schema></schemas>
</configuration>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.4</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<repositories>

View File

@ -0,0 +1,36 @@
package com.stktrk.app.db.migrations;
import org.flywaydb.core.api.migration.BaseJavaMigration;
import org.flywaydb.core.api.migration.Context;
import java.sql.*;
import java.util.Properties;
public class V1__CreateTest extends BaseJavaMigration {
public void migrate(Context context) throws Exception {
Class.forName("org.postgresql.Driver");
Properties props = new Properties();
props.setProperty("user", "root");
props.setProperty("password", "playwithdata");
props.setProperty("ssl", "false");
props.setProperty("sslmode", "disable");
System.out.println ("migration");
try (Connection connection = DriverManager.getConnection("jdbc:postgresql://192.168.178.50:5432/graph", props)) {
Statement st = connection.createStatement();
st.execute("CREATE VERTEX TYPE test");
connection.close();
} catch (Exception e) {
System.out.println (e);
}
}
}

View File

@ -1,3 +1,7 @@
spring.application.name=app
server.port=9090
springdoc.swagger-ui.path=/swagger-ui.html
flyway.user=flyway_user
flyway.password=7e7v55UcYGrY0e3UPYI0qtyMA4YJ1ZkTEaoyZ252GluFkiEMHVT9U5ULS7Rg2rGi
flyway.schemas=flyway_db