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
@@ -58,6 +58,34 @@ WHERE
|
||||
AND need_id = sqlc.arg(need_id)
|
||||
AND version = sqlc.arg(version);
|
||||
|
||||
-- Read one bounded newest-first page of current needs. Both the organization
|
||||
-- scope and the tuple cursor are applied before the limit.
|
||||
-- name: ListOrganizationNeeds :many
|
||||
SELECT
|
||||
need.organization_id,
|
||||
need.id AS need_id,
|
||||
need.current_version,
|
||||
need.requirements_version,
|
||||
need.created_at,
|
||||
need.updated_at,
|
||||
version.snapshot::text AS snapshot
|
||||
FROM organization_needs AS need
|
||||
INNER JOIN organization_need_versions AS version
|
||||
ON version.organization_id = need.organization_id
|
||||
AND version.need_id = need.id
|
||||
AND version.version = need.current_version
|
||||
WHERE
|
||||
need.organization_id = sqlc.arg(organization_id)
|
||||
AND (
|
||||
sqlc.narg(after_created_at)::timestamptz IS NULL
|
||||
OR (need.created_at, need.id) < (
|
||||
sqlc.narg(after_created_at)::timestamptz,
|
||||
sqlc.narg(after_need_id)::uuid
|
||||
)
|
||||
)
|
||||
ORDER BY need.created_at DESC, need.id DESC
|
||||
LIMIT sqlc.arg(row_limit);
|
||||
|
||||
-- The conditional parent update is the compare-and-swap. Appending the
|
||||
-- snapshot is part of the same SQL statement, so a failed insert leaves the
|
||||
-- parent pointer unchanged even before the surrounding transaction rolls
|
||||
@@ -100,3 +128,19 @@ WITH advanced AS (
|
||||
)
|
||||
SELECT appended.snapshot
|
||||
FROM appended;
|
||||
|
||||
-- The generic idempotency scope serializes retries. Replacing the child row
|
||||
-- is safe only in the transaction that reserves an expired scope for a new
|
||||
-- create; live retries read and return the stored response without writing.
|
||||
-- name: SaveOrganizationNeedCreationResult :exec
|
||||
INSERT INTO organization_need_creation_results (scope_hash, snapshot)
|
||||
VALUES (sqlc.arg(scope_hash), sqlc.arg(snapshot)::jsonb)
|
||||
ON CONFLICT (scope_hash) DO UPDATE
|
||||
SET snapshot = excluded.snapshot;
|
||||
|
||||
-- Read only the immutable original response. The current need may have moved
|
||||
-- to a later version since this result was created.
|
||||
-- name: GetOrganizationNeedCreationResult :one
|
||||
SELECT snapshot::text AS snapshot
|
||||
FROM organization_need_creation_results
|
||||
WHERE scope_hash = sqlc.arg(scope_hash);
|
||||
Reference in new issue
Block a user