chore: [CODE-3779]: add index for migrations table (#3742)

This commit is contained in:
Johannes Batzill 2025-04-28 21:01:06 +00:00 committed by Harness
parent f296f1c37d
commit 0d51e10332
2 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,2 @@
-- primary key is required by some database tools and dependencies.
ALTER TABLE migrations ADD PRIMARY KEY (version);

View File

@ -0,0 +1,16 @@
-- primary key is required by some database tools and dependencies.
-- 1. Create a new table with primary key
CREATE TABLE migrations_with_primary_key (
version TEXT PRIMARY KEY
);
-- 2. Copy data (without this step, the new migration table would be empty after startup on a fresh db)
INSERT INTO migrations_with_primary_key(version)
SELECT version
FROM migrations;
-- 3. Drop the old table
DROP TABLE migrations;
-- 4. Rename the new table
ALTER TABLE migrations_with_primary_key RENAME TO migrations;