Fix: Make prepare function idempotent.

This commit is contained in:
Kevin Gorham 2021-05-07 17:31:32 -04:00
parent 07c9335ea4
commit 10561d6329
No known key found for this signature in database
GPG Key ID: CCA55602DF49FC38
1 changed files with 9 additions and 5 deletions

View File

@ -93,11 +93,15 @@ class PagedTransactionRepository(
override suspend fun getAccountCount(): Int = lazy.accounts.count()
override fun prepare() {
twig("Preparing repository for use...")
initMissingDatabases()
// provide the database to all the lazy properties that are waiting for it to exist
lazy.db = buildDatabase()
applyKeyMigrations()
if (lazy.isPrepared.get()) {
twig("Warning: skipped the preparation step because we're already prepared!")
} else {
twig("Preparing repository for use...")
initMissingDatabases()
// provide the database to all the lazy properties that are waiting for it to exist
lazy.db = buildDatabase()
applyKeyMigrations()
}
}
/**