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
This commit is contained in:
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user