Fix race condition related to sqlite3 database not being created before we access it (#4479)

This commit is contained in:
Chris Stewart 2022-07-09 21:38:21 -05:00 committed by GitHub
parent 1ae4d40dac
commit 84ce76e16c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,6 +16,15 @@ trait DbManagement extends Logging {
import scala.language.implicitConversions
protected lazy val flyway: Flyway = {
//create the database if it doesn't exist yet in sqlite3
appConfig.driver match {
case SQLite =>
SQLiteUtil.createDbFileIfDNE(appConfig.dbPath, appConfig.dbName)
val jdbcUrl = appConfig.jdbcUrl.replace("\"", "")
SQLiteUtil.setJournalMode(jdbcUrl, "WAL")
case PostgreSQL =>
()
}
val module = appConfig.moduleName
val driverName = appConfig.driver match {
@ -157,14 +166,6 @@ trait DbManagement extends Logging {
*/
def migrate(): MigrateResult = {
try {
appConfig.driver match {
case SQLite =>
SQLiteUtil.createDbFileIfDNE(appConfig.dbPath, appConfig.dbName)
val jdbcUrl = appConfig.jdbcUrl.replace("\"", "")
SQLiteUtil.setJournalMode(jdbcUrl, "WAL")
case PostgreSQL =>
()
}
flyway.migrate()
} catch {
case err: FlywayException =>