Skip to content

Commit 1abd11d

Browse files
Update test status in place (Kitware#3083)
Kitware#3012 added a migration which proved to be exceedingly slow on large systems. This PR attempts to speed up the migration by updating the status column in-place, thus preventing a table rewrite.
1 parent 2a48731 commit 1abd11d

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

database/migrations/2025_07_30_131713_test_status_enum.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ public function up(): void
99
// We drop the type first in case the database has been truncated previously.
1010
DB::statement('DROP TYPE IF EXISTS teststatus');
1111
DB::statement("CREATE TYPE teststatus AS ENUM ('failed', 'notrun', 'passed')");
12-
DB::statement('ALTER TABLE build2test RENAME COLUMN status TO old_status');
13-
DB::statement('ALTER TABLE build2test ADD COLUMN status teststatus');
14-
DB::update("UPDATE build2test SET status = old_status::teststatus WHERE old_status IN ('failed', 'notrun', 'passed')");
15-
DB::update("UPDATE build2test SET status = 'passed' WHERE status IS NULL");
12+
DB::statement('ALTER TABLE build2test ALTER COLUMN status DROP DEFAULT');
13+
DB::statement("
14+
ALTER TABLE build2test
15+
ALTER COLUMN status
16+
TYPE teststatus USING
17+
CASE
18+
WHEN status = 'failed' THEN 'failed'::teststatus
19+
WHEN status = 'notrun' THEN 'notrun'::teststatus
20+
WHEN status = 'passed' THEN 'passed'::teststatus
21+
ELSE 'passed'::teststatus
22+
END
23+
");
1624
DB::statement('ALTER TABLE build2test ALTER COLUMN status SET NOT NULL');
17-
DB::statement('ALTER TABLE build2test DROP COLUMN old_status');
18-
DB::statement('CREATE INDEX ON build2test (buildid, status)');
1925
}
2026

2127
public function down(): void

0 commit comments

Comments
 (0)