Shuffle/supabase/tests/database/00_schema.test.sql
cschlaefke 317634dac5
Some checks are pending
CI / flutter (push) Waiting to run
CI / supabase (push) Waiting to run
CI / supabase-tests (push) Waiting to run
chore: initial project kit
2026-11-02 12:14:09 +01:00

40 lines
1.7 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'), 17::bigint,
'R1 hat genau 17 Tabellen');
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;