mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-15 20:30:17 +01:00
If migrations fail, attempt to baseline the database and apply migrations again (#1058)
This commit is contained in:
parent
48f775182b
commit
0d8f9de855
1 changed files with 11 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
package org.bitcoins.db
|
package org.bitcoins.db
|
||||||
|
|
||||||
import org.flywaydb.core.Flyway
|
import org.flywaydb.core.Flyway
|
||||||
|
import org.flywaydb.core.api.FlywayException
|
||||||
import slick.jdbc.SQLiteProfile.api._
|
import slick.jdbc.SQLiteProfile.api._
|
||||||
|
|
||||||
import scala.concurrent.{ExecutionContext, Future}
|
import scala.concurrent.{ExecutionContext, Future}
|
||||||
|
@ -97,6 +98,15 @@ abstract class DbManagement extends DatabaseLogger {
|
||||||
val dbName = appConfig.dbName.split('.').head.mkString
|
val dbName = appConfig.dbName.split('.').head.mkString
|
||||||
val config = Flyway.configure().locations(s"classpath:${dbName}/migration/")
|
val config = Flyway.configure().locations(s"classpath:${dbName}/migration/")
|
||||||
val flyway = config.dataSource(url, username, password).load
|
val flyway = config.dataSource(url, username, password).load
|
||||||
flyway.migrate()
|
|
||||||
|
try {
|
||||||
|
flyway.migrate()
|
||||||
|
} catch {
|
||||||
|
case _: FlywayException =>
|
||||||
|
//maybe we have an existing database, so attempt to baseline the existing
|
||||||
|
//database and then apply migrations again
|
||||||
|
flyway.baseline()
|
||||||
|
flyway.migrate()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue