Skip to content

Commit

Permalink
fixup schema init promises
Browse files Browse the repository at this point in the history
  • Loading branch information
wernst authored and pbohlman committed May 24, 2024
1 parent 46a0e17 commit 6faf486
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions packages/db/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,19 +493,28 @@ export default class DB<M extends Models<any, any> | undefined = undefined> {
});

this.storageReady = this.tripleStore.ensureStorageIsMigrated();
this.schemaInitialized = this.storageReady
// Setup schema subscription
.then(() => {
this.setupSchemaListener();
})
// Apply migrations or overwrite schema
.then(() => this.initializeDBWithMigrations(migrations))
.then(() =>
this.initializeDBWithSchema(
// @ts-expect-error
tripleStoreSchema
)
);
this.schemaInitialized = !!tripleStoreSchema
? this.storageReady
// Setup schema subscription
.then(() => {
this.setupSchemaListener();
})
.then(() =>
this.initializeDBWithSchema(
// @ts-expect-error
tripleStoreSchema
)
)
: !!migrations
? this.storageReady
// TODO: look into why test fails if we setup listener first for migrations
.then(() => this.initializeDBWithMigrations(migrations))
.then(() => {
this.setupSchemaListener();
})
: this.storageReady.then(() => {
this.setupSchemaListener();
});

this.ready = Promise.all([this.storageReady, this.schemaInitialized]).then(
() => this.logger.debug('Ready')
Expand Down

0 comments on commit 6faf486

Please sign in to comment.