feat(supabase): regenerated types, row aliases, publishSheetVersion gate, schema test

This commit is contained in:
bchanot committed 2026-10-08 23:42:44 +02:00
1 parent f4ceaf68f9
commit 8cac8b1a68
6 files changed
+510 -8

No files matched your search

@@ -20,6 +20,50 @@ type ColumnMap = {
}
const expectedColumns = {
anatomical_sheet_assets: [
'byte_size',
'content_type',
'created_at',
'created_by',
'file_name',
'id',
'sha256',
'sheet_id',
],
anatomical_sheet_versions: [
'change_note',
'content',
'created_at',
'created_by',
'deprecated_at',
'deprecated_by',
'document_schema_version',
'id',
'published_at',
'published_by',
'sheet_id',
'status',
'updated_at',
'version_number',
],
anatomical_sheets: [
'archived_at',
'based_on_sheet_id',
'based_on_version_id',
'created_at',
'creator_user_id',
'current_version_id',
'deleted_at',
'description',
'id',
'is_official',
'name',
'slug',
'species_id',
'status',
'updated_at',
'visibility',
],
profile_roles: [
'granted_at',
'granted_by',
@@ -43,6 +87,7 @@ const expectedColumns = {
'timezone',
'updated_at',
],
species: ['active', 'created_at', 'id', 'name_en', 'name_fr', 'sort_order'],
} as const satisfies ColumnMap
// Compile-time: a column present in the type but absent from the list is an error.
@@ -59,7 +104,26 @@ type FunctionArgs = {
string)[]
}
const expectedFunctionArgs = {
archive_anatomical_sheet: ['sheet_id'],
create_anatomical_sheet: [
'description',
'document',
'name',
'official',
'slug',
'species_id',
'visibility',
],
create_sheet_draft: ['change_note', 'from_version_id', 'sheet_id'],
delete_anatomical_sheet: ['sheet_id'],
delete_sheet_asset: ['asset_id'],
delete_sheet_version: ['version_id'],
deprecate_sheet_version: ['reason', 'version_id'],
fork_anatomical_sheet: ['name', 'slug', 'source_version_id', 'visibility'],
grant_platform_role: ['role', 'target_user_id'],
publish_sheet_version: ['version_id'],
register_sheet_asset: ['byte_size', 'file_name', 'sha256', 'sheet_id'],
restore_anatomical_sheet: ['sheet_id'],
revoke_platform_role: ['reason', 'role', 'target_user_id'],
} as const satisfies FunctionArgs
@@ -78,6 +142,10 @@ interface ColumnRow {
interface NameRow {
name: string
}
interface EnumRow {
name: string
labels: string[]
}
interface FunctionRow {
name: string
args: string[]
@@ -122,17 +190,23 @@ describe('database.types.ts matches the migrated schema', () => {
expect(actual).toEqual(expected)
})
it('lists the enum labels in order', async () => {
const { rows } = await db.query<NameRow>(
`select e.enumlabel as name
it('lists every public enum with its labels in order', async () => {
const { rows } = await db.query<EnumRow>(
`select t.typname as name,
array_agg(e.enumlabel order by e.enumsortorder) as labels
from pg_enum e join pg_type t on t.oid = e.enumtypid
join pg_namespace n on n.oid = t.typnamespace
where n.nspname = 'public' and t.typname = 'platform_role'
order by e.enumsortorder`,
where n.nspname = 'public'
group by t.typname order by t.typname`,
)
expect(rows.map((r) => r.name)).toEqual([
...Constants.public.Enums.platform_role,
])
const actual = Object.fromEntries(rows.map((r) => [r.name, r.labels]))
const expected = Object.fromEntries(
Object.entries(Constants.public.Enums).map(([name, labels]) => [
name,
[...labels],
]),
)
expect(actual).toEqual(expected)
})
it('lists exactly the public functions and their argument names', async () => {