-- Seed resources table with base tables defined in the schema
INSERT INTO resources (resource_type_id, tenant_id, branch_id, name, description)
SELECT (SELECT id FROM resource_types WHERE name='table'), NULL, NULL, tablename, NULL
FROM pg_catalog.pg_tables t
WHERE t.schemaname = 'public'
  AND NOT EXISTS (
      SELECT 1 FROM resources r
      WHERE r.name = t.tablename
        AND r.resource_type_id = (SELECT id FROM resource_types WHERE name='table')
  );
