|
| 1 | +create table if not exists authorisation_sessions ( |
| 2 | + session_id text primary key, |
| 3 | + poll_token_hash text not null, |
| 4 | + browser_token_hash text not null, |
| 5 | + registry_origin text not null, |
| 6 | + website_origin text not null, |
| 7 | + capability_pubkey text not null, |
| 8 | + requested_scopes text[] not null, |
| 9 | + capability_expires_at timestamptz not null, |
| 10 | + cli_version text not null, |
| 11 | + namespace text not null, |
| 12 | + name text not null, |
| 13 | + artifact_kind text not null, |
| 14 | + status text not null default 'pending', |
| 15 | + principal_type text, |
| 16 | + principal_id text, |
| 17 | + payload jsonb, |
| 18 | + challenge_token_hash text, |
| 19 | + capability_key_id text references capabilities(key_id), |
| 20 | + namespace_status text, |
| 21 | + audit_request_id text not null, |
| 22 | + created_at timestamptz not null default now(), |
| 23 | + updated_at timestamptz not null default now(), |
| 24 | + expires_at timestamptz not null, |
| 25 | + completed_at timestamptz, |
| 26 | + check (session_id ~ '^auth_[0-9a-f]{32}$'), |
| 27 | + check (poll_token_hash ~ '^sha256:[0-9a-f]{64}$'), |
| 28 | + check (browser_token_hash ~ '^sha256:[0-9a-f]{64}$'), |
| 29 | + check (cardinality(requested_scopes) > 0), |
| 30 | + check (artifact_kind in ( |
| 31 | + 'source_library', 'profile_library', 'runtime_verifier', |
| 32 | + 'deployable_contract', 'reproducible_binary', 'template' |
| 33 | + )), |
| 34 | + check (status in ('pending', 'authorised', 'review_pending')), |
| 35 | + check (namespace_status is null or namespace_status in ('active', 'review_pending')), |
| 36 | + check ( |
| 37 | + (status = 'pending' and capability_key_id is null and namespace_status is null and completed_at is null) |
| 38 | + or |
| 39 | + (status in ('authorised', 'review_pending') and capability_key_id is not null |
| 40 | + and namespace_status is not null and completed_at is not null) |
| 41 | + ) |
| 42 | +); |
| 43 | + |
| 44 | +create index if not exists authorisation_sessions_expiry_idx |
| 45 | + on authorisation_sessions(expires_at); |
0 commit comments