Skip to content

Commit

Permalink
add migration
Browse files Browse the repository at this point in the history
  • Loading branch information
mathnogueira committed Jan 11, 2024
1 parent b63ac6d commit 3ceca94
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions server/migrations/38_migrate_run_sequences.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
DO $$
DECLARE
temprow record;
BEGIN
FOR temprow IN
SELECT max(id)+1 AS next_value, test_id, tenant_id
FROM test_runs
GROUP BY test_id, tenant_id
LOOP
EXECUTE format('CREATE SEQUENCE IF NOT EXISTS runs_test_%s_seq START WITH %s',
MD5(FORMAT('%s%s', temprow.test_id, temprow.tenant_id)), temprow.next_value);
END LOOP;

FOR temprow IN
SELECT max(id::int)+1 AS next_value, test_suite_id, tenant_id
FROM test_suite_runs
GROUP BY test_suite_id, tenant_id
LOOP
EXECUTE format('CREATE SEQUENCE IF NOT EXISTS runs_test_suite_%s_seq START WITH %s',
MD5(FORMAT('%s%s', temprow.test_suite_id, temprow.tenant_id)), temprow.next_value);
END LOOP;
END $$;

0 comments on commit 3ceca94

Please sign in to comment.