feat: add assessment, privacy and support flows
This commit is contained in:
1 parent
ee3738ee73
commit
e4f24fa202
339 files changed
+56454
-1126
No files matched your search
@@ -0,0 +1,201 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: assessment_signals.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const countAssessmentSignalEvents = `-- name: CountAssessmentSignalEvents :one
|
||||
SELECT count(*)::bigint AS event_count
|
||||
FROM assessment_signal_events
|
||||
WHERE attempt_id = $1
|
||||
`
|
||||
|
||||
// Count events only for the already owner-locked attempt.
|
||||
func (q *Queries) CountAssessmentSignalEvents(ctx context.Context, attemptID pgtype.UUID) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, countAssessmentSignalEvents, attemptID)
|
||||
var event_count int64
|
||||
err := row.Scan(&event_count)
|
||||
return event_count, err
|
||||
}
|
||||
|
||||
const countRecentAssessmentSignalOutcomes = `-- name: CountRecentAssessmentSignalOutcomes :one
|
||||
SELECT
|
||||
count(*)::bigint AS outcome_count,
|
||||
COALESCE(min(received_at), $1::timestamptz) AS oldest_at
|
||||
FROM assessment_signal_idempotency_outcomes
|
||||
WHERE
|
||||
attempt_id = $2
|
||||
AND received_at > $1
|
||||
`
|
||||
|
||||
type CountRecentAssessmentSignalOutcomesParams struct {
|
||||
Since pgtype.Timestamptz
|
||||
AttemptID pgtype.UUID
|
||||
}
|
||||
|
||||
type CountRecentAssessmentSignalOutcomesRow struct {
|
||||
OutcomeCount int64
|
||||
OldestAt interface{}
|
||||
}
|
||||
|
||||
// New outcomes share the generic idempotency row and are counted for the
|
||||
// attempt's rolling receipt window. Replays bypass this query in the usecase.
|
||||
func (q *Queries) CountRecentAssessmentSignalOutcomes(ctx context.Context, arg CountRecentAssessmentSignalOutcomesParams) (CountRecentAssessmentSignalOutcomesRow, error) {
|
||||
row := q.db.QueryRow(ctx, countRecentAssessmentSignalOutcomes, arg.Since, arg.AttemptID)
|
||||
var i CountRecentAssessmentSignalOutcomesRow
|
||||
err := row.Scan(&i.OutcomeCount, &i.OldestAt)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteExpiredAssessmentSignalOutcome = `-- name: DeleteExpiredAssessmentSignalOutcome :exec
|
||||
DELETE FROM assessment_signal_idempotency_outcomes
|
||||
WHERE scope_hash = $1
|
||||
`
|
||||
|
||||
// The generic reservation has already established that a previous outcome is
|
||||
// expired before this child is removed and replaced in the same transaction.
|
||||
func (q *Queries) DeleteExpiredAssessmentSignalOutcome(ctx context.Context, scopeHash []byte) error {
|
||||
_, err := q.db.Exec(ctx, deleteExpiredAssessmentSignalOutcome, scopeHash)
|
||||
return err
|
||||
}
|
||||
|
||||
const getAssessmentSignalOutcome = `-- name: GetAssessmentSignalOutcome :one
|
||||
SELECT status, accepted_events, received_at
|
||||
FROM assessment_signal_idempotency_outcomes
|
||||
WHERE scope_hash = $1
|
||||
`
|
||||
|
||||
type GetAssessmentSignalOutcomeRow struct {
|
||||
Status string
|
||||
AcceptedEvents int32
|
||||
ReceivedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
// Read only the receipt associated with the reserved idempotency scope.
|
||||
func (q *Queries) GetAssessmentSignalOutcome(ctx context.Context, scopeHash []byte) (GetAssessmentSignalOutcomeRow, error) {
|
||||
row := q.db.QueryRow(ctx, getAssessmentSignalOutcome, scopeHash)
|
||||
var i GetAssessmentSignalOutcomeRow
|
||||
err := row.Scan(&i.Status, &i.AcceptedEvents, &i.ReceivedAt)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertAssessmentSignalBatch = `-- name: InsertAssessmentSignalBatch :exec
|
||||
INSERT INTO assessment_signal_batches (id, attempt_id, received_at, event_count)
|
||||
VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4
|
||||
)
|
||||
`
|
||||
|
||||
type InsertAssessmentSignalBatchParams struct {
|
||||
ID pgtype.UUID
|
||||
AttemptID pgtype.UUID
|
||||
ReceivedAt pgtype.Timestamptz
|
||||
EventCount int32
|
||||
}
|
||||
|
||||
// The attempt row is already locked by the caller. Store a parent before its
|
||||
// bounded child events, in the same transaction as the immutable receipt.
|
||||
func (q *Queries) InsertAssessmentSignalBatch(ctx context.Context, arg InsertAssessmentSignalBatchParams) error {
|
||||
_, err := q.db.Exec(ctx, insertAssessmentSignalBatch,
|
||||
arg.ID,
|
||||
arg.AttemptID,
|
||||
arg.ReceivedAt,
|
||||
arg.EventCount,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const insertAssessmentSignalEvent = `-- name: InsertAssessmentSignalEvent :exec
|
||||
INSERT INTO assessment_signal_events (
|
||||
batch_id,
|
||||
attempt_id,
|
||||
ordinal,
|
||||
item_instance_id,
|
||||
kind,
|
||||
occurred_at,
|
||||
duration_ms,
|
||||
size_bytes
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
$6,
|
||||
$7::integer,
|
||||
$8::integer
|
||||
)
|
||||
`
|
||||
|
||||
type InsertAssessmentSignalEventParams struct {
|
||||
BatchID pgtype.UUID
|
||||
AttemptID pgtype.UUID
|
||||
Ordinal int32
|
||||
ItemInstanceID pgtype.UUID
|
||||
Kind string
|
||||
OccurredAt pgtype.Timestamptz
|
||||
DurationMs pgtype.Int4
|
||||
SizeBytes pgtype.Int4
|
||||
}
|
||||
|
||||
// Each inserted event is checked by the database guard against attempt state
|
||||
// and the aggregate capacity as a second line of defense.
|
||||
func (q *Queries) InsertAssessmentSignalEvent(ctx context.Context, arg InsertAssessmentSignalEventParams) error {
|
||||
_, err := q.db.Exec(ctx, insertAssessmentSignalEvent,
|
||||
arg.BatchID,
|
||||
arg.AttemptID,
|
||||
arg.Ordinal,
|
||||
arg.ItemInstanceID,
|
||||
arg.Kind,
|
||||
arg.OccurredAt,
|
||||
arg.DurationMs,
|
||||
arg.SizeBytes,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const insertAssessmentSignalOutcome = `-- name: InsertAssessmentSignalOutcome :exec
|
||||
INSERT INTO assessment_signal_idempotency_outcomes (
|
||||
scope_hash,
|
||||
attempt_id,
|
||||
status,
|
||||
accepted_events,
|
||||
received_at
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5
|
||||
)
|
||||
`
|
||||
|
||||
type InsertAssessmentSignalOutcomeParams struct {
|
||||
ScopeHash []byte
|
||||
AttemptID pgtype.UUID
|
||||
Status string
|
||||
AcceptedEvents int32
|
||||
ReceivedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
// Save exactly one immutable response receipt for each live idempotency scope.
|
||||
func (q *Queries) InsertAssessmentSignalOutcome(ctx context.Context, arg InsertAssessmentSignalOutcomeParams) error {
|
||||
_, err := q.db.Exec(ctx, insertAssessmentSignalOutcome,
|
||||
arg.ScopeHash,
|
||||
arg.AttemptID,
|
||||
arg.Status,
|
||||
arg.AcceptedEvents,
|
||||
arg.ReceivedAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
Reference in new issue
Block a user