playerthree/postgres

playerthree/postgres — durable storage for PlayerThree on PostgreSQL (e.g. Railway's DATABASE_URL): commander rosters, OAuth connections, the published-policy pool and the session history, all game-scoped. Opening applies the pending migrations — PlayerThree's own (./migrations, scope playerthree), then the game's — each in its own transaction, under a session advisory lock so concurrent instances never migrate twice.

Each store runs its operations one at a time in issue order (the connection pool could otherwise reorder them), and close() drains every store before it ends the pool. The connection string is never logged.

Interfaces

PostgresStorage

Defined in: packages/playerthree/src/postgres/index.ts:37

Opened PostgreSQL storage: game-scoped stores to pass to the host, the MCP endpoint and the series runner.

Methods

close()
close(): Promise<void>;

Defined in: packages/playerthree/src/postgres/index.ts:47

Waits for every store's queued operations, then ends the pool. Idempotent.

Returns

Promise<void>

commanderLog()
commanderLog(game): CommanderLogStore;

Defined in: packages/playerthree/src/postgres/index.ts:42

Parameters
ParameterType
gamestring
Returns

CommanderLogStore

commanders()
commanders(game): CommanderStore;

Defined in: packages/playerthree/src/postgres/index.ts:38

Parameters
ParameterType
gamestring
Returns

CommanderStore

connections()
connections(game): ConnectionStore;

Defined in: packages/playerthree/src/postgres/index.ts:39

Parameters
ParameterType
gamestring
Returns

ConnectionStore

history()
history(game): HistoryStore;

Defined in: packages/playerthree/src/postgres/index.ts:41

Parameters
ParameterType
gamestring
Returns

HistoryStore

pool()
pool(game): PoolStore;

Defined in: packages/playerthree/src/postgres/index.ts:40

Parameters
ParameterType
gamestring
Returns

PoolStore

query()
query<R>(text, params?): Promise<R[]>;

Defined in: packages/playerthree/src/postgres/index.ts:45

Parameterized query for the game's own tables (rows).

Type Parameters
Type ParameterDefault type
R extends Record<string, unknown>Record<string, unknown>
Parameters
ParameterType
textstring
params?unknown[]
Returns

Promise<R[]>

series()
series(game): SeriesStore;

Defined in: packages/playerthree/src/postgres/index.ts:43

Parameters
ParameterType
gamestring
Returns

SeriesStore


PostgresStorageOptions

Defined in: packages/playerthree/src/postgres/index.ts:27

Options of openPostgresStorage.

Properties

PropertyTypeDescriptionDefined in
max?numberPool size (default 10).packages/playerthree/src/postgres/index.ts:31
migrations?objectThe game's own migrations: a directory of NNN_name.sql files applied in name order after PlayerThree's, tracked under scope.packages/playerthree/src/postgres/index.ts:33
migrations.dirstring-packages/playerthree/src/postgres/index.ts:33
migrations.scopestring-packages/playerthree/src/postgres/index.ts:33
urlstringpostgres:// connection string (e.g. Railway's DATABASE_URL).packages/playerthree/src/postgres/index.ts:29

Variables

PLAYERTHREE_SCOPE

const PLAYERTHREE_SCOPE: "playerthree" = 'playerthree';

Defined in: packages/playerthree/src/postgres/ledger.ts:4

Migration scope of PlayerThree's own schema; its tables are named playerthree_*.

Functions

openPostgresStorage()

function openPostgresStorage(opts): Promise<PostgresStorage>;

Defined in: packages/playerthree/src/postgres/index.ts:119

Connects, applies pending migrations (one transaction each, under a pg advisory lock), returns the storage.

Parameters

ParameterType
optsPostgresStorageOptions

Returns

Promise<PostgresStorage>