Fix issues in migration 1ff737bef438
This commit fixes a couple of issues with the migration 1ff737bef438. First, on multi-byte configured mysql systems the status column is too big to index, so this adds a length to the index to allow it to run on those envs. The second is that since the migration fails to run on certain envs checks need to be done to account for migrations that are only partially applied. The min version of SQLAlchemy is also bumped to version 0.8.2 because that's when using dictionaries on the mysql_length for composite indexes was added. Change-Id: Iad056d44251ad2eac8a5cb5628779b27c2126630
This commit is contained in:
parent
c7f1df0962
commit
4d04042bd6
|
@ -4,5 +4,5 @@ oslo.db!=1.12.0,<2.0.0
|
|||
pbr>=1.0.0
|
||||
python-subunit>=0.0.18
|
||||
six>=1.5.2
|
||||
SQLAlchemy>=0.7.8
|
||||
SQLAlchemy>=0.8.2
|
||||
stevedore>=1.3.0
|
||||
|
|
|
@ -24,26 +24,50 @@ Create Date: 2015-06-25 14:27:10.465845
|
|||
revision = '1ff737bef438'
|
||||
down_revision = '487f279b8c78'
|
||||
|
||||
from alembic import context
|
||||
from alembic import op
|
||||
from sqlalchemy.engine import reflection
|
||||
|
||||
|
||||
def upgrade():
|
||||
migration_context = context.get_context()
|
||||
insp = reflection.Inspector(migration_context.bind)
|
||||
run_indx = insp.get_indexes('runs')
|
||||
run_indx_names = [x['name'] for x in run_indx]
|
||||
test_run_indx = insp.get_indexes('test_runs')
|
||||
test_run_indx_names = [x['name'] for x in test_run_indx]
|
||||
test_run_metad_indx = insp.get_indexes('test_run_metadata')
|
||||
test_run_metad_indx_names = [x['name'] for x in test_run_metad_indx]
|
||||
run_metad_indx = insp.get_indexes('run_metadata')
|
||||
run_metad_indx_names = [x['name'] for x in run_metad_indx]
|
||||
test_metad_indx = insp.get_indexes('test_metadata')
|
||||
test_metad_indx_names = [x['name'] for x in test_metad_indx]
|
||||
|
||||
# Add indexes to time columns these are often used for searches and filters
|
||||
op.create_index('ix_test_start_time', 'test_runs',
|
||||
['start_time'])
|
||||
op.create_index('ix_test_stop_time', 'test_runs',
|
||||
['stop_time'])
|
||||
op.create_index('ix_run_at', 'runs', ['run_at'])
|
||||
if 'ix_test_start_time' not in test_run_indx_names:
|
||||
op.create_index('ix_test_start_time', 'test_runs',
|
||||
['start_time'])
|
||||
if 'ix_test_stop_time' not in test_run_indx_names:
|
||||
op.create_index('ix_test_stop_time', 'test_runs',
|
||||
['stop_time'])
|
||||
if 'ix_run_at' not in run_indx_names:
|
||||
op.create_index('ix_run_at', 'runs', ['run_at'])
|
||||
# Add compound index on metadata tables key, value columns
|
||||
op.create_index('ix_run_key_value', 'run_metadata', ['key', 'value'])
|
||||
op.create_index('ix_test_run_key_value', 'test_run_metadata',
|
||||
['key', 'value'])
|
||||
op.create_index('ix_test_key_value', 'test_metadata', ['key', 'value'])
|
||||
if 'ix_run_key_value' not in run_metad_indx_names:
|
||||
op.create_index('ix_run_key_value', 'run_metadata', ['key', 'value'])
|
||||
if 'ix_test_run_key_value' not in test_run_metad_indx_names:
|
||||
op.create_index('ix_test_run_key_value', 'test_run_metadata',
|
||||
['key', 'value'])
|
||||
if 'ix_test_key_value' not in test_metad_indx_names:
|
||||
op.create_index('ix_test_key_value', 'test_metadata', ['key', 'value'])
|
||||
# Add compound index on test_id and status and start_time, these are common
|
||||
# graph query patterns
|
||||
op.create_index('ix_test_id_status', 'test_runs', ['test_id', 'status'])
|
||||
op.create_index('ix_test_id_start_time', 'test_runs', ['test_id',
|
||||
'start_time'])
|
||||
if 'ix_test_id_status' not in test_run_indx_names:
|
||||
op.create_index('ix_test_id_status', 'test_runs',
|
||||
['test_id', 'status'], mysql_length={'status': 30})
|
||||
if 'ix_test_id_start_time' not in test_run_indx_names:
|
||||
op.create_index('ix_test_id_start_time', 'test_runs', ['test_id',
|
||||
'start_time'])
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
|
Loading…
Reference in New Issue