feat(supabase): files foundation — assets table, private buckets, avatar policies through assets, purge queue, browser and worker RPCs

Migration 20261013100000: asset_status enum, public.assets (server-built keys,
lease token, closed rejection reasons), seven private buckets (avatars open with
cap and MIME list, six closed), storage.objects SELECT/INSERT policies for
avatars evaluated through assets, private.object_purge_queue fed by status and
delete triggers (48 h / 1 h grace), storage ceiling, RPCs begin_avatar_upload /
confirm_asset_upload / remove_avatar (authenticated) and claim_avatar_jobs /
complete_avatar_job / reject_avatar_job / mark_quarantine_purged / claim_purges /
ack_purge / claim_quarantine_leftovers / expire_pending_uploads (service_role),
explicit revokes and column grants. pgTAP 010 (125 checks: allowed and denied
twins, policy census, stale lease, supersede, removal, leftovers, cascade,
ceiling), 001 census extended, database.types.ts regenerated from the real
stack, schema-types test counts input arguments only.
This commit is contained in:
bchanot committed 2026-10-13 19:32:15 +02:00
1 parent 3f1105bf39
commit 614887470c
5 files changed
+1346 -6

No files matched your search

@@ -66,6 +66,25 @@ const expectedColumns = {
'updated_at',
'visibility',
],
assets: [
'attempts',
'bucket_id',
'byte_size',
'created_at',
'declared_mime',
'declared_size',
'id',
'kind',
'lock_token',
'locked_at',
'object_key',
'owner_id',
'quarantine_key',
'rejection_reason',
'sha256',
'status',
'updated_at',
],
profile_roles: [
'granted_at',
'granted_by',
@@ -109,7 +128,14 @@ type FunctionArgs = {
string)[]
}
const expectedFunctionArgs = {
ack_purge: ['purge_id'],
archive_anatomical_sheet: ['sheet_id'],
begin_avatar_upload: ['declared_mime', 'declared_size'],
claim_avatar_jobs: ['max_jobs'],
claim_purges: ['max_items'],
claim_quarantine_leftovers: ['max_items', 'older_than_seconds'],
complete_avatar_job: ['asset_id', 'byte_size', 'lock_token', 'sha256'],
confirm_asset_upload: ['asset_id'],
confirm_sheet_asset_upload: ['asset_id'],
create_anatomical_sheet: [
'description',
@@ -125,20 +151,28 @@ const expectedFunctionArgs = {
delete_sheet_asset: ['asset_id'],
delete_sheet_version: ['version_id'],
deprecate_sheet_version: ['reason', 'version_id'],
expire_pending_uploads: ['max_age_seconds'],
fork_anatomical_sheet: ['name', 'slug', 'source_version_id', 'visibility'],
grant_platform_role: ['role', 'target_user_id'],
mark_quarantine_purged: ['asset_id'],
publish_sheet_version: ['version_id'],
register_sheet_asset: ['byte_size', 'file_name', 'sha256', 'sheet_id'],
reject_avatar_job: ['asset_id', 'lock_token', 'reason'],
remove_avatar: [],
restore_anatomical_sheet: ['sheet_id'],
revoke_platform_role: ['reason', 'role', 'target_user_id'],
set_sheet_visibility: ['sheet_id', 'visibility'],
} as const satisfies FunctionArgs
// A function without arguments is generated as `Record<PropertyKey, never>`
// (every key, no value): its key set is open, so only named keys are checked.
type MissingArgs = {
[F in keyof Functions]: Exclude<
keyof Functions[F]['Args'],
(typeof expectedFunctionArgs)[F][number]
>
[F in keyof Functions]: string extends keyof Functions[F]['Args']
? never
: Exclude<
keyof Functions[F]['Args'],
(typeof expectedFunctionArgs)[F][number]
>
}[keyof Functions]
const noMissingArg: MissingArgs extends never ? true : never = true
@@ -216,9 +250,15 @@ describe('database.types.ts matches the migrated schema', () => {
expect(actual).toEqual(expected)
})
// Input arguments only: a `returns table` function also names its output columns in proargnames.
it('lists exactly the public functions and their argument names', async () => {
const { rows } = await db.query<FunctionRow>(
`select p.proname as name, coalesce(p.proargnames, '{}') as args
`select p.proname as name,
case when p.proargmodes is null then coalesce(p.proargnames, '{}')
else coalesce((select array_agg(u.n order by u.i)
from unnest(p.proargnames, p.proargmodes) with ordinality as u(n, m, i)
where u.m in ('i', 'b', 'v')), '{}')
end as args
from pg_proc p join pg_namespace n on n.oid = p.pronamespace
where n.nspname = 'public' and p.prokind = 'f'
and not exists (