From 3a0af236ca8f151f0c91555783c14278e15a16b7 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Mon, 4 Apr 2016 16:48:44 -0400 Subject: [PATCH] Rework migration 1679b5bc102c to not use the db api This commit reworks the data migration to split microseconds from the time column into the separate microseconds column as to not rely on the DB api. For sqlite and postgres this causes potential issues when we try to modify the schema for the test_runs table when this migration is run because the models don't match the state of the DB when this migration is run. MySQL is unaffected by this potential issue because it runs the migration separately in hand written sql. Change-Id: I527e2ab9d030be639954fdb63584c3c4c6f4dd1c --- ...dd_subsecond_columns_to_test_runs_table.py | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/subunit2sql/migrations/versions/1679b5bc102c_add_subsecond_columns_to_test_runs_table.py b/subunit2sql/migrations/versions/1679b5bc102c_add_subsecond_columns_to_test_runs_table.py index 398ac25..fe1a969 100644 --- a/subunit2sql/migrations/versions/1679b5bc102c_add_subsecond_columns_to_test_runs_table.py +++ b/subunit2sql/migrations/versions/1679b5bc102c_add_subsecond_columns_to_test_runs_table.py @@ -29,12 +29,8 @@ import os from alembic import context from alembic import op from oslo_config import cfg -from oslo_db.sqlalchemy import utils as db_utils import sqlalchemy as sa -from subunit2sql.db import api as db_api -from subunit2sql.db import models - CONF = cfg.CONF @@ -54,17 +50,19 @@ def upgrade(): op.add_column('test_runs', sa.Column('stop_time_microsecond', sa.Integer(), default=0)) if not CONF.disable_microsecond_data_migration: - session = db_api.get_session() - query = db_utils.model_query(models.TestRun, session).values( - models.TestRun.id, models.TestRun.start_time, - models.TestRun.stop_time) - for test_run in query: - start_micro = test_run[1].microsecond - stop_micro = test_run[2].microsecond + bind = op.get_bind() + metadata = sa.schema.MetaData() + metadata.bind = bind + test_runs = sa.Table('test_runs', metadata, autoload=True) + res = test_runs.select().execute() + for test_run in res: + start_micro = test_run[4].microsecond + stop_micro = test_run[5].microsecond values = {'start_time_microsecond': start_micro, 'stop_time_microsecond': stop_micro} - db_api.update_test_run(values, test_run[0], session) - session.close() + op.execute(test_runs.update().where( + test_runs.c.id == test_run[0]).values(values)) + res.close() def downgrade():