Skip to content

Commit e5882ef

Browse files
committed
By awaiting the MigrateResult it should no longer run the migration async. Which prevents the Bot from booting up before it finishes.
1 parent e075957 commit e5882ef

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

7-
<groupId>de.presti.ree6</groupId>
7+
<groupId>de.ree6</groupId>
88
<artifactId>Ree6-SQL</artifactId>
99
<description>This is the SQL-Module for Ree6!</description>
1010
<version>2.1.4</version>

src/main/java/de/presti/ree6/sql/SQLConnector.java

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import com.zaxxer.hikari.HikariDataSource;
44
import io.sentry.Sentry;
5+
import lombok.Getter;
56
import lombok.Setter;
67
import lombok.extern.slf4j.Slf4j;
78
import org.flywaydb.core.Flyway;
89
import org.flywaydb.core.api.MigrationInfo;
10+
import org.flywaydb.core.api.output.MigrateResult;
911
import org.hibernate.Session;
1012
import org.hibernate.query.Query;
1113
import org.jetbrains.annotations.NotNull;
@@ -30,11 +32,13 @@ public class SQLConnector {
3032
/**
3133
* An Instance of the actual Java SQL Connection.
3234
*/
35+
@Getter
3336
private HikariDataSource dataSource;
3437

3538
/**
3639
* An Instance of the SQL-Worker which works with the Data in the Database.
3740
*/
41+
@Getter
3842
private final SQLWorker sqlWorker;
3943

4044
/**
@@ -113,7 +117,13 @@ public void runMigrations() {
113117
log.info("No pending migrations found.");
114118
}
115119

116-
flyway.migrate();
120+
MigrateResult result = flyway.migrate();
121+
122+
if (result.success) {
123+
log.info("Flyway Migrations were successful.");
124+
} else {
125+
log.error("Flyway Migrations were unsuccessful.");
126+
}
117127
} catch (Exception exception) {
118128
log.error("Migration failed!", exception);
119129
}
@@ -231,24 +241,6 @@ public void close() {
231241
}
232242
}
233243

234-
/**
235-
* Retrieve an Instance of the SQL-Connection.
236-
*
237-
* @return DataSource Instance of te SQL-Connection.
238-
*/
239-
public HikariDataSource getDataSource() {
240-
return dataSource;
241-
}
242-
243-
/**
244-
* Retrieve an Instance of the SQL-Worker to work with the Data.
245-
*
246-
* @return {@link SQLWorker} the Instance saved in this SQL-Connector.
247-
*/
248-
public SQLWorker getSqlWorker() {
249-
return sqlWorker;
250-
}
251-
252244
/**
253245
* Check if there was at least one successful Connection to the Database Server.
254246
*

src/main/java/de/presti/ree6/sql/SQLSession.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ public static void setMaxPoolSize(int maxPoolSize) {
305305
SQLSession.maxPoolSize = maxPoolSize;
306306
}
307307

308+
/**
309+
* Get or create a SessionFactory.
310+
* @return The {@link SessionFactory}.
311+
*/
308312
public static SessionFactory getSessionFactory() {
309313
if (sessionFactory == null)
310314
return sessionFactory = buildSessionFactory(isDebug());

0 commit comments

Comments
 (0)