apidb: Compact Queens database migrations

Specific changes include:

- Add 'description' column to 'flavors' table (050)
- Add 'root_provider_id' and 'parent_provider_id' columns to
  'resource_providers' table (051)
- Add indexes covering 'root_provider_id' and 'parent_provider_id'
  columns of 'resource_providers' table (051)
- Alter type of 'spec' column of 'request_specs' table to MediumText
  (052)

Change-Id: Iafccbb52cba0c45b5159984d6560b822d9405d5f
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2020-10-23 11:24:48 +01:00
parent 31f01aa44f
commit 86b423f9f3
11 changed files with 13 additions and 261 deletions

View File

@ -1,23 +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.
# This is a placeholder for backports.
# Do not use this number for new work. New work starts after
# all the placeholders.
#
# See this for more information:
# http://lists.openstack.org/pipermail/openstack-dev/2013-March/006827.html
def upgrade(migrate_engine):
pass

View File

@ -1,23 +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.
# This is a placeholder for backports.
# Do not use this number for new work. New work starts after
# all the placeholders.
#
# See this for more information:
# http://lists.openstack.org/pipermail/openstack-dev/2013-March/006827.html
def upgrade(migrate_engine):
pass

View File

@ -1,23 +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.
# This is a placeholder for backports.
# Do not use this number for new work. New work starts after
# all the placeholders.
#
# See this for more information:
# http://lists.openstack.org/pipermail/openstack-dev/2013-March/006827.html
def upgrade(migrate_engine):
pass

View File

@ -1,23 +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.
# This is a placeholder for backports.
# Do not use this number for new work. New work starts after
# all the placeholders.
#
# See this for more information:
# http://lists.openstack.org/pipermail/openstack-dev/2013-March/006827.html
def upgrade(migrate_engine):
pass

View File

@ -1,23 +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.
# This is a placeholder for backports.
# Do not use this number for new work. New work starts after
# all the placeholders.
#
# See this for more information:
# http://lists.openstack.org/pipermail/openstack-dev/2013-March/006827.html
def upgrade(migrate_engine):
pass

View File

@ -1,26 +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 MetaData
from sqlalchemy import Table
from sqlalchemy import Text
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
flavors = Table('flavors', meta, autoload=True)
if not hasattr(flavors.c, 'description'):
flavors.create_column(Column('description', Text()))

View File

@ -1,50 +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 ForeignKey
from sqlalchemy import Index
from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy import Table
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
resource_providers = Table('resource_providers', meta, autoload=True)
columns_to_add = [
('root_provider_id',
Column('root_provider_id', Integer,
ForeignKey('resource_providers.id'))),
('parent_provider_id',
Column('parent_provider_id', Integer,
ForeignKey('resource_providers.id'))),
]
for col_name, column in columns_to_add:
if not hasattr(resource_providers.c, col_name):
resource_providers.create_column(column)
indexed_columns = set()
for idx in resource_providers.indexes:
for c in idx.columns:
indexed_columns.add(c.name)
if 'root_provider_id' not in indexed_columns:
index = Index('resource_providers_root_provider_id_idx',
resource_providers.c.root_provider_id)
index.create()
if 'parent_provider_id' not in indexed_columns:
index = Index('resource_providers_parent_provider_id_idx',
resource_providers.c.parent_provider_id)
index.create()

View File

@ -102,6 +102,7 @@ def upgrade(migrate_engine):
Column('ephemeral_gb', Integer),
Column('disabled', Boolean),
Column('is_public', Boolean),
Column('description', Text()),
UniqueConstraint('flavorid', name='uniq_flavors0flavorid'),
UniqueConstraint('name', name='uniq_flavors0name'),
mysql_engine='InnoDB',
@ -143,7 +144,7 @@ def upgrade(migrate_engine):
Column('updated_at', DateTime),
Column('id', Integer, primary_key=True, nullable=False),
Column('instance_uuid', String(36), nullable=False),
Column('spec', Text, nullable=False),
Column('spec', MediumText(), nullable=False),
UniqueConstraint(
'instance_uuid', name='uniq_request_specs0instance_uuid'),
Index('request_spec_instance_uuid_idx', 'instance_uuid'),
@ -249,10 +250,19 @@ def upgrade(migrate_engine):
Column('name', Unicode(200, **nameargs), nullable=True),
Column('generation', Integer, default=0),
Column('can_host', Integer, default=0),
Column(
'root_provider_id', Integer,
ForeignKey('resource_providers.id')),
Column(
'parent_provider_id', Integer,
ForeignKey('resource_providers.id')),
UniqueConstraint('uuid', name='uniq_resource_providers0uuid'),
UniqueConstraint('name', name='uniq_resource_providers0name'),
Index('resource_providers_name_idx', 'name'),
Index('resource_providers_uuid_idx', 'uuid'),
Index('resource_providers_root_provider_id_idx', 'root_provider_id'),
Index(
'resource_providers_parent_provider_id_idx', 'parent_provider_id'),
mysql_engine='InnoDB',
mysql_charset='latin1'
)

View File

@ -1,25 +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 MetaData
from sqlalchemy import Table
from nova.db.sqlalchemy import api_models
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
request_specs = Table('request_specs', meta, autoload=True)
if request_specs.c.spec.type != api_models.MediumText():
request_specs.c.spec.alter(type=api_models.MediumText())

View File

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

View File

@ -36,7 +36,6 @@ 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
from oslo_serialization import jsonutils
import sqlalchemy
from sqlalchemy.engine import reflection
import testtools
@ -172,7 +171,6 @@ class NovaAPIMigrationsWalk(test_migrations.WalkVersionsMixin):
return self.engine
def _skippable_migrations(self):
pike_placeholders = list(range(45, 50))
queens_placeholders = list(range(53, 58))
# We forgot to add the rocky placeholders
stein_placeholders = list(range(63, 68))
@ -182,8 +180,7 @@ class NovaAPIMigrationsWalk(test_migrations.WalkVersionsMixin):
special_cases = [
self.INIT_VERSION + 1, # initial change
]
return (pike_placeholders +
queens_placeholders +
return (queens_placeholders +
stein_placeholders +
train_placeholders +
ussuri_placeholders +
@ -221,45 +218,6 @@ class NovaAPIMigrationsWalk(test_migrations.WalkVersionsMixin):
self.assertRaises(sqlalchemy.exc.NoSuchTableError,
db_utils.get_table, engine, table_name)
def _check_050(self, engine, data):
self.assertColumnExists(engine, 'flavors', 'description')
def _check_051(self, engine, data):
for column in ['root_provider_id', 'parent_provider_id']:
self.assertColumnExists(engine, 'resource_providers', column)
self.assertIndexExists(engine, 'resource_providers',
'resource_providers_root_provider_id_idx')
self.assertIndexExists(engine, 'resource_providers',
'resource_providers_parent_provider_id_idx')
def _pre_upgrade_052(self, engine):
request_specs = db_utils.get_table(engine, 'request_specs')
# The spec value is a serialized json blob.
spec = jsonutils.dumps(
{"instance_group": {"id": 42,
"members": ["uuid1",
"uuid2",
"uuid3"]}})
fake_request_spec = {
'id': 42, 'spec': spec, 'instance_uuid': uuids.instance}
request_specs.insert().execute(fake_request_spec)
def _check_052(self, engine, data):
request_specs = db_utils.get_table(engine, 'request_specs')
if engine.name == 'mysql':
self.assertIsInstance(request_specs.c.spec.type,
sqlalchemy.dialects.mysql.MEDIUMTEXT)
expected_spec = {"instance_group": {"id": 42,
"members": ["uuid1",
"uuid2",
"uuid3"]}}
from_db_request_spec = request_specs.select(
request_specs.c.id == 42).execute().first()
self.assertEqual(uuids.instance, from_db_request_spec['instance_uuid'])
db_spec = jsonutils.loads(from_db_request_spec['spec'])
self.assertDictEqual(expected_spec, db_spec)
def _check_058(self, engine, data):
self.assertColumnExists(engine, 'cell_mappings', 'disabled')