feat(policy): add immutable versioned product policy store
This commit is contained in:
1 parent
0e2a3b02ab
commit
7a5105acc7
30 files changed
+3893
-37
No files matched your search
@@ -18,3 +18,11 @@ func TransactionForIntegrationTest(unit outbound.UnitOfWork) (pgx.Tx, bool) {
|
||||
}
|
||||
return postgresUnit.tx, true
|
||||
}
|
||||
|
||||
// MapPolicyErrorForIntegrationTest applies the policy error mapping to an
|
||||
// error from a raw statement, so integration tests can prove that the
|
||||
// database refusal of a policy change becomes the port sentinel. It is
|
||||
// compiled only with the integration build tag.
|
||||
func MapPolicyErrorForIntegrationTest(err error) error {
|
||||
return mapPolicyError(err)
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"lincodex/backend/internal/adapter/secondary/postgres/sqlc"
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/port/outbound"
|
||||
)
|
||||
|
||||
const (
|
||||
// integrityConstraintViolationCode is the SQLSTATE that the
|
||||
// policy_versions_refuse_change trigger raises.
|
||||
integrityConstraintViolationCode = "23000"
|
||||
checkViolationCode = "23514"
|
||||
// policyVersionsImmutableConstraint is the constraint name the trigger
|
||||
// reports. It is not a table constraint; the trigger sets it so the error
|
||||
// can be matched like one.
|
||||
policyVersionsImmutableConstraint = "policy_versions_immutable"
|
||||
)
|
||||
|
||||
// policyConstraintErrors maps policy errors whose cause is a caller-visible
|
||||
// outcome to port sentinels by SQLSTATE and constraint name, never by text.
|
||||
// Unique violations do not occur: the insert uses ON CONFLICT DO NOTHING.
|
||||
var policyConstraintErrors = map[constraintViolation]error{
|
||||
{integrityConstraintViolationCode, policyVersionsImmutableConstraint}: outbound.ErrPolicyVersionImmutable,
|
||||
{checkViolationCode, "policy_versions_effective_after_creation"}: outbound.ErrPolicyVersionBackdated,
|
||||
}
|
||||
|
||||
// mapPolicyError turns a known policy constraint or trigger error into its
|
||||
// port sentinel and keeps the constraint name. Any other PostgreSQL error is
|
||||
// replaced by its SQLSTATE and constraint name, as the identity repositories
|
||||
// do, so authors and document values never reach error text. Deadlocks and
|
||||
// serialization failures also match ErrTransactionConflict. A connection
|
||||
// error loses the pgx prefix that names the database user and database;
|
||||
// other errors that do not come from PostgreSQL pass through.
|
||||
func mapPolicyError(err error) error {
|
||||
var pgError *pgconn.PgError
|
||||
if !errors.As(err, &pgError) {
|
||||
return sanitizeConnectError(err)
|
||||
}
|
||||
if sentinel, ok := policyConstraintErrors[constraintViolation{code: pgError.Code, constraint: pgError.ConstraintName}]; ok {
|
||||
return fmt.Errorf("postgres.mapPolicyError - violate constraint %s: %w", pgError.ConstraintName, sentinel)
|
||||
}
|
||||
return markTransactionConflict(&databaseError{code: pgError.Code, constraint: pgError.ConstraintName})
|
||||
}
|
||||
|
||||
// PolicyStore provides the policy repository outside a transaction. Every
|
||||
// call runs as its own statement on a pool connection. Called with a context
|
||||
// that belongs to a Transactor callback, it fails with
|
||||
// outbound.ErrNestedTransaction; use UnitOfWork.Policies there.
|
||||
type PolicyStore struct {
|
||||
queries *sqlc.Queries
|
||||
}
|
||||
|
||||
func NewPolicyStore(pool *pgxpool.Pool) *PolicyStore {
|
||||
return &PolicyStore{queries: sqlc.New(standaloneDB{pool: pool})}
|
||||
}
|
||||
|
||||
func (store *PolicyStore) Policies() outbound.PolicyRepository {
|
||||
return policyRepository{queries: store.queries}
|
||||
}
|
||||
|
||||
func (unit *UnitOfWork) Policies() outbound.PolicyRepository {
|
||||
return policyRepository{queries: unit.queries}
|
||||
}
|
||||
|
||||
type policyRepository struct {
|
||||
queries *sqlc.Queries
|
||||
}
|
||||
|
||||
var _ outbound.PolicyRepository = policyRepository{}
|
||||
|
||||
func (repository policyRepository) Create(ctx context.Context, draft domain.PolicyVersionDraft) (domain.PolicyVersion, error) {
|
||||
if draft.IsZero() || draft.Version() <= 0 {
|
||||
return domain.PolicyVersion{}, fmt.Errorf("policyRepository.Create - draft was not built and numbered by domain.NewPolicyVersionDraft: %w", domain.ErrInvalidPolicyVersion)
|
||||
}
|
||||
effectiveAt := pgtype.Timestamptz{}
|
||||
if scheduled, ok := draft.EffectiveAt(); ok {
|
||||
effectiveAt = pgTime(scheduled)
|
||||
}
|
||||
hash := draft.DocumentHash()
|
||||
row, err := repository.queries.InsertPolicyVersion(ctx, sqlc.InsertPolicyVersionParams{
|
||||
ID: pgUUID(draft.ID().UUID()),
|
||||
PolicyKey: string(draft.Key()),
|
||||
Version: draft.Version(),
|
||||
Kind: string(draft.Kind()),
|
||||
EffectiveAt: effectiveAt,
|
||||
Author: string(draft.Author()),
|
||||
Document: draft.Document(),
|
||||
DocumentSha256: hash[:],
|
||||
})
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return domain.PolicyVersion{}, fmt.Errorf("policyRepository.Create - insert %s version %d: %w", draft.Key(), draft.Version(), outbound.ErrPolicyVersionConflict)
|
||||
}
|
||||
if err != nil {
|
||||
return domain.PolicyVersion{}, fmt.Errorf("policyRepository.Create - insert policy version: %w", mapPolicyError(err))
|
||||
}
|
||||
return policyVersionFromRow(row)
|
||||
}
|
||||
|
||||
func (repository policyRepository) GetByID(ctx context.Context, id domain.PolicyVersionID) (domain.PolicyVersion, error) {
|
||||
row, err := repository.queries.GetPolicyVersionByID(ctx, pgUUID(id.UUID()))
|
||||
if err != nil {
|
||||
return domain.PolicyVersion{}, fmt.Errorf("policyRepository.GetByID - select policy version: %w", mapPolicyNoRows(err))
|
||||
}
|
||||
return policyVersionFromRow(row)
|
||||
}
|
||||
|
||||
func (repository policyRepository) GetEffective(ctx context.Context, key domain.PolicyKey, at time.Time) (domain.PolicyVersion, error) {
|
||||
if err := requireTime("policyRepository.GetEffective", at, domain.ErrInvalidPolicyVersion); err != nil {
|
||||
return domain.PolicyVersion{}, err
|
||||
}
|
||||
if err := requireKnownFamily("policyRepository.GetEffective", key); err != nil {
|
||||
return domain.PolicyVersion{}, err
|
||||
}
|
||||
row, err := repository.queries.GetEffectivePolicyVersion(ctx, sqlc.GetEffectivePolicyVersionParams{
|
||||
PolicyKey: string(key),
|
||||
At: pgTime(at),
|
||||
})
|
||||
if err != nil {
|
||||
return domain.PolicyVersion{}, fmt.Errorf("policyRepository.GetEffective - select policy version: %w", mapPolicyNoRows(err))
|
||||
}
|
||||
return policyVersionFromRow(row)
|
||||
}
|
||||
|
||||
func (repository policyRepository) GetLatest(ctx context.Context, key domain.PolicyKey) (domain.PolicyVersion, error) {
|
||||
if err := requireKnownFamily("policyRepository.GetLatest", key); err != nil {
|
||||
return domain.PolicyVersion{}, err
|
||||
}
|
||||
row, err := repository.queries.GetLatestPolicyVersion(ctx, string(key))
|
||||
if err != nil {
|
||||
return domain.PolicyVersion{}, fmt.Errorf("policyRepository.GetLatest - select policy version: %w", mapPolicyNoRows(err))
|
||||
}
|
||||
return policyVersionFromRow(row)
|
||||
}
|
||||
|
||||
func (repository policyRepository) HasVersions(ctx context.Context, key domain.PolicyKey) (bool, error) {
|
||||
if err := requireKnownFamily("policyRepository.HasVersions", key); err != nil {
|
||||
return false, err
|
||||
}
|
||||
present, err := repository.queries.PolicyVersionExists(ctx, string(key))
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("policyRepository.HasVersions - check policy versions: %w", mapPolicyError(err))
|
||||
}
|
||||
return present, nil
|
||||
}
|
||||
|
||||
func requireKnownFamily(location string, key domain.PolicyKey) error {
|
||||
if _, err := domain.ParsePolicyKey(string(key)); err != nil {
|
||||
return fmt.Errorf("%s - validate family: %w", location, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func mapPolicyNoRows(err error) error {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return outbound.ErrPolicyVersionNotFound
|
||||
}
|
||||
return mapPolicyError(err)
|
||||
}
|
||||
|
||||
func policyVersionFromRow(row sqlc.PolicyVersion) (domain.PolicyVersion, error) {
|
||||
version, err := domain.RestorePolicyVersion(domain.StoredPolicyVersion{
|
||||
ID: domain.PolicyVersionID(row.ID.Bytes),
|
||||
Key: row.PolicyKey,
|
||||
Version: row.Version,
|
||||
Kind: row.Kind,
|
||||
Author: row.Author,
|
||||
EffectiveAt: row.EffectiveAt.Time,
|
||||
CreatedAt: row.CreatedAt.Time,
|
||||
Document: row.Document,
|
||||
DocumentHash: row.DocumentSha256,
|
||||
})
|
||||
if err != nil {
|
||||
return domain.PolicyVersion{}, fmt.Errorf("postgres.policyVersionFromRow - restore policy version: %w", err)
|
||||
}
|
||||
return version, nil
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/port/outbound"
|
||||
)
|
||||
|
||||
func TestMapPolicyErrorRecognizesPolicyConstraints(t *testing.T) {
|
||||
tests := []struct {
|
||||
code string
|
||||
constraint string
|
||||
want error
|
||||
}{
|
||||
{code: integrityConstraintViolationCode, constraint: policyVersionsImmutableConstraint, want: outbound.ErrPolicyVersionImmutable},
|
||||
{code: checkViolationCode, constraint: "policy_versions_effective_after_creation", want: outbound.ErrPolicyVersionBackdated},
|
||||
}
|
||||
for _, test := range tests {
|
||||
err := mapPolicyError(&pgconn.PgError{Code: test.code, ConstraintName: test.constraint, Detail: "Key (author)=(operator:secret) already exists."})
|
||||
if !errors.Is(err, test.want) {
|
||||
t.Fatalf("mapPolicyError(%s %s) = %v, want %v", test.code, test.constraint, err, test.want)
|
||||
}
|
||||
if !strings.Contains(err.Error(), test.constraint) || strings.Contains(err.Error(), "secret") {
|
||||
t.Fatalf("mapPolicyError(%s) = %v, want the constraint name and no detail", test.constraint, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapPolicyErrorMatchesCodeAndConstraintTogether(t *testing.T) {
|
||||
// The immutability sentinel needs both the trigger's SQLSTATE and its
|
||||
// constraint name; either one alone is another error.
|
||||
for _, original := range []*pgconn.PgError{
|
||||
{Code: "P0001", ConstraintName: policyVersionsImmutableConstraint, Message: "policy versions are immutable"},
|
||||
{Code: integrityConstraintViolationCode, ConstraintName: "other_constraint", Message: "policy versions are immutable"},
|
||||
} {
|
||||
err := mapPolicyError(original)
|
||||
if errors.Is(err, outbound.ErrPolicyVersionImmutable) {
|
||||
t.Fatalf("mapPolicyError(%s %s) = %v, want no immutability sentinel", original.Code, original.ConstraintName, err)
|
||||
}
|
||||
var stateError sqlStateError
|
||||
if !errors.As(err, &stateError) || stateError.SQLState() != original.Code || strings.Contains(err.Error(), "are immutable") {
|
||||
t.Fatalf("mapPolicyError() = %v, want only SQLSTATE %s and the constraint", err, original.Code)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapPolicyErrorKeepsOtherErrors(t *testing.T) {
|
||||
for _, original := range []error{context.Canceled, outbound.ErrNestedTransaction} {
|
||||
if err := mapPolicyError(original); !errors.Is(err, original) {
|
||||
t.Fatalf("mapPolicyError(%v) = %v, want the original error", original, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPolicyRepositoryRejectsInvalidInputBeforeQuerying(t *testing.T) {
|
||||
// A repository without queries proves that no statement runs.
|
||||
repository := policyRepository{}
|
||||
if _, err := repository.Create(t.Context(), domain.PolicyVersionDraft{}); !errors.Is(err, domain.ErrInvalidPolicyVersion) {
|
||||
t.Fatalf("Create(zero draft) error = %v, want ErrInvalidPolicyVersion", err)
|
||||
}
|
||||
draft, err := domain.NewPolicyVersionDraft(domain.NewPolicyVersionDraftInput{
|
||||
Key: domain.ProductPolicyKey, Kind: domain.PolicyKindDemo, Author: domain.DemoPolicySeedAuthor, Policy: domain.DemoProductPolicyV1(),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("NewPolicyVersionDraft() error = %v", err)
|
||||
}
|
||||
if _, err := repository.Create(t.Context(), draft); !errors.Is(err, domain.ErrInvalidPolicyVersion) {
|
||||
t.Fatalf("Create(unnumbered draft) error = %v, want ErrInvalidPolicyVersion", err)
|
||||
}
|
||||
if _, err := repository.GetEffective(t.Context(), domain.ProductPolicyKey, time.Time{}); !errors.Is(err, domain.ErrInvalidPolicyVersion) {
|
||||
t.Fatalf("GetEffective(zero time) error = %v, want ErrInvalidPolicyVersion", err)
|
||||
}
|
||||
if _, err := repository.GetEffective(t.Context(), "other", time.Now()); !errors.Is(err, domain.ErrInvalidPolicyVersion) {
|
||||
t.Fatalf("GetEffective(unknown family) error = %v, want ErrInvalidPolicyVersion", err)
|
||||
}
|
||||
if _, err := repository.GetLatest(t.Context(), "other"); !errors.Is(err, domain.ErrInvalidPolicyVersion) {
|
||||
t.Fatalf("GetLatest(unknown family) error = %v, want ErrInvalidPolicyVersion", err)
|
||||
}
|
||||
if _, err := repository.HasVersions(t.Context(), "other"); !errors.Is(err, domain.ErrInvalidPolicyVersion) {
|
||||
t.Fatalf("HasVersions(unknown family) error = %v, want ErrInvalidPolicyVersion", err)
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,18 @@ type OutboxEvent struct {
|
||||
PublishedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type PolicyVersion struct {
|
||||
ID pgtype.UUID
|
||||
PolicyKey string
|
||||
Version int32
|
||||
Kind string
|
||||
EffectiveAt pgtype.Timestamptz
|
||||
Author string
|
||||
Document []byte
|
||||
DocumentSha256 []byte
|
||||
CreatedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type Session struct {
|
||||
ID pgtype.UUID
|
||||
UserID pgtype.UUID
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: policy.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const getEffectivePolicyVersion = `-- name: GetEffectivePolicyVersion :one
|
||||
SELECT
|
||||
id,
|
||||
policy_key,
|
||||
version,
|
||||
kind,
|
||||
effective_at,
|
||||
author,
|
||||
document,
|
||||
document_sha256,
|
||||
created_at
|
||||
FROM policy_versions
|
||||
WHERE
|
||||
policy_key = $1
|
||||
AND effective_at <= $2
|
||||
ORDER BY version DESC
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
type GetEffectivePolicyVersionParams struct {
|
||||
PolicyKey string
|
||||
At pgtype.Timestamptz
|
||||
}
|
||||
|
||||
// Among the versions of a family already effective at a time, the newest
|
||||
// publication wins. A version scheduled for later therefore never undoes a
|
||||
// version published after it. The unique (policy_key, version) index serves
|
||||
// the backward scan.
|
||||
func (q *Queries) GetEffectivePolicyVersion(ctx context.Context, arg GetEffectivePolicyVersionParams) (PolicyVersion, error) {
|
||||
row := q.db.QueryRow(ctx, getEffectivePolicyVersion, arg.PolicyKey, arg.At)
|
||||
var i PolicyVersion
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.PolicyKey,
|
||||
&i.Version,
|
||||
&i.Kind,
|
||||
&i.EffectiveAt,
|
||||
&i.Author,
|
||||
&i.Document,
|
||||
&i.DocumentSha256,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getLatestPolicyVersion = `-- name: GetLatestPolicyVersion :one
|
||||
SELECT
|
||||
id,
|
||||
policy_key,
|
||||
version,
|
||||
kind,
|
||||
effective_at,
|
||||
author,
|
||||
document,
|
||||
document_sha256,
|
||||
created_at
|
||||
FROM policy_versions
|
||||
WHERE policy_key = $1
|
||||
ORDER BY version DESC
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetLatestPolicyVersion(ctx context.Context, policyKey string) (PolicyVersion, error) {
|
||||
row := q.db.QueryRow(ctx, getLatestPolicyVersion, policyKey)
|
||||
var i PolicyVersion
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.PolicyKey,
|
||||
&i.Version,
|
||||
&i.Kind,
|
||||
&i.EffectiveAt,
|
||||
&i.Author,
|
||||
&i.Document,
|
||||
&i.DocumentSha256,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getPolicyVersionByID = `-- name: GetPolicyVersionByID :one
|
||||
SELECT
|
||||
id,
|
||||
policy_key,
|
||||
version,
|
||||
kind,
|
||||
effective_at,
|
||||
author,
|
||||
document,
|
||||
document_sha256,
|
||||
created_at
|
||||
FROM policy_versions
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetPolicyVersionByID(ctx context.Context, id pgtype.UUID) (PolicyVersion, error) {
|
||||
row := q.db.QueryRow(ctx, getPolicyVersionByID, id)
|
||||
var i PolicyVersion
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.PolicyKey,
|
||||
&i.Version,
|
||||
&i.Kind,
|
||||
&i.EffectiveAt,
|
||||
&i.Author,
|
||||
&i.Document,
|
||||
&i.DocumentSha256,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertPolicyVersion = `-- name: InsertPolicyVersion :one
|
||||
INSERT INTO policy_versions (
|
||||
id,
|
||||
policy_key,
|
||||
version,
|
||||
kind,
|
||||
effective_at,
|
||||
author,
|
||||
document,
|
||||
document_sha256
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
$6,
|
||||
$7,
|
||||
$8
|
||||
)
|
||||
ON CONFLICT DO NOTHING
|
||||
RETURNING
|
||||
id,
|
||||
policy_key,
|
||||
version,
|
||||
kind,
|
||||
effective_at,
|
||||
author,
|
||||
document,
|
||||
document_sha256,
|
||||
created_at
|
||||
`
|
||||
|
||||
type InsertPolicyVersionParams struct {
|
||||
ID pgtype.UUID
|
||||
PolicyKey string
|
||||
Version int32
|
||||
Kind string
|
||||
EffectiveAt pgtype.Timestamptz
|
||||
Author string
|
||||
Document []byte
|
||||
DocumentSha256 []byte
|
||||
}
|
||||
|
||||
// Stores a version and returns the stored row with the publication time and
|
||||
// effective time set by the stamp trigger. A taken ID or version number
|
||||
// returns no row instead of an error, so a conflict does not abort the
|
||||
// surrounding transaction. created_at is never taken from the caller, and a
|
||||
// NULL effective_at means "at publication".
|
||||
func (q *Queries) InsertPolicyVersion(ctx context.Context, arg InsertPolicyVersionParams) (PolicyVersion, error) {
|
||||
row := q.db.QueryRow(ctx, insertPolicyVersion,
|
||||
arg.ID,
|
||||
arg.PolicyKey,
|
||||
arg.Version,
|
||||
arg.Kind,
|
||||
arg.EffectiveAt,
|
||||
arg.Author,
|
||||
arg.Document,
|
||||
arg.DocumentSha256,
|
||||
)
|
||||
var i PolicyVersion
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.PolicyKey,
|
||||
&i.Version,
|
||||
&i.Kind,
|
||||
&i.EffectiveAt,
|
||||
&i.Author,
|
||||
&i.Document,
|
||||
&i.DocumentSha256,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const policyVersionExists = `-- name: PolicyVersionExists :one
|
||||
SELECT exists(
|
||||
SELECT 1 FROM policy_versions
|
||||
WHERE policy_key = $1
|
||||
) AS present
|
||||
`
|
||||
|
||||
// Reports whether a family has any version without reading a document, so a
|
||||
// caller that only needs presence never depends on decoding.
|
||||
func (q *Queries) PolicyVersionExists(ctx context.Context, policyKey string) (bool, error) {
|
||||
row := q.db.QueryRow(ctx, policyVersionExists, policyKey)
|
||||
var present bool
|
||||
err := row.Scan(&present)
|
||||
return present, err
|
||||
}
|
||||
@@ -33,12 +33,25 @@ type Querier interface {
|
||||
// statement was locked above.
|
||||
DeleteUnverifiedUsersRegisteredBefore(ctx context.Context, arg DeleteUnverifiedUsersRegisteredBeforeParams) (int64, error)
|
||||
GetActiveSessionByTokenHash(ctx context.Context, arg GetActiveSessionByTokenHashParams) (Session, error)
|
||||
// Among the versions of a family already effective at a time, the newest
|
||||
// publication wins. A version scheduled for later therefore never undoes a
|
||||
// version published after it. The unique (policy_key, version) index serves
|
||||
// the backward scan.
|
||||
GetEffectivePolicyVersion(ctx context.Context, arg GetEffectivePolicyVersionParams) (PolicyVersion, error)
|
||||
// Explains why ConsumeEmailToken matched no row.
|
||||
GetEmailTokenState(ctx context.Context, arg GetEmailTokenStateParams) (GetEmailTokenStateRow, error)
|
||||
GetLatestPolicyVersion(ctx context.Context, policyKey string) (PolicyVersion, error)
|
||||
GetPolicyVersionByID(ctx context.Context, id pgtype.UUID) (PolicyVersion, error)
|
||||
GetUserByEmailNormalized(ctx context.Context, emailNormalized string) (User, error)
|
||||
GetUserByID(ctx context.Context, id pgtype.UUID) (User, error)
|
||||
InsertEmailToken(ctx context.Context, arg InsertEmailTokenParams) error
|
||||
InsertOutboxEvent(ctx context.Context, arg InsertOutboxEventParams) error
|
||||
// Stores a version and returns the stored row with the publication time and
|
||||
// effective time set by the stamp trigger. A taken ID or version number
|
||||
// returns no row instead of an error, so a conflict does not abort the
|
||||
// surrounding transaction. created_at is never taken from the caller, and a
|
||||
// NULL effective_at means "at publication".
|
||||
InsertPolicyVersion(ctx context.Context, arg InsertPolicyVersionParams) (PolicyVersion, error)
|
||||
InsertSession(ctx context.Context, arg InsertSessionParams) error
|
||||
InsertUser(ctx context.Context, arg InsertUserParams) error
|
||||
InvalidateActiveEmailTokens(ctx context.Context, arg InvalidateActiveEmailTokensParams) (int64, error)
|
||||
@@ -46,6 +59,9 @@ type Querier interface {
|
||||
// was issued for.
|
||||
MarkUserEmailVerified(ctx context.Context, arg MarkUserEmailVerifiedParams) (User, error)
|
||||
Ping(ctx context.Context) (int32, error)
|
||||
// Reports whether a family has any version without reading a document, so a
|
||||
// caller that only needs presence never depends on decoding.
|
||||
PolicyVersionExists(ctx context.Context, policyKey string) (bool, error)
|
||||
RevokeSession(ctx context.Context, arg RevokeSessionParams) (int64, error)
|
||||
RevokeUserSessions(ctx context.Context, arg RevokeUserSessionsParams) (int64, error)
|
||||
// Records activity on an active session and reports whether it is active.
|
||||
|
||||
Reference in new issue
Block a user