Files
subunit2sql/subunit2sql/migrations/versions/1679b5bc102c_add_subsecond_columns_to_test_runs_table.mysql_upgrade.sql
Matthew Treinish 86b867521e Hard code the sql for mysql on migration 1679b5bc102
Due to some issues with trying to execute migration 1679b5bc102 with
the alembic operations on the production infra subunit2sql DB this
commit adds some explicit SQL commands to achieve the same end goal,
but bypass the issues.

Co-Authored-By: Monty Taylor <mordred@inaugust.com>
Change-Id: Ie7fee27dd4eaa5cbdb24a0578274439227e9f1bb
2015-03-16 21:42:50 +00:00

17 lines
999 B
SQL

--
-- This file is necessary because of an issue with a large MySQL DB having
-- issues with the alter table to add a column
--
CREATE TABLE test_runs_migration LIKE test_runs;
ALTER TABLE test_runs_migration ADD COLUMN start_time_microsecond INTEGER default 0;
ALTER TABLE test_runs_migration ADD COLUMN stop_time_microsecond INTEGER default 0;
LOCK TABLES test_runs write, test_runs_migration write, test_run_metadata write;
INSERT INTO test_runs_migration SELECT id, test_id, run_id, status, start_time, stop_time, MICROSECOND(start_time), MICROSECOND(stop_time) from test_runs;
ALTER TABLE test_run_metadata drop foreign key test_run_metadata_ibfk_1;
UNLOCK TABLES;
-- race condition here - but at worst you'll lose a microsecond of data as rename is very fast and atomic
RENAME TABLE test_runs to test_runs_old, test_runs_migration to test_runs;
ALTER TABLE test_run_metadata ADD CONSTRAINT test_run_metadata_ibfk_1 FOREIGN KEY(test_run_id) REFERENCES test_runs(id);
DROP TABLE test_runs_old;