feat(accounts): add consent settings and organization management

This commit is contained in:
TakuyaYagam1 committed 2026-10-07 13:00:39 +03:00
1 parent 24638d46d2
commit 391af7a1ef
83 files changed
+10198 -613

No files matched your search

@@ -0,0 +1,37 @@
-- A C1 revocation creates a durable request for the account-deletion workflow.
-- The API records the request and its outbox intent atomically; processing and
-- deleting the account are separate operations.
-- +goose Up
CREATE TABLE account_deletion_requests (
id uuid NOT NULL,
subject_id uuid,
status text NOT NULL,
requested_at timestamptz NOT NULL,
completed_at timestamptz,
CONSTRAINT account_deletion_requests_pkey PRIMARY KEY (id),
CONSTRAINT account_deletion_requests_subject_id_fkey FOREIGN KEY (subject_id)
REFERENCES users (id) ON DELETE SET NULL,
CONSTRAINT account_deletion_requests_status_known CHECK (
status IN ('requested', 'processing', 'completed')
),
CONSTRAINT account_deletion_requests_state_shape CHECK (
(status = 'completed') = (completed_at IS NOT NULL)
),
CONSTRAINT account_deletion_requests_subject_retained_until_complete CHECK (
subject_id IS NOT NULL OR status = 'completed'
),
CONSTRAINT account_deletion_requests_completed_after_request CHECK (
completed_at IS NULL OR completed_at >= requested_at
)
);
CREATE UNIQUE INDEX account_deletion_requests_one_active_per_subject
ON account_deletion_requests (subject_id)
WHERE subject_id IS NOT NULL AND status IN ('requested', 'processing');
CREATE INDEX account_deletion_requests_processing_idx
ON account_deletion_requests (requested_at, id)
WHERE status IN ('requested', 'processing');
-- +goose Down
DROP TABLE account_deletion_requests;
@@ -0,0 +1,25 @@
-- +goose Up
-- Replay follows the generic record's 24-hour retention. Expired records are
-- removed by bounded opportunistic purges, so physical deletion may happen
-- later; this foreign key removes the snapshot with its record. The snapshot
-- is separate from the live organization so later profile edits cannot change
-- a replay. It contains bounded profile and owner-membership data, never a
-- request key.
CREATE TABLE organization_creation_results (
scope_hash bytea NOT NULL,
snapshot jsonb NOT NULL,
CONSTRAINT organization_creation_results_pkey PRIMARY KEY (scope_hash),
CONSTRAINT organization_creation_results_idempotency_fkey FOREIGN KEY (
scope_hash
) REFERENCES idempotency_records (scope_hash) ON DELETE CASCADE,
CONSTRAINT organization_creation_results_scope_hash_sha256 CHECK (
octet_length(scope_hash) = 32
),
CONSTRAINT organization_creation_results_snapshot_bounded CHECK (
jsonb_typeof(snapshot) = 'object'
AND octet_length(snapshot::text) <= 65536
)
);
-- +goose Down
DROP TABLE organization_creation_results;