apidb: Compact Stein database migrations

Specific changes include:

- Add 'user_id' column to 'instance_mappings' table (062)
- Add index covering 'user_id' and 'project_id' columns to
  'instance_mappings' table (062)

Note that we forgot to add placeholder migrations in Rocky, meaning
there is significantly less to clean up here.

Change-Id: I38a6f4d1c3d2a9797ba543694401b7b821a79805
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2020-10-23 11:41:02 +01:00
parent 6665bd8cb9
commit dae3c89874
4 changed files with 5 additions and 61 deletions

View File

@ -1,32 +0,0 @@
# 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.
from sqlalchemy import Column
from sqlalchemy import Index
from sqlalchemy import MetaData
from sqlalchemy import String
from sqlalchemy import Table
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
instance_mappings = Table('instance_mappings', meta, autoload=True)
if not hasattr(instance_mappings.c, 'user_id'):
instance_mappings.create_column(Column('user_id', String(length=255),
nullable=True))
index = Index('instance_mappings_user_id_project_id_idx',
instance_mappings.c.user_id,
instance_mappings.c.project_id)
index.create()

View File

@ -86,10 +86,14 @@ def upgrade(migrate_engine):
Column(
'queued_for_delete', Boolean(create_constraint=False),
default=False),
Column('user_id', String(length=255), nullable=True),
UniqueConstraint(
'instance_uuid', name='uniq_instance_mappings0instance_uuid'),
Index('instance_uuid_idx', 'instance_uuid'),
Index('project_id_idx', 'project_id'),
Index(
'instance_mappings_user_id_project_id_idx', 'user_id',
'project_id'),
ForeignKeyConstraint(
columns=['cell_id'], refcolumns=[cell_mappings.c.id]),
mysql_engine='InnoDB',

View File

@ -30,7 +30,7 @@ from nova.i18n import _
INIT_VERSION = {}
INIT_VERSION['main'] = 401
INIT_VERSION['api'] = 60
INIT_VERSION['api'] = 61
_REPOSITORY = {}
LOG = logging.getLogger(__name__)

View File

@ -35,9 +35,6 @@ import mock
from oslo_db.sqlalchemy import enginefacade
from oslo_db.sqlalchemy import test_fixtures
from oslo_db.sqlalchemy import test_migrations
from oslo_db.sqlalchemy import utils as db_utils
import sqlalchemy
from sqlalchemy.engine import reflection
import testtools
from nova.db import migration
@ -170,7 +167,6 @@ class NovaAPIMigrationsWalk(test_migrations.WalkVersionsMixin):
return self.engine
def _skippable_migrations(self):
# We forgot to add the rocky placeholders
stein_placeholders = list(range(63, 68))
train_placeholders = list(range(68, 73))
ussuri_placeholders = list(range(73, 78))
@ -196,30 +192,6 @@ class NovaAPIMigrationsWalk(test_migrations.WalkVersionsMixin):
def test_walk_versions(self):
self.walk_versions(snake_walk=False, downgrade=False)
def assertColumnExists(self, engine, table_name, column):
self.assertTrue(db_utils.column_exists(engine, table_name, column),
'Column %s.%s does not exist' % (table_name, column))
def assertIndexExists(self, engine, table_name, index):
self.assertTrue(db_utils.index_exists(engine, table_name, index),
'Index %s on table %s does not exist' %
(index, table_name))
def assertUniqueConstraintExists(self, engine, table_name, columns):
inspector = reflection.Inspector.from_engine(engine)
constrs = inspector.get_unique_constraints(table_name)
constr_columns = [constr['column_names'] for constr in constrs]
self.assertIn(columns, constr_columns)
def assertTableNotExists(self, engine, table_name):
self.assertRaises(sqlalchemy.exc.NoSuchTableError,
db_utils.get_table, engine, table_name)
def _check_062(self, engine, data):
self.assertColumnExists(engine, 'instance_mappings', 'user_id')
self.assertIndexExists(engine, 'instance_mappings',
'instance_mappings_user_id_project_id_idx')
class TestNovaAPIMigrationsWalkSQLite(NovaAPIMigrationsWalk,
test_fixtures.OpportunisticDBTestMixin,