Skip to Content
Signet

Storage

Store contracts, bundled adapters, migrations and the four-table schema.

Applications own their database and schema. Signet defines four narrow contracts composed into Store:

ContractResponsibility
UserStoreCreate, read, update and delete Users.
AccountStoreManage credential and provider Accounts.
SessionStoreManage Sessions and their digests.
TokenStoreCreate, look up and atomically consume single-use Tokens.

Single-record lookup misses return ErrNotFound; the batch UsersByIDs lookup omits absent IDs instead. Implementing the four contracts is enough to plug in a custom schema; see docs/custom-schema.md in the repository.

Bundled adapters

AdapterPackageGuide
SQLitestore/sqliteSQLite
PostgreSQLstore/postgresPostgreSQL

Both adapters expose Migrate(ctx), which applies embedded, idempotent SQL. Signet never runs migrations automatically — call Migrate from your own startup or migration job. The caller owns the database handle and its lifecycle. New statements are appended as new migration files, so after upgrading Signet, calling Migrate once brings an existing database up to date; replaying every statement stays safe.

The bundled schema

Four tables are created:

TableContents
signet_usersUser identity, verified flag, disabled flag, timestamps.
signet_accountsprovider + provider user ID, password verifier, verified email; FK to Users with cascade.
signet_sessionstoken digest, idle/absolute deadlines, sign-in client user agent, revoked timestamp (revocation deletes the row, so the column stays null); FK to Users with cascade.
signet_tokenskind, digest, expiry, used timestamp. No FK to Users.

Indexes cover email lookup, Accounts by User, Sessions by User and Tokens by (User, kind). Sessions and Accounts cascade when a User is deleted; Tokens do not, because applications may own that table.

Single-use guarantee

ConsumeToken performs an atomic conditional update: it marks a Token used only if it was still unused, then returns the consumed row. Only one caller can win a race. This is what makes verification, reset, OAuth state and refresh Tokens single-use under concurrency.

Conformance suite

store/conformance.Run(t, factory) tests any Store implementation: Users, Accounts, Sessions, Tokens and token concurrency (16 racers, exactly one winner). The optional contracts have their own suites: store/conformance.RunOrganizations(t, factory) for OrganizationStore implementations (membership-scoped List, ErrNotFound on role misses, idempotent removal) and store/conformance.RunAdminUsers(t, factory) for AdminUserStore. Run them against your own store before relying on it. See Tooling for the shared checks.

On this page