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:
| Contract | Responsibility |
|---|---|
| UserStore | Create, read, update and delete Users. |
| AccountStore | Manage credential and provider Accounts. |
| SessionStore | Manage Sessions and their digests. |
| TokenStore | Create, 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
| Adapter | Package | Guide |
|---|---|---|
| SQLite | store/sqlite | SQLite |
| PostgreSQL | store/postgres | PostgreSQL |
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:
| Table | Contents |
|---|---|
signet_users | User identity, verified flag, disabled flag, timestamps. |
signet_accounts | provider + provider user ID, password verifier, verified email; FK to Users with cascade. |
signet_sessions | token 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_tokens | kind, 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.