@lastshotlabs/slingshot-postgres
npm install @lastshotlabs/slingshot-postgres
Functions
Section titled “Functions”applyPostgresAuthSchema
Section titled “applyPostgresAuthSchema”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
checkPostgresAuthSchema
Section titled “checkPostgresAuthSchema”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
connectPostgres
Section titled “connectPostgres”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
createPostgresAdapter
Section titled “createPostgresAdapter”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
parseMigrationVersion
Section titled “parseMigrationVersion”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): numberSource: packages/slingshot-postgres/src/adapter.ts
Interfaces
Section titled “Interfaces”DrizzlePostgresDb
Section titled “DrizzlePostgresDb”A connected Postgres handle bundling a raw pg.Pool and a Drizzle ORM client.
pool— passed to plugin adapters that accept a rawpg.Pool(permissions, push, webhooks).db— passed to Drizzle-based adapters such ascreatePostgresAdapter(auth).
Source: packages/slingshot-postgres/src/connection.ts
PostgresAdapterOptions
Section titled “PostgresAdapterOptions”Options accepted by createPostgresAdapter.
Source: packages/slingshot-postgres/src/adapter.ts
PostgresConnectionOptions
Section titled “PostgresConnectionOptions”Options for connectPostgres controlling pool sizing, migrations, and health checks.
Source: packages/slingshot-postgres/src/connection.ts
PostgresPoolConfig
Section titled “PostgresPoolConfig”Tunable pool-level settings forwarded to the underlying pg.Pool constructor.
Source: packages/slingshot-postgres/src/connection.ts