Shuffle/supabase/tests/database/00_schema.test.sql
cschlaefke 147dd1870e feat(db): game reports table, admin_resolve_report and visibility trigger (KAT-05 2c) Refs #2
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-03 21:05:02 +01:00

40 lines
1.8 KiB
PL/PgSQL

-- Struktur-Regeln für alle Tabellen im Schema public.
begin;
select plan(5);
select is((select count(*) from pg_tables where schemaname = 'public'), 21::bigint,
'R1 hat genau 21 Tabellen (17 + catalog_sources, publishers, game_publishers, game_reports)');
select is_empty($$
select c.relname from pg_class c join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public' and c.relkind = 'r' and not c.relrowsecurity$$,
'Jede Tabelle hat Row Level Security');
select is_empty($$
select t.table_name from information_schema.tables t
where t.table_schema = 'public' and t.table_type = 'BASE TABLE'
and (select count(*) from information_schema.columns c
where c.table_schema = 'public' and c.table_name = t.table_name
and ((c.column_name = 'id' and c.data_type = 'uuid')
or (c.column_name in ('created_at', 'updated_at')
and c.data_type = 'timestamp with time zone'
and c.is_nullable = 'NO'))) <> 3$$,
'Jede Tabelle hat id (uuid), created_at und updated_at');
select is_empty($$
select t.table_name from information_schema.tables t
where t.table_schema = 'public' and t.table_type = 'BASE TABLE'
and not exists (select 1 from information_schema.table_constraints k
where k.table_schema = 'public' and k.table_name = t.table_name
and k.constraint_type = 'PRIMARY KEY')$$,
'Jede Tabelle hat einen Primärschlüssel');
select is_empty($$
select c.relname from pg_class c join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public' and c.relkind = 'r'
and not exists (select 1 from pg_trigger g
where g.tgrelid = c.oid and g.tgname = 'set_updated_at')$$,
'Jede Tabelle setzt updated_at per Trigger');
select * from finish();
rollback;