Skip to content

@lastshotlabs/slingshot-postgres

npm install @lastshotlabs/slingshot-postgres

Applies any pending schema migrations to the database in a single serialised transaction.

Acquires a PostgreSQL advisory transaction lock using pg_advisory_xact_lock so that concurrent server processes cannot race during migrations (e.g. on cluster startup). The lock is released automatically when the transaction commits or rolls back.

Tracks applied migrations in _slingshot_auth_schema_version. The runner first canonicalizes that table to a single row holding the highest observed version, then applies any missing migrations and bumps the version in the same locked transaction. If any migration throws, the entire transaction is rolled back and the error is re-thrown.

async function applyPostgresAuthSchema(pool: Pool): Promise<void>

Source: packages/slingshot-postgres/src/adapter.ts

Check that the complete auth schema expected by this package is installed.

async function checkPostgresAuthSchema(pool: Pool): Promise<

Source: packages/slingshot-postgres/src/adapter.ts

Opens a Postgres connection pool and returns a bundled { pool, db } handle.

The pool is eagerly verified with a SELECT 1 query to surface connectivity problems at startup rather than at first request (fail-fast). Both pool and db share the same underlying connection pool.

async function connectPostgres(connectionString: string, options: PostgresConnectionOptions = {},): Promise<DrizzlePostgresDb>

Source: packages/slingshot-postgres/src/connection.ts

Creates a PostgreSQL-backed AuthAdapter for slingshot-auth.

Schema migrations run automatically on first call using a per-migration transaction with a _slingshot_schema_version guard table. The adapter implements the full AuthAdapter interface: users, groups, memberships, roles, OAuth accounts, WebAuthn credentials, recovery codes, and tenant roles.

async function createPostgresAdapter(opts: PostgresAdapterOptions): Promise<AuthAdapter>

Source: packages/slingshot-postgres/src/adapter.ts

Parse and validate the migration version stored in the Postgres metadata table.

Accepts numeric values and numeric strings returned by different Postgres clients, rejects malformed or negative versions, and fails fast when the database schema is newer than the migrations bundled with the current package version.

function parseMigrationVersion(raw: unknown, maxVersion: number): number

Source: packages/slingshot-postgres/src/adapter.ts

A connected Postgres handle bundling a raw pg.Pool and a Drizzle ORM client.

  • pool — passed to plugin adapters that accept a raw pg.Pool (permissions, push, webhooks).
  • db — passed to Drizzle-based adapters such as createPostgresAdapter (auth).

Source: packages/slingshot-postgres/src/connection.ts

Options accepted by createPostgresAdapter.

Source: packages/slingshot-postgres/src/adapter.ts

Options for connectPostgres controlling pool sizing, migrations, and health checks.

Source: packages/slingshot-postgres/src/connection.ts

Tunable pool-level settings forwarded to the underlying pg.Pool constructor.

Source: packages/slingshot-postgres/src/connection.ts