setup flyway with separate postgres for history info

This commit is contained in:
Rasmus Neikes 2024-08-31 21:12:25 +02:00
parent 0d8f4c63d4
commit 51485e68a2
6 changed files with 52 additions and 9 deletions

View File

@ -197,14 +197,15 @@
<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>
<schemas>
<schema>flyway_db</schema>
</schemas>
</configuration>

View File

@ -3,7 +3,9 @@ package com.stktrk.app;
import com.arcadedb.gremlin.ArcadeGraph;
import com.github.javafaker.Faker;
import com.stktrk.app.configuration.GraphDbConfig;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

View File

@ -2,20 +2,30 @@ package com.stktrk.app;
import com.arcadedb.gremlin.ArcadeGraph;
import com.arcadedb.gremlin.ArcadeGraphFactory;
import com.stktrk.app.configuration.GraphDbConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Component
public class ConnectionPool {
static final ArcadeGraphFactory pool;
static ArcadeGraphFactory pool;
static {
@Autowired
GraphDbConfig graphDbConfig;
@PostConstruct
void init () {
try {
pool = ArcadeGraphFactory.withRemote("192.168.178.50", 2480, "graph", "root", "playwithdata");
pool = ArcadeGraphFactory.withRemote(graphDbConfig.getHost(), graphDbConfig.getHttpPort(), graphDbConfig.getGraphName(), graphDbConfig.getUser(), graphDbConfig.getPassword());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static ArcadeGraph getGraph(){
public static ArcadeGraph getGraph() {
return pool.get();
}
}

View File

@ -0,0 +1,22 @@
package com.stktrk.app.configuration;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@Getter
@Setter
@ConfigurationProperties(prefix = "graph")
public class GraphDbConfig {
String host;
int httpPort;
int postgresPort;
String graphName;
String user;
String password;
}

View File

@ -6,7 +6,7 @@ import org.flywaydb.core.api.migration.Context;
import java.sql.*;
import java.util.Properties;
public class V1__CreateTest extends BaseJavaMigration {
public class V2__CreateTest extends BaseJavaMigration {
public void migrate(Context context) throws Exception {
Class.forName("org.postgresql.Driver");
@ -25,7 +25,6 @@ public class V1__CreateTest extends BaseJavaMigration {
Statement st = connection.createStatement();
st.execute("CREATE VERTEX TYPE test");
connection.close();
} catch (Exception e) {

View File

@ -5,3 +5,12 @@ springdoc.swagger-ui.path=/swagger-ui.html
flyway.user=flyway_user
flyway.password=7e7v55UcYGrY0e3UPYI0qtyMA4YJ1ZkTEaoyZ252GluFkiEMHVT9U5ULS7Rg2rGi
flyway.schemas=flyway_db
graph.user=root
graph.password=playwithdata
graph.connection=jdbc:postgresql://192.168.178.50:5432/graph
graph.http-port:2480
graph.postgres-port:5432
graph.host=192.168.178.50
graph.graph-name=graph