Add a migration for another set of index creations

This commit adds a new migration that will create some unique
constraints which will help with the performance of some larger
queries as well as better model the relationships of the
metadata tables.

Change-Id: Ie87fedd6567c7258fec9434b7cc3e23b601159cf
This commit is contained in:
Matthew Treinish 2015-12-02 11:12:01 -05:00
parent 990776c8c6
commit 5a22609d18
No known key found for this signature in database
GPG Key ID: FD12A0F214C9E177
3 changed files with 56 additions and 3 deletions

View File

@ -0,0 +1,3 @@
---
upgrade:
- A new migration is added to add unique constraints on the metadata tables.

View File

@ -110,7 +110,9 @@ class TestRun(BASE, SubunitBase):
class RunMetadata(BASE, SubunitBase): class RunMetadata(BASE, SubunitBase):
__tablename__ = 'run_metadata' __tablename__ = 'run_metadata'
__table_args__ = (sa.Index('ix_run_key_value', 'key', 'value'), __table_args__ = (sa.Index('ix_run_key_value', 'key', 'value'),
sa.Index('ix_run_id', 'run_id')) sa.Index('ix_run_id', 'run_id'),
sa.UniqueConstraint('run_id', 'key', 'value',
name='uq_run_metadata'))
id = sa.Column(sa.BigInteger, primary_key=True) id = sa.Column(sa.BigInteger, primary_key=True)
key = sa.Column(sa.String(255)) key = sa.Column(sa.String(255))
@ -123,7 +125,9 @@ class RunMetadata(BASE, SubunitBase):
class TestRunMetadata(BASE, SubunitBase): class TestRunMetadata(BASE, SubunitBase):
__tablename__ = 'test_run_metadata' __tablename__ = 'test_run_metadata'
__table_args__ = (sa.Index('ix_test_run_key_value', 'key', 'value'), __table_args__ = (sa.Index('ix_test_run_key_value', 'key', 'value'),
sa.Index('ix_test_run_id', 'test_run_id')) sa.Index('ix_test_run_id', 'test_run_id'),
sa.UniqueConstraint('test_run_id', 'key', 'value',
name='uq_test_run_metadata'))
id = sa.Column(sa.BigInteger, primary_key=True) id = sa.Column(sa.BigInteger, primary_key=True)
key = sa.Column(sa.String(255)) key = sa.Column(sa.String(255))
@ -138,7 +142,9 @@ class TestRunMetadata(BASE, SubunitBase):
class TestMetadata(BASE, SubunitBase): class TestMetadata(BASE, SubunitBase):
__tablename__ = 'test_metadata' __tablename__ = 'test_metadata'
__table_args__ = (sa.Index('ix_test_key_value', 'key', 'value'), __table_args__ = (sa.Index('ix_test_key_value', 'key', 'value'),
sa.Index('ix_test_id', 'test_id')) sa.Index('ix_test_id', 'test_id'),
sa.UniqueConstraint('test_id', 'key', 'value',
name='uq_test_metadata'))
id = sa.Column(sa.BigInteger, primary_key=True) id = sa.Column(sa.BigInteger, primary_key=True)
key = sa.Column(sa.String(255)) key = sa.Column(sa.String(255))

View File

@ -0,0 +1,44 @@
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Add even more indexes
Revision ID: 10a2b6d4b06e
Revises: 35cd45895e56
Create Date: 2015-12-01 18:19:11.328298
"""
# revision identifiers, used by Alembic.
revision = '10a2b6d4b06e'
down_revision = '35cd45895e56'
from alembic import op
def upgrade():
with op.batch_alter_table('run_metadata') as batch_op:
batch_op.create_unique_constraint('uq_run_metadata',
['run_id', 'key', 'value'])
with op.batch_alter_table('test_metadata') as batch_op:
batch_op.create_unique_constraint('uq_test_metadata',
['test_id', 'key', 'value'])
with op.batch_alter_table('test_run_metadata') as batch_op:
batch_op.create_unique_constraint('uq_test_run_metadata',
['test_run_id', 'key', 'value'])
def downgrade():
NotImplementedError()