1
0
Fork 0
polaris-task-force/reset-seq.sql
Z8MB1E d9253e6725 chore(payload): regenerate types and schema, harden sequence reset
- Regenerate payload-types and the drizzle schema for the new collections and
  fields (promotion nominations, leadership transfers, the accessory asset
  type, the Ornith model settings) and register the new migrations.
- Fix the reset-sequences SQL function to skip empty tables, and update the
  prod sync script to match.
2026-10-03 03:30:43 -04:00

20 lines
No EOL
1.1 KiB
SQL

SELECT
'SELECT SETVAL(' ||
quote_literal(quote_ident(sequence_namespace.nspname) || '.' || quote_ident(class_sequence.relname)) ||
', COALESCE(MAX(' || quote_ident(pg_attribute.attname) || '), 1), ' ||
'MAX(' || quote_ident(pg_attribute.attname) || ') IS NOT NULL) FROM ' ||
quote_ident(table_namespace.nspname) || '.' || quote_ident(class_table.relname) || ';'
FROM pg_depend
INNER JOIN pg_class AS class_sequence
ON class_sequence.oid = pg_depend.objid
AND class_sequence.relkind = 'S'
INNER JOIN pg_class AS class_table
ON class_table.oid = pg_depend.refobjid
INNER JOIN pg_attribute
ON pg_attribute.attrelid = class_table.oid
AND pg_depend.refobjsubid = pg_attribute.attnum
INNER JOIN pg_namespace as table_namespace
ON table_namespace.oid = class_table.relnamespace
INNER JOIN pg_namespace AS sequence_namespace
ON sequence_namespace.oid = class_sequence.relnamespace
ORDER BY sequence_namespace.nspname, class_sequence.relname;