Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions packages/verrou/src/drivers/knex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@
}

async createTableIfNotExists() {
const hasTable = await this.#connection.schema.hasTable(this.#tableName)
if (hasTable) return

await this.#connection.schema.createTable(this.#tableName, (table) => {
table.string('key', 255).notNullable().primary()
table.string('owner').notNullable()
table.bigint('expiration').unsigned().nullable()
await this.#connection.transaction(async (trx) => {
// Acquire transaction-level lock to ensure only
// one process creates the table with the same name.
await trx.raw(

Check warning on line 38 in packages/verrou/src/drivers/knex.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎········"SELECT·pg_advisory_xact_lock(hashtext(?))",⏎········[this.#tableName]⏎······` with `'SELECT·pg_advisory_xact_lock(hashtext(?))',·[this.#tableName]`
"SELECT pg_advisory_xact_lock(hashtext(?))",
[this.#tableName]
)

Check warning on line 42 in packages/verrou/src/drivers/knex.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `······`
const hasTable = await trx.schema.hasTable(this.#tableName)
if (hasTable) return

Check warning on line 45 in packages/verrou/src/drivers/knex.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `······`
await trx.schema.createTable(this.#tableName, (table) => {
table.string('key', 255).notNullable().primary()
table.string('owner').notNullable()
table.bigint('expiration').unsigned().nullable()
})
})
}

Expand Down