Skip to content

Commit

Permalink
feat: a new script is now available to update the auto increment columns
Browse files Browse the repository at this point in the history
  • Loading branch information
sriramkanakam87 committed Aug 22, 2024
1 parent b32f65b commit 13378b3
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions database/scripts/resetSequenceColumns.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
DO $$
DECLARE
r RECORD;
BEGIN
FOR r IN
SELECT
table_name,
column_name,
substring(column_default FROM 'nextval\(''(.*)''::regclass\)') AS sequence_name
FROM
information_schema.columns
WHERE
column_default LIKE 'nextval%'
LOOP
EXECUTE 'SELECT setval(''' || r.sequence_name || ''', COALESCE((SELECT MAX(' || r.column_name || ') FROM ' || r.table_name || '), 1));';
END LOOP;
END $$;

0 comments on commit 13378b3

Please sign in to comment.