From 3ceca9465df9f681ba3130a0c91a48bf2cfb60c0 Mon Sep 17 00:00:00 2001 From: Matheus Nogueira Date: Thu, 11 Jan 2024 15:49:54 -0300 Subject: [PATCH] add migration --- .../38_migrate_run_sequences.up.sql | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 server/migrations/38_migrate_run_sequences.up.sql diff --git a/server/migrations/38_migrate_run_sequences.up.sql b/server/migrations/38_migrate_run_sequences.up.sql new file mode 100644 index 0000000000..c9f04ebcde --- /dev/null +++ b/server/migrations/38_migrate_run_sequences.up.sql @@ -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 $$;