-- Erzeugt von supabase/catalog/build_startbestand.ts. Nicht von Hand bearbeiten. -- Include für pgTAP (\ir), keine Test-Datei. Dieselbe Abfrage wie checks.sql, aber mit den IDs der -- Testspiele aus supabase/catalog/testdata/. create temp view checks_result as with sb(id) as ( select t.value::uuid from jsonb_array_elements_text('[ "5189ad0e-ab5b-5500-a3e0-a0b3671cdf14", "6577717f-4c1f-5829-af22-ae6bb37c8394", "c3c6f0fd-43bc-5fb9-b692-3be7770b6cc3" ]'::jsonb) as t(value) ), voc(kind, id, name_de) as ( select x.kind, x.id, x.name_de from jsonb_to_recordset('[ {"kind":"genre","id":"b685bcce-91da-5bdb-b5bc-5ccb45e2445c","name_de":"Testgenre A"}, {"kind":"genre","id":"4af96f83-6ee7-51e6-8ee0-f9554ca9bd4e","name_de":"Testgenre B"}, {"kind":"mechanic","id":"d27d168e-f05f-5781-8ccf-2443e4224795","name_de":"Testmechanik A"}, {"kind":"mechanic","id":"17182118-57e3-520c-8ff9-d4cce37a17ce","name_de":"Testmechanik B"} ]'::jsonb) as x(kind text, id uuid, name_de text) ) select rule, beschreibung, soll, ist, case when ok is null then 'Information' when ok then 'ok' else 'Verstoß' end as status from ( select 1 as ord, 'SB0' as rule, 'Startbestandsspiele in der Datenbank vorhanden' as beschreibung, 'alle ' || (select count(*) from sb) as soll, n as ist, null::boolean as ok from (select count(*) as n from public.games g join sb on sb.id = g.id) x union all select 2, 'SB1', 'Sichtbare Katalogspiele aus dem Startbestand (Abnahme: mindestens 180)', '>= 180', n, n >= 180 from (select count(*) as n from public.catalog_games c join sb on sb.id = c.id) x union all select 3, 'SB2', 'Spiele ohne Pflicht-Fakt (Jahr, Spielerzahl, Dauer, Alter, Verlag, Genre, Mechanik)', '0', n, n = 0 from (select count(*) as n from public.games g join sb on sb.id = g.id where g.year is null or g.min_players is null or g.max_players is null or g.min_minutes is null or g.max_minutes is null or g.min_age is null or not exists (select 1 from public.game_publishers x where x.game_id = g.id) or not exists (select 1 from public.game_genres x where x.game_id = g.id) or not exists (select 1 from public.game_mechanics x where x.game_id = g.id)) x union all select 4, 'SB4', 'Spiele ohne deutschen Kurztext', '0', n, n = 0 from (select count(*) as n from public.games g join sb on sb.id = g.id where g.description is null or g.description_locale is distinct from 'de') x union all select 5, 'SB6', 'Spiele mit Cover, Quelle oder BGG-Kennung', '0', n, n = 0 from (select count(*) as n from public.games g join sb on sb.id = g.id where g.image_path is not null or g.catalog_source_id is not null or g.bgg_id is not null) x union all select 6, 'Info', 'Begriffe mit abweichender ID (im Studio angelegt, bitte prüfen)', '-', n, null::boolean from (select (select count(*) from public.genres t join voc v on v.kind = 'genre' and v.name_de = t.name_de where t.id <> v.id) + (select count(*) from public.mechanics t join voc v on v.kind = 'mechanic' and v.name_de = t.name_de where t.id <> v.id) as n) x union all select 7, 'Info-Alt', 'Startbestandsspiele mit alternativen Titeln', '-', n, null::boolean from (select count(distinct a.game_id) as n from public.game_alt_titles a join sb on sb.id = a.game_id) x ) r order by ord;