Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samwillis committed Dec 8, 2024
1 parent e6ca903 commit 2ec9edc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
24 changes: 12 additions & 12 deletions packages/pglite-sync/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,20 @@ async function createPlugin(
// resolved by using reference counting in shadow tables
const shapePerTableLock = new Map<string, void>()

let initMetadataTablesDone = false
const initMetadataTables = async () => {
if (initMetadataTablesDone) return
initMetadataTablesDone = true
await migrateShapeMetadataTables({
pg,
metadataSchema,
})
}

const namespaceObj = {
initMetadataTables,
syncShapeToTable: async (options: SyncShapeToTableOptions) => {
await firstRun()
await initMetadataTables()
options = {
commitGranularity: 'up-to-date',
...options,
Expand Down Expand Up @@ -322,17 +333,6 @@ async function createPlugin(
}
}

let firstRunDone = false

const firstRun = async () => {
if (firstRunDone) return
firstRunDone = true
await migrateShapeMetadataTables({
pg,
metadataSchema,
})
}

return {
namespaceObj,
close,
Expand Down
3 changes: 2 additions & 1 deletion packages/pglite-sync/test/sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ describe('pglite-sync', () => {
}),
},
})
await db.electric.initMetadataTables()

const result = await db.query(
`SELECT schema_name FROM information_schema.schemata WHERE schema_name = $1`,
Expand Down Expand Up @@ -503,7 +504,7 @@ describe('pglite-sync', () => {
// Check the flag is not set outside of a sync
const result0 =
await pg.sql`SELECT current_setting('electric.syncing', true)`
expect(result0.rows[0]).toEqual({ current_setting: 'false' })
expect(result0.rows[0]).toEqual({ current_setting: null }) // not set yet as syncShapeToTable hasn't been called

const shape = await pg.electric.syncShapeToTable({
shape: { url: 'http://localhost:3000/v1/shape', table: 'test_syncing' },
Expand Down

0 comments on commit 2ec9edc

Please sign in to comment.