Files
archie/internal/infrastructure/postgres/postgresdb/identities.sql.go
T
sam 0cece95b4a feat(postgres): port events/identities/status surfaces, fix shipped defects
CHECKPOINT -- the full State Store port is in progress; this lands the
compile-clean core so the review pass has a diff to work against. Remaining:
advisory-lock ownership, event-insert serialization, maintenance, and the
ported test battery.

Two corrections to behaviour that already shipped, not new features:
- UpdateTask wrote park_reason raw where SQLite applies clip(park_reason,
  4000); the PostgreSQL adapter now clips before binding (clip.go).
- tasks.review_cursor existed on the protobuf wire and in workflow.Task but
  not in the PostgreSQL schema; 0004 adds it as a NEW migration rather than
  amending 0001 because a dev database may already have applied 0001 and
  goose tracks version numbers, not checksums.

Also moves the control-plane Resource/ResourceWrite types and their sentinels
into storecontract so the postgres package can stop importing internal/store
(they stay aliased there for daemon callers).
2026-09-24 02:17:44 +10:00

271 lines
6.6 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: identities.sql
package postgresdb
import (
"context"
"time"
)
const getIdentity = `-- name: GetIdentity :one
SELECT id, kind, display_name, lifecycle, version, created_at, updated_at
FROM identities WHERE id = $1
`
func (q *Queries) GetIdentity(ctx context.Context, id string) (Identity, error) {
row := q.db.QueryRow(ctx, getIdentity, id)
var i Identity
err := row.Scan(
&i.ID,
&i.Kind,
&i.DisplayName,
&i.Lifecycle,
&i.Version,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const insertIdentity = `-- name: InsertIdentity :exec
INSERT INTO identities (id, kind, display_name, lifecycle, version, created_at, updated_at)
VALUES ($1, $2, $3, $4, $5, $6, $7)
`
type InsertIdentityParams struct {
ID string
Kind string
DisplayName string
Lifecycle string
Version int64
CreatedAt time.Time
UpdatedAt time.Time
}
func (q *Queries) InsertIdentity(ctx context.Context, arg InsertIdentityParams) error {
_, err := q.db.Exec(ctx, insertIdentity,
arg.ID,
arg.Kind,
arg.DisplayName,
arg.Lifecycle,
arg.Version,
arg.CreatedAt,
arg.UpdatedAt,
)
return err
}
const insertIdentityAlias = `-- name: InsertIdentityAlias :exec
INSERT INTO identity_aliases (alias, identity_id) VALUES ($1, $2)
`
type InsertIdentityAliasParams struct {
Alias string
IdentityID string
}
func (q *Queries) InsertIdentityAlias(ctx context.Context, arg InsertIdentityAliasParams) error {
_, err := q.db.Exec(ctx, insertIdentityAlias, arg.Alias, arg.IdentityID)
return err
}
const insertIdentityAliasIgnoreConflict = `-- name: InsertIdentityAliasIgnoreConflict :exec
INSERT INTO identity_aliases (alias, identity_id) VALUES ($1, $2) ON CONFLICT DO NOTHING
`
type InsertIdentityAliasIgnoreConflictParams struct {
Alias string
IdentityID string
}
func (q *Queries) InsertIdentityAliasIgnoreConflict(ctx context.Context, arg InsertIdentityAliasIgnoreConflictParams) error {
_, err := q.db.Exec(ctx, insertIdentityAliasIgnoreConflict, arg.Alias, arg.IdentityID)
return err
}
const insertIdentityEvent = `-- name: InsertIdentityEvent :exec
INSERT INTO identity_events (identity_id, event_type, from_lifecycle, to_lifecycle, display_name, actor_id, source, request_id, at)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
`
type InsertIdentityEventParams struct {
IdentityID string
EventType string
FromLifecycle string
ToLifecycle string
DisplayName string
ActorID string
Source string
RequestID string
At time.Time
}
func (q *Queries) InsertIdentityEvent(ctx context.Context, arg InsertIdentityEventParams) error {
_, err := q.db.Exec(ctx, insertIdentityEvent,
arg.IdentityID,
arg.EventType,
arg.FromLifecycle,
arg.ToLifecycle,
arg.DisplayName,
arg.ActorID,
arg.Source,
arg.RequestID,
arg.At,
)
return err
}
const listIdentities = `-- name: ListIdentities :many
SELECT id, kind, display_name, lifecycle, version, created_at, updated_at
FROM identities ORDER BY created_at, id
`
// Identity persistence. The domain owns lifecycle semantics (internal/domain/
// identity); these queries are the durable half of that contract. Aliases are
// unique on lower(alias) rather than the case-sensitive PRIMARY KEY, matching
// the SQLite schema's COLLATE NOCASE.
func (q *Queries) ListIdentities(ctx context.Context) ([]Identity, error) {
rows, err := q.db.Query(ctx, listIdentities)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Identity
for rows.Next() {
var i Identity
if err := rows.Scan(
&i.ID,
&i.Kind,
&i.DisplayName,
&i.Lifecycle,
&i.Version,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const resolveIdentityAlias = `-- name: ResolveIdentityAlias :one
SELECT i.id, i.kind, i.display_name, i.lifecycle, i.version, i.created_at, i.updated_at
FROM identities i JOIN identity_aliases a ON a.identity_id = i.id
WHERE lower(a.alias) = lower($1)
`
func (q *Queries) ResolveIdentityAlias(ctx context.Context, lower string) (Identity, error) {
row := q.db.QueryRow(ctx, resolveIdentityAlias, lower)
var i Identity
err := row.Scan(
&i.ID,
&i.Kind,
&i.DisplayName,
&i.Lifecycle,
&i.Version,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const resolveIdentitySubject = `-- name: ResolveIdentitySubject :one
SELECT i.id, i.kind, i.display_name, i.lifecycle, i.version, i.created_at, i.updated_at
FROM identities i JOIN identity_subjects b ON b.identity_id = i.id
WHERE b.issuer = $1 AND b.subject = $2
`
type ResolveIdentitySubjectParams struct {
Issuer string
Subject string
}
func (q *Queries) ResolveIdentitySubject(ctx context.Context, arg ResolveIdentitySubjectParams) (Identity, error) {
row := q.db.QueryRow(ctx, resolveIdentitySubject, arg.Issuer, arg.Subject)
var i Identity
err := row.Scan(
&i.ID,
&i.Kind,
&i.DisplayName,
&i.Lifecycle,
&i.Version,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const updateIdentity = `-- name: UpdateIdentity :execrows
UPDATE identities SET display_name = $2, lifecycle = $3, version = $4, updated_at = $5
WHERE id = $1 AND version = $6
`
type UpdateIdentityParams struct {
ID string
DisplayName string
Lifecycle string
Version int64
UpdatedAt time.Time
Version_2 int64
}
func (q *Queries) UpdateIdentity(ctx context.Context, arg UpdateIdentityParams) (int64, error) {
result, err := q.db.Exec(ctx, updateIdentity,
arg.ID,
arg.DisplayName,
arg.Lifecycle,
arg.Version,
arg.UpdatedAt,
arg.Version_2,
)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const updateTaskIdentity = `-- name: UpdateTaskIdentity :exec
UPDATE tasks SET identity = $1 WHERE identity = $2
`
type UpdateTaskIdentityParams struct {
Identity string
Identity_2 string
}
func (q *Queries) UpdateTaskIdentity(ctx context.Context, arg UpdateTaskIdentityParams) error {
_, err := q.db.Exec(ctx, updateTaskIdentity, arg.Identity, arg.Identity_2)
return err
}
const upsertIdentitySubject = `-- name: UpsertIdentitySubject :exec
INSERT INTO identity_subjects (issuer, subject, identity_id, bound_at)
VALUES ($1, $2, $3, $4)
ON CONFLICT (issuer, subject) DO UPDATE SET identity_id = excluded.identity_id, bound_at = excluded.bound_at
`
type UpsertIdentitySubjectParams struct {
Issuer string
Subject string
IdentityID string
BoundAt time.Time
}
func (q *Queries) UpsertIdentitySubject(ctx context.Context, arg UpsertIdentitySubjectParams) error {
_, err := q.db.Exec(ctx, upsertIdentitySubject,
arg.Issuer,
arg.Subject,
arg.IdentityID,
arg.BoundAt,
)
return err
}