feat(assessment): add immutable family versions and the demo bank loader
This commit is contained in:
1 parent
94488e2b57
commit
204c6bae62
28 files changed
+6269
-9
No files matched your search
@@ -0,0 +1,733 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: assessment_bank.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const countPublishedAssessmentFamilies = `-- name: CountPublishedAssessmentFamilies :one
|
||||
SELECT count(DISTINCT family_key)::integer AS published
|
||||
FROM assessment_families
|
||||
WHERE
|
||||
category = $1
|
||||
AND lifecycle = 'published'
|
||||
`
|
||||
|
||||
// Counts the families of a category that have at least one published
|
||||
// version, however many versions each has.
|
||||
func (q *Queries) CountPublishedAssessmentFamilies(ctx context.Context, category string) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, countPublishedAssessmentFamilies, category)
|
||||
var published int32
|
||||
err := row.Scan(&published)
|
||||
return published, err
|
||||
}
|
||||
|
||||
const getAssessmentFamilyByID = `-- name: GetAssessmentFamilyByID :one
|
||||
SELECT
|
||||
id,
|
||||
family_key,
|
||||
version,
|
||||
category,
|
||||
specialization,
|
||||
title,
|
||||
bundle_name,
|
||||
author,
|
||||
reviewer,
|
||||
review_status,
|
||||
seed_generator,
|
||||
answer_key,
|
||||
rubric,
|
||||
content_sha256,
|
||||
hash_scheme,
|
||||
lifecycle,
|
||||
created_at,
|
||||
published_at,
|
||||
published_by,
|
||||
retired_at,
|
||||
retired_by
|
||||
FROM assessment_families
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetAssessmentFamilyByID(ctx context.Context, id pgtype.UUID) (AssessmentFamily, error) {
|
||||
row := q.db.QueryRow(ctx, getAssessmentFamilyByID, id)
|
||||
var i AssessmentFamily
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.FamilyKey,
|
||||
&i.Version,
|
||||
&i.Category,
|
||||
&i.Specialization,
|
||||
&i.Title,
|
||||
&i.BundleName,
|
||||
&i.Author,
|
||||
&i.Reviewer,
|
||||
&i.ReviewStatus,
|
||||
&i.SeedGenerator,
|
||||
&i.AnswerKey,
|
||||
&i.Rubric,
|
||||
&i.ContentSha256,
|
||||
&i.HashScheme,
|
||||
&i.Lifecycle,
|
||||
&i.CreatedAt,
|
||||
&i.PublishedAt,
|
||||
&i.PublishedBy,
|
||||
&i.RetiredAt,
|
||||
&i.RetiredBy,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getAssessmentFamilyVersion = `-- name: GetAssessmentFamilyVersion :one
|
||||
SELECT
|
||||
id,
|
||||
family_key,
|
||||
version,
|
||||
category,
|
||||
specialization,
|
||||
title,
|
||||
bundle_name,
|
||||
author,
|
||||
reviewer,
|
||||
review_status,
|
||||
seed_generator,
|
||||
answer_key,
|
||||
rubric,
|
||||
content_sha256,
|
||||
hash_scheme,
|
||||
lifecycle,
|
||||
created_at,
|
||||
published_at,
|
||||
published_by,
|
||||
retired_at,
|
||||
retired_by
|
||||
FROM assessment_families
|
||||
WHERE
|
||||
family_key = $1
|
||||
AND version = $2
|
||||
`
|
||||
|
||||
type GetAssessmentFamilyVersionParams struct {
|
||||
FamilyKey string
|
||||
Version int32
|
||||
}
|
||||
|
||||
func (q *Queries) GetAssessmentFamilyVersion(ctx context.Context, arg GetAssessmentFamilyVersionParams) (AssessmentFamily, error) {
|
||||
row := q.db.QueryRow(ctx, getAssessmentFamilyVersion, arg.FamilyKey, arg.Version)
|
||||
var i AssessmentFamily
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.FamilyKey,
|
||||
&i.Version,
|
||||
&i.Category,
|
||||
&i.Specialization,
|
||||
&i.Title,
|
||||
&i.BundleName,
|
||||
&i.Author,
|
||||
&i.Reviewer,
|
||||
&i.ReviewStatus,
|
||||
&i.SeedGenerator,
|
||||
&i.AnswerKey,
|
||||
&i.Rubric,
|
||||
&i.ContentSha256,
|
||||
&i.HashScheme,
|
||||
&i.Lifecycle,
|
||||
&i.CreatedAt,
|
||||
&i.PublishedAt,
|
||||
&i.PublishedBy,
|
||||
&i.RetiredAt,
|
||||
&i.RetiredBy,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getCurrentAssessmentCategoryOpening = `-- name: GetCurrentAssessmentCategoryOpening :one
|
||||
SELECT
|
||||
id,
|
||||
category,
|
||||
policy_version_id,
|
||||
opened_by,
|
||||
required_families,
|
||||
published_families,
|
||||
opened_at
|
||||
FROM assessment_category_openings
|
||||
WHERE category = $1
|
||||
ORDER BY opened_at DESC, id DESC
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetCurrentAssessmentCategoryOpening(ctx context.Context, category string) (AssessmentCategoryOpening, error) {
|
||||
row := q.db.QueryRow(ctx, getCurrentAssessmentCategoryOpening, category)
|
||||
var i AssessmentCategoryOpening
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Category,
|
||||
&i.PolicyVersionID,
|
||||
&i.OpenedBy,
|
||||
&i.RequiredFamilies,
|
||||
&i.PublishedFamilies,
|
||||
&i.OpenedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getDatabaseTime = `-- name: GetDatabaseTime :one
|
||||
SELECT clock_timestamp()::timestamptz AS now
|
||||
`
|
||||
|
||||
// The database clock, which stamps the effective time of a policy version, so
|
||||
// "the version in force now" is judged against the same clock.
|
||||
func (q *Queries) GetDatabaseTime(ctx context.Context) (pgtype.Timestamptz, error) {
|
||||
row := q.db.QueryRow(ctx, getDatabaseTime)
|
||||
var now pgtype.Timestamptz
|
||||
err := row.Scan(&now)
|
||||
return now, err
|
||||
}
|
||||
|
||||
const getLatestAssessmentFamily = `-- name: GetLatestAssessmentFamily :one
|
||||
SELECT
|
||||
id,
|
||||
family_key,
|
||||
version,
|
||||
category,
|
||||
specialization,
|
||||
title,
|
||||
bundle_name,
|
||||
author,
|
||||
reviewer,
|
||||
review_status,
|
||||
seed_generator,
|
||||
answer_key,
|
||||
rubric,
|
||||
content_sha256,
|
||||
hash_scheme,
|
||||
lifecycle,
|
||||
created_at,
|
||||
published_at,
|
||||
published_by,
|
||||
retired_at,
|
||||
retired_by
|
||||
FROM assessment_families
|
||||
WHERE family_key = $1
|
||||
ORDER BY version DESC
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetLatestAssessmentFamily(ctx context.Context, familyKey string) (AssessmentFamily, error) {
|
||||
row := q.db.QueryRow(ctx, getLatestAssessmentFamily, familyKey)
|
||||
var i AssessmentFamily
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.FamilyKey,
|
||||
&i.Version,
|
||||
&i.Category,
|
||||
&i.Specialization,
|
||||
&i.Title,
|
||||
&i.BundleName,
|
||||
&i.Author,
|
||||
&i.Reviewer,
|
||||
&i.ReviewStatus,
|
||||
&i.SeedGenerator,
|
||||
&i.AnswerKey,
|
||||
&i.Rubric,
|
||||
&i.ContentSha256,
|
||||
&i.HashScheme,
|
||||
&i.Lifecycle,
|
||||
&i.CreatedAt,
|
||||
&i.PublishedAt,
|
||||
&i.PublishedBy,
|
||||
&i.RetiredAt,
|
||||
&i.RetiredBy,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getPublishedAssessmentFamily = `-- name: GetPublishedAssessmentFamily :one
|
||||
SELECT
|
||||
id,
|
||||
family_key,
|
||||
version,
|
||||
category,
|
||||
specialization,
|
||||
title,
|
||||
bundle_name,
|
||||
author,
|
||||
reviewer,
|
||||
review_status,
|
||||
seed_generator,
|
||||
answer_key,
|
||||
rubric,
|
||||
content_sha256,
|
||||
hash_scheme,
|
||||
lifecycle,
|
||||
created_at,
|
||||
published_at,
|
||||
published_by,
|
||||
retired_at,
|
||||
retired_by
|
||||
FROM assessment_families
|
||||
WHERE
|
||||
family_key = $1
|
||||
AND lifecycle = 'published'
|
||||
`
|
||||
|
||||
// The published version of a family, if any. The partial unique index
|
||||
// assessment_families_one_published_key allows at most one.
|
||||
func (q *Queries) GetPublishedAssessmentFamily(ctx context.Context, familyKey string) (AssessmentFamily, error) {
|
||||
row := q.db.QueryRow(ctx, getPublishedAssessmentFamily, familyKey)
|
||||
var i AssessmentFamily
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.FamilyKey,
|
||||
&i.Version,
|
||||
&i.Category,
|
||||
&i.Specialization,
|
||||
&i.Title,
|
||||
&i.BundleName,
|
||||
&i.Author,
|
||||
&i.Reviewer,
|
||||
&i.ReviewStatus,
|
||||
&i.SeedGenerator,
|
||||
&i.AnswerKey,
|
||||
&i.Rubric,
|
||||
&i.ContentSha256,
|
||||
&i.HashScheme,
|
||||
&i.Lifecycle,
|
||||
&i.CreatedAt,
|
||||
&i.PublishedAt,
|
||||
&i.PublishedBy,
|
||||
&i.RetiredAt,
|
||||
&i.RetiredBy,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertAssessmentCategoryOpening = `-- name: InsertAssessmentCategoryOpening :one
|
||||
INSERT INTO assessment_category_openings (
|
||||
id,
|
||||
category,
|
||||
policy_version_id,
|
||||
opened_by,
|
||||
required_families,
|
||||
published_families,
|
||||
opened_at
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
0,
|
||||
0,
|
||||
clock_timestamp()
|
||||
)
|
||||
RETURNING
|
||||
id,
|
||||
category,
|
||||
policy_version_id,
|
||||
opened_by,
|
||||
required_families,
|
||||
published_families,
|
||||
opened_at
|
||||
`
|
||||
|
||||
type InsertAssessmentCategoryOpeningParams struct {
|
||||
ID pgtype.UUID
|
||||
Category string
|
||||
PolicyVersionID pgtype.UUID
|
||||
OpenedBy string
|
||||
}
|
||||
|
||||
// Stores an opening. The insert trigger derives required_families from the
|
||||
// policy document and counts the published families, and the coverage CHECK
|
||||
// refuses the row when they are fewer; both numbers from the caller are
|
||||
// replaced by the trigger's.
|
||||
func (q *Queries) InsertAssessmentCategoryOpening(ctx context.Context, arg InsertAssessmentCategoryOpeningParams) (AssessmentCategoryOpening, error) {
|
||||
row := q.db.QueryRow(ctx, insertAssessmentCategoryOpening,
|
||||
arg.ID,
|
||||
arg.Category,
|
||||
arg.PolicyVersionID,
|
||||
arg.OpenedBy,
|
||||
)
|
||||
var i AssessmentCategoryOpening
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Category,
|
||||
&i.PolicyVersionID,
|
||||
&i.OpenedBy,
|
||||
&i.RequiredFamilies,
|
||||
&i.PublishedFamilies,
|
||||
&i.OpenedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertAssessmentFamily = `-- name: InsertAssessmentFamily :one
|
||||
INSERT INTO assessment_families (
|
||||
id,
|
||||
family_key,
|
||||
version,
|
||||
category,
|
||||
specialization,
|
||||
title,
|
||||
bundle_name,
|
||||
author,
|
||||
reviewer,
|
||||
review_status,
|
||||
seed_generator,
|
||||
answer_key,
|
||||
rubric,
|
||||
content_sha256,
|
||||
hash_scheme,
|
||||
lifecycle
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
$6,
|
||||
$7,
|
||||
$8,
|
||||
$9,
|
||||
$10,
|
||||
$11,
|
||||
$12,
|
||||
$13,
|
||||
$14,
|
||||
$15,
|
||||
'draft'
|
||||
)
|
||||
ON CONFLICT DO NOTHING
|
||||
RETURNING
|
||||
id,
|
||||
family_key,
|
||||
version,
|
||||
category,
|
||||
specialization,
|
||||
title,
|
||||
bundle_name,
|
||||
author,
|
||||
reviewer,
|
||||
review_status,
|
||||
seed_generator,
|
||||
answer_key,
|
||||
rubric,
|
||||
content_sha256,
|
||||
hash_scheme,
|
||||
lifecycle,
|
||||
created_at,
|
||||
published_at,
|
||||
published_by,
|
||||
retired_at,
|
||||
retired_by
|
||||
`
|
||||
|
||||
type InsertAssessmentFamilyParams struct {
|
||||
ID pgtype.UUID
|
||||
FamilyKey string
|
||||
Version int32
|
||||
Category string
|
||||
Specialization string
|
||||
Title string
|
||||
BundleName string
|
||||
Author string
|
||||
Reviewer pgtype.Text
|
||||
ReviewStatus string
|
||||
SeedGenerator []byte
|
||||
AnswerKey []byte
|
||||
Rubric []byte
|
||||
ContentSha256 []byte
|
||||
HashScheme int16
|
||||
}
|
||||
|
||||
// Stores a new family version as a draft and returns the stored row with the
|
||||
// creation time set by the stamp trigger. A taken ID or (family_key, version)
|
||||
// returns no row instead of an error, so a conflict does not abort the
|
||||
// surrounding transaction.
|
||||
func (q *Queries) InsertAssessmentFamily(ctx context.Context, arg InsertAssessmentFamilyParams) (AssessmentFamily, error) {
|
||||
row := q.db.QueryRow(ctx, insertAssessmentFamily,
|
||||
arg.ID,
|
||||
arg.FamilyKey,
|
||||
arg.Version,
|
||||
arg.Category,
|
||||
arg.Specialization,
|
||||
arg.Title,
|
||||
arg.BundleName,
|
||||
arg.Author,
|
||||
arg.Reviewer,
|
||||
arg.ReviewStatus,
|
||||
arg.SeedGenerator,
|
||||
arg.AnswerKey,
|
||||
arg.Rubric,
|
||||
arg.ContentSha256,
|
||||
arg.HashScheme,
|
||||
)
|
||||
var i AssessmentFamily
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.FamilyKey,
|
||||
&i.Version,
|
||||
&i.Category,
|
||||
&i.Specialization,
|
||||
&i.Title,
|
||||
&i.BundleName,
|
||||
&i.Author,
|
||||
&i.Reviewer,
|
||||
&i.ReviewStatus,
|
||||
&i.SeedGenerator,
|
||||
&i.AnswerKey,
|
||||
&i.Rubric,
|
||||
&i.ContentSha256,
|
||||
&i.HashScheme,
|
||||
&i.Lifecycle,
|
||||
&i.CreatedAt,
|
||||
&i.PublishedAt,
|
||||
&i.PublishedBy,
|
||||
&i.RetiredAt,
|
||||
&i.RetiredBy,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listAssessmentFamiliesByCategory = `-- name: ListAssessmentFamiliesByCategory :many
|
||||
SELECT
|
||||
id,
|
||||
family_key,
|
||||
version,
|
||||
category,
|
||||
specialization,
|
||||
title,
|
||||
bundle_name,
|
||||
author,
|
||||
reviewer,
|
||||
review_status,
|
||||
seed_generator,
|
||||
answer_key,
|
||||
rubric,
|
||||
content_sha256,
|
||||
hash_scheme,
|
||||
lifecycle,
|
||||
created_at,
|
||||
published_at,
|
||||
published_by,
|
||||
retired_at,
|
||||
retired_by
|
||||
FROM assessment_families
|
||||
WHERE
|
||||
category = $1
|
||||
AND (family_key, version) > ($2::text, $3::integer)
|
||||
ORDER BY family_key ASC, version ASC
|
||||
LIMIT $4
|
||||
`
|
||||
|
||||
type ListAssessmentFamiliesByCategoryParams struct {
|
||||
Category string
|
||||
AfterKey string
|
||||
AfterVersion int32
|
||||
PageSize int32
|
||||
}
|
||||
|
||||
// One page of the versions of a category in key and version order, after the
|
||||
// given position; an empty key and version 0 start at the beginning. The
|
||||
// (family_key, version) unique index serves the scan.
|
||||
func (q *Queries) ListAssessmentFamiliesByCategory(ctx context.Context, arg ListAssessmentFamiliesByCategoryParams) ([]AssessmentFamily, error) {
|
||||
rows, err := q.db.Query(ctx, listAssessmentFamiliesByCategory,
|
||||
arg.Category,
|
||||
arg.AfterKey,
|
||||
arg.AfterVersion,
|
||||
arg.PageSize,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []AssessmentFamily
|
||||
for rows.Next() {
|
||||
var i AssessmentFamily
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.FamilyKey,
|
||||
&i.Version,
|
||||
&i.Category,
|
||||
&i.Specialization,
|
||||
&i.Title,
|
||||
&i.BundleName,
|
||||
&i.Author,
|
||||
&i.Reviewer,
|
||||
&i.ReviewStatus,
|
||||
&i.SeedGenerator,
|
||||
&i.AnswerKey,
|
||||
&i.Rubric,
|
||||
&i.ContentSha256,
|
||||
&i.HashScheme,
|
||||
&i.Lifecycle,
|
||||
&i.CreatedAt,
|
||||
&i.PublishedAt,
|
||||
&i.PublishedBy,
|
||||
&i.RetiredAt,
|
||||
&i.RetiredBy,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const lockAssessmentCategory = `-- name: LockAssessmentCategory :exec
|
||||
SELECT pg_advisory_xact_lock(
|
||||
hashtextextended('lincodex.assessment.category:' || $1::text, 0)
|
||||
)
|
||||
`
|
||||
|
||||
// Serializes the operations that change which versions of a category are
|
||||
// published or open the category, until the transaction ends. The key is
|
||||
// namespaced, so it cannot collide with another use of advisory locks.
|
||||
func (q *Queries) LockAssessmentCategory(ctx context.Context, category string) error {
|
||||
_, err := q.db.Exec(ctx, lockAssessmentCategory, category)
|
||||
return err
|
||||
}
|
||||
|
||||
const publishAssessmentFamily = `-- name: PublishAssessmentFamily :one
|
||||
UPDATE assessment_families
|
||||
SET
|
||||
lifecycle = 'published',
|
||||
published_by = $1
|
||||
WHERE
|
||||
id = $2
|
||||
AND lifecycle = 'draft'
|
||||
RETURNING
|
||||
id,
|
||||
family_key,
|
||||
version,
|
||||
category,
|
||||
specialization,
|
||||
title,
|
||||
bundle_name,
|
||||
author,
|
||||
reviewer,
|
||||
review_status,
|
||||
seed_generator,
|
||||
answer_key,
|
||||
rubric,
|
||||
content_sha256,
|
||||
hash_scheme,
|
||||
lifecycle,
|
||||
created_at,
|
||||
published_at,
|
||||
published_by,
|
||||
retired_at,
|
||||
retired_by
|
||||
`
|
||||
|
||||
type PublishAssessmentFamilyParams struct {
|
||||
Actor pgtype.Text
|
||||
ID pgtype.UUID
|
||||
}
|
||||
|
||||
// Moves a draft to published by the named operator and returns the row with
|
||||
// the publication time set by the guard trigger. No row means the version
|
||||
// was not a draft any more.
|
||||
func (q *Queries) PublishAssessmentFamily(ctx context.Context, arg PublishAssessmentFamilyParams) (AssessmentFamily, error) {
|
||||
row := q.db.QueryRow(ctx, publishAssessmentFamily, arg.Actor, arg.ID)
|
||||
var i AssessmentFamily
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.FamilyKey,
|
||||
&i.Version,
|
||||
&i.Category,
|
||||
&i.Specialization,
|
||||
&i.Title,
|
||||
&i.BundleName,
|
||||
&i.Author,
|
||||
&i.Reviewer,
|
||||
&i.ReviewStatus,
|
||||
&i.SeedGenerator,
|
||||
&i.AnswerKey,
|
||||
&i.Rubric,
|
||||
&i.ContentSha256,
|
||||
&i.HashScheme,
|
||||
&i.Lifecycle,
|
||||
&i.CreatedAt,
|
||||
&i.PublishedAt,
|
||||
&i.PublishedBy,
|
||||
&i.RetiredAt,
|
||||
&i.RetiredBy,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const retireAssessmentFamily = `-- name: RetireAssessmentFamily :one
|
||||
UPDATE assessment_families
|
||||
SET
|
||||
lifecycle = 'retired',
|
||||
retired_by = $1
|
||||
WHERE
|
||||
id = $2
|
||||
AND lifecycle = 'published'
|
||||
RETURNING
|
||||
id,
|
||||
family_key,
|
||||
version,
|
||||
category,
|
||||
specialization,
|
||||
title,
|
||||
bundle_name,
|
||||
author,
|
||||
reviewer,
|
||||
review_status,
|
||||
seed_generator,
|
||||
answer_key,
|
||||
rubric,
|
||||
content_sha256,
|
||||
hash_scheme,
|
||||
lifecycle,
|
||||
created_at,
|
||||
published_at,
|
||||
published_by,
|
||||
retired_at,
|
||||
retired_by
|
||||
`
|
||||
|
||||
type RetireAssessmentFamilyParams struct {
|
||||
Actor pgtype.Text
|
||||
ID pgtype.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) RetireAssessmentFamily(ctx context.Context, arg RetireAssessmentFamilyParams) (AssessmentFamily, error) {
|
||||
row := q.db.QueryRow(ctx, retireAssessmentFamily, arg.Actor, arg.ID)
|
||||
var i AssessmentFamily
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.FamilyKey,
|
||||
&i.Version,
|
||||
&i.Category,
|
||||
&i.Specialization,
|
||||
&i.Title,
|
||||
&i.BundleName,
|
||||
&i.Author,
|
||||
&i.Reviewer,
|
||||
&i.ReviewStatus,
|
||||
&i.SeedGenerator,
|
||||
&i.AnswerKey,
|
||||
&i.Rubric,
|
||||
&i.ContentSha256,
|
||||
&i.HashScheme,
|
||||
&i.Lifecycle,
|
||||
&i.CreatedAt,
|
||||
&i.PublishedAt,
|
||||
&i.PublishedBy,
|
||||
&i.RetiredAt,
|
||||
&i.RetiredBy,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -8,6 +8,40 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type AssessmentCategoryOpening struct {
|
||||
ID pgtype.UUID
|
||||
Category string
|
||||
PolicyVersionID pgtype.UUID
|
||||
OpenedBy string
|
||||
RequiredFamilies int32
|
||||
PublishedFamilies int32
|
||||
OpenedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type AssessmentFamily struct {
|
||||
ID pgtype.UUID
|
||||
FamilyKey string
|
||||
Version int32
|
||||
Category string
|
||||
Specialization string
|
||||
Title string
|
||||
BundleName string
|
||||
Author string
|
||||
Reviewer pgtype.Text
|
||||
ReviewStatus string
|
||||
SeedGenerator []byte
|
||||
AnswerKey []byte
|
||||
Rubric []byte
|
||||
ContentSha256 []byte
|
||||
HashScheme int16
|
||||
Lifecycle string
|
||||
CreatedAt pgtype.Timestamptz
|
||||
PublishedAt pgtype.Timestamptz
|
||||
PublishedBy pgtype.Text
|
||||
RetiredAt pgtype.Timestamptz
|
||||
RetiredBy pgtype.Text
|
||||
}
|
||||
|
||||
type ConsentRecord struct {
|
||||
ID pgtype.UUID
|
||||
SubjectID pgtype.UUID
|
||||
|
||||
@@ -48,6 +48,9 @@ type Querier interface {
|
||||
// returned registration version in the same transaction, rolled back when it
|
||||
// matches no row.
|
||||
ConsumeEmailToken(ctx context.Context, arg ConsumeEmailTokenParams) (EmailToken, error)
|
||||
// Counts the families of a category that have at least one published
|
||||
// version, however many versions each has.
|
||||
CountPublishedAssessmentFamilies(ctx context.Context, category string) (int32, error)
|
||||
DeleteMailRequest(ctx context.Context, id pgtype.UUID) (int64, error)
|
||||
DeleteOrganizationRepresentatives(ctx context.Context, organizationID pgtype.UUID) error
|
||||
// Deletes one batch of accounts that stayed unverified since before cutoff,
|
||||
@@ -91,13 +94,19 @@ type Querier interface {
|
||||
// provider's idempotency window reuses it instead of counting again.
|
||||
FindOpenMailQuotaReservation(ctx context.Context, arg FindOpenMailQuotaReservationParams) (FindOpenMailQuotaReservationRow, error)
|
||||
GetActiveSessionByTokenHash(ctx context.Context, arg GetActiveSessionByTokenHashParams) (Session, error)
|
||||
GetAssessmentFamilyByID(ctx context.Context, id pgtype.UUID) (AssessmentFamily, error)
|
||||
GetAssessmentFamilyVersion(ctx context.Context, arg GetAssessmentFamilyVersionParams) (AssessmentFamily, error)
|
||||
GetConsentText(ctx context.Context, arg GetConsentTextParams) (ConsentText, error)
|
||||
GetContactConsentRecordByInvitation(ctx context.Context, arg GetContactConsentRecordByInvitationParams) (GetContactConsentRecordByInvitationRow, error)
|
||||
GetCurrentAssessmentCategoryOpening(ctx context.Context, category string) (AssessmentCategoryOpening, error)
|
||||
// The newest unrevoked record of a purpose other than C4.
|
||||
GetCurrentConsentRecord(ctx context.Context, arg GetCurrentConsentRecordParams) (GetCurrentConsentRecordRow, error)
|
||||
// The text of a purpose that applies at a time: the latest publication not
|
||||
// after it.
|
||||
GetCurrentConsentText(ctx context.Context, arg GetCurrentConsentTextParams) (ConsentText, error)
|
||||
// The database clock, which stamps the effective time of a policy version, so
|
||||
// "the version in force now" is judged against the same clock.
|
||||
GetDatabaseTime(ctx context.Context) (pgtype.Timestamptz, error)
|
||||
GetDeliveryByID(ctx context.Context, id pgtype.UUID) (Delivery, error)
|
||||
// Aggregates the deliveries by kind and status for the metrics, at most once
|
||||
// per metrics interval. It reads only kind, status, and next_attempt_at,
|
||||
@@ -112,6 +121,7 @@ type Querier interface {
|
||||
GetEffectivePolicyVersion(ctx context.Context, arg GetEffectivePolicyVersionParams) (PolicyVersion, error)
|
||||
// Explains why ConsumeEmailToken matched no row.
|
||||
GetEmailTokenState(ctx context.Context, arg GetEmailTokenStateParams) (GetEmailTokenStateRow, error)
|
||||
GetLatestAssessmentFamily(ctx context.Context, familyKey string) (AssessmentFamily, error)
|
||||
// Reads the status of the newest delivery of a kind addressed to an account,
|
||||
// for the account's own view of its mail. It selects no address and no
|
||||
// content. The recipient index narrows the scan to the account's rows.
|
||||
@@ -133,6 +143,9 @@ type Querier interface {
|
||||
// clock that set occurred_at.
|
||||
GetOutboxBacklog(ctx context.Context) (GetOutboxBacklogRow, error)
|
||||
GetPolicyVersionByID(ctx context.Context, id pgtype.UUID) (PolicyVersion, error)
|
||||
// The published version of a family, if any. The partial unique index
|
||||
// assessment_families_one_published_key allows at most one.
|
||||
GetPublishedAssessmentFamily(ctx context.Context, familyKey string) (AssessmentFamily, error)
|
||||
// Reads the backlog for metrics without locking: jobs that a worker may
|
||||
// claim at now, how long the earliest of them has waited, and the dead
|
||||
// jobs. The
|
||||
@@ -146,6 +159,16 @@ type Querier interface {
|
||||
GetUnrevokedConsentRecordByVersion(ctx context.Context, arg GetUnrevokedConsentRecordByVersionParams) (GetUnrevokedConsentRecordByVersionRow, error)
|
||||
GetUserByEmailNormalized(ctx context.Context, emailNormalized string) (User, error)
|
||||
GetUserByID(ctx context.Context, id pgtype.UUID) (User, error)
|
||||
// Stores an opening. The insert trigger derives required_families from the
|
||||
// policy document and counts the published families, and the coverage CHECK
|
||||
// refuses the row when they are fewer; both numbers from the caller are
|
||||
// replaced by the trigger's.
|
||||
InsertAssessmentCategoryOpening(ctx context.Context, arg InsertAssessmentCategoryOpeningParams) (AssessmentCategoryOpening, error)
|
||||
// Stores a new family version as a draft and returns the stored row with the
|
||||
// creation time set by the stamp trigger. A taken ID or (family_key, version)
|
||||
// returns no row instead of an error, so a conflict does not abort the
|
||||
// surrounding transaction.
|
||||
InsertAssessmentFamily(ctx context.Context, arg InsertAssessmentFamilyParams) (AssessmentFamily, error)
|
||||
// Records a grant of C1, C2, C3, or C5. An unrevoked record of the same
|
||||
// subject, purpose, and text version already exists when no row returns;
|
||||
// the insert then changes nothing and does not abort the transaction.
|
||||
@@ -204,6 +227,10 @@ type Querier interface {
|
||||
InsertSession(ctx context.Context, arg InsertSessionParams) error
|
||||
InsertUser(ctx context.Context, arg InsertUserParams) error
|
||||
InvalidateActiveEmailTokens(ctx context.Context, arg InvalidateActiveEmailTokensParams) (int64, error)
|
||||
// One page of the versions of a category in key and version order, after the
|
||||
// given position; an empty key and version 0 start at the beginning. The
|
||||
// (family_key, version) unique index serves the scan.
|
||||
ListAssessmentFamiliesByCategory(ctx context.Context, arg ListAssessmentFamiliesByCategoryParams) ([]AssessmentFamily, error)
|
||||
// One page of the subject's ledger, newest grant first, optionally limited
|
||||
// to one state. Every record query is scoped by the subject, so a caller
|
||||
// never reads or revokes another subject's consent. The state is computed,
|
||||
@@ -222,6 +249,10 @@ type Querier interface {
|
||||
// Lists the other accounts of a provider that have usage in a month, so
|
||||
// startup can warn about a renamed EMAIL_ACCOUNT.
|
||||
ListOtherMailQuotaAccounts(ctx context.Context, arg ListOtherMailQuotaAccountsParams) ([]string, error)
|
||||
// Serializes the operations that change which versions of a category are
|
||||
// published or open the category, until the transaction ends. The key is
|
||||
// namespaced, so it cannot collide with another use of advisory locks.
|
||||
LockAssessmentCategory(ctx context.Context, category string) error
|
||||
// Locks a claimed job for its handler transaction and checks that the lease
|
||||
// still belongs to this attempt. It returns no row when the job was
|
||||
// canceled, or reclaimed after the lease expired. While the lock is held,
|
||||
@@ -264,6 +295,10 @@ type Querier interface {
|
||||
// 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)
|
||||
// Moves a draft to published by the named operator and returns the row with
|
||||
// the publication time set by the guard trigger. No row means the version
|
||||
// was not a draft any more.
|
||||
PublishAssessmentFamily(ctx context.Context, arg PublishAssessmentFamilyParams) (AssessmentFamily, error)
|
||||
// Advances a delivery past one attempt and appends the attempt in one
|
||||
// statement, so both happen or neither does, inside or outside a
|
||||
// transaction. The update applies only while the stored version still
|
||||
@@ -288,6 +323,7 @@ type Querier interface {
|
||||
// the job did not cause the failure. The same guard as the completion
|
||||
// applies, one (id, attempt) pair per job. It returns the IDs it released.
|
||||
ReleaseScheduledJobs(ctx context.Context, arg ReleaseScheduledJobsParams) ([]int64, error)
|
||||
RetireAssessmentFamily(ctx context.Context, arg RetireAssessmentFamilyParams) (AssessmentFamily, error)
|
||||
// Revokes every unrevoked record of a purpose other than C4, superseded ones
|
||||
// included, and returns them. A revocation time before the grant time, from
|
||||
// clock skew between instances, is stamped at the grant time instead.
|
||||
|
||||
Reference in new issue
Block a user