Compact Liberty database migrations

This compacts all database migrations up to Liberty into one
initial schema to remove the need to apply every database
change along the way.

Change-Id: Id3b43e0df3162e368007c705d249539047d5da08
This commit is contained in:
Sean McGinnis 2016-09-19 15:37:44 -05:00
parent 205a850276
commit 38f2ad54b3
18 changed files with 42 additions and 412 deletions

View File

@ -28,7 +28,7 @@ from cinder import exception
from cinder.i18n import _
INIT_VERSION = 45
INIT_VERSION = 60
_IMPL = None
_LOCK = threading.Lock()

View File

@ -1,44 +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 oslo_utils import timeutils
from sqlalchemy import MetaData, Table
# Get default value via config. The default will either
# come from the default value set in the quota configuration option
# or via cinder.conf if the user has configured
# default value for per volume size limit there.
def upgrade(migrate_engine):
"""Add default "per_volume_gigabytes" row into DB."""
meta = MetaData()
meta.bind = migrate_engine
quota_classes = Table('quota_classes', meta, autoload=True)
row = quota_classes.count().\
where(quota_classes.c.resource == 'per_volume_gigabytes').\
execute().scalar()
# Do not add entry if there is already 'default' entry exists
# in the database.
# We don't want to write over something the user added.
if row:
return
# Set default per_volume_gigabytes for per volume size
qci = quota_classes.insert()
qci.execute({'created_at': timeutils.utcnow(),
'class_name': 'default',
'resource': 'per_volume_gigabytes',
'hard_limit': -1,
'deleted': False, })

View File

@ -1,25 +0,0 @@
# Copyright 2015 Yahoo Inc.
#
# 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, Integer, MetaData, Table
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
quotas = Table('quotas', meta, autoload=True)
# Add a new column allocated to save allocated quota
allocated = Column('allocated', Integer, default=0)
quotas.create_column(allocated)

View File

@ -1,31 +0,0 @@
# Copyright (c) 2015 EMC Corporation
# All Rights Reserved.
#
# 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, MetaData, String, Table
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
backups = Table('backups', meta, autoload=True)
temp_volume_id = Column('temp_volume_id', String(length=36))
temp_snapshot_id = Column('temp_snapshot_id', String(length=36))
backups.create_column(temp_volume_id)
backups.update().values(temp_volume_id=None).execute()
backups.create_column(temp_snapshot_id)
backups.update().values(temp_snapshot_id=None).execute()

View File

@ -1,27 +0,0 @@
# Copyright (c) 2015 EMC Corporation
# All Rights Reserved.
#
# 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, MetaData, String, Table
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
volumes = Table('volumes', meta, autoload=True)
previous_status = Column('previous_status', String(length=255))
volumes.create_column(previous_status)
volumes.update().values(previous_status=None).execute()

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, String, Table
def upgrade(migrate_engine):
"""Add source_cgid column to consistencygroups."""
meta = MetaData()
meta.bind = migrate_engine
consistencygroups = Table('consistencygroups', meta, autoload=True)
source_cgid = Column('source_cgid', String(36))
consistencygroups.create_column(source_cgid)
consistencygroups.update().values(source_cgid=None).execute()

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 Column
from sqlalchemy import MetaData, String, Table
def upgrade(migrate_engine):
"""Add provider_auth column to snapshots."""
meta = MetaData()
meta.bind = migrate_engine
snapshots = Table('snapshots', meta, autoload=True)
provider_auth = Column('provider_auth', String(255))
snapshots.create_column(provider_auth)
snapshots.update().values(provider_auth=None).execute()

View File

@ -1,36 +0,0 @@
# Copyright (C) 2015 SimpliVity Corp.
# All Rights Reserved.
#
# 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, String, Table
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
services = Table('services', meta, autoload=True)
rpc_current_version = Column('rpc_current_version', String(36))
rpc_available_version = Column('rpc_available_version', String(36))
object_current_version = Column('object_current_version', String(36))
object_available_version = Column('object_available_version', String(36))
services.create_column(rpc_current_version)
services.create_column(rpc_available_version)
services.create_column(object_current_version)
services.create_column(object_available_version)
services.update().values(rpc_current_version=None).execute()
services.update().values(rpc_available_version=None).execute()
services.update().values(object_current_version=None).execute()
services.update().values(object_available_version=None).execute()

View File

@ -1,33 +0,0 @@
# Copyright (c) 2015 Huawei Technologies Co., Ltd.
# All Rights Reserved.
#
# 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, Integer, MetaData, Table
def upgrade(migrate_engine):
"""Add num_dependent_backups column to backups."""
meta = MetaData()
meta.bind = migrate_engine
backups = Table('backups', meta, autoload=True)
num_dependent_backups = Column('num_dependent_backups', Integer, default=0)
backups.create_column(num_dependent_backups)
backups_list = list(backups.select().execute())
for backup in backups_list:
dep_bks_list = list(backups.select().where(backups.columns.parent_id ==
backup.id).execute())
if dep_bks_list:
backups.update().where(backups.columns.id == backup.id).values(
num_dependent_backups=len(dep_bks_list)).execute()

View File

@ -1,37 +0,0 @@
# Copyright (C) 2015 Pure Storage, Inc.
#
# 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, DateTime, Integer
from sqlalchemy import MetaData, String, Table
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
# New table
image_volume_cache = Table(
'image_volume_cache_entries', meta,
Column('image_updated_at', DateTime(timezone=False)),
Column('id', Integer, primary_key=True, nullable=False),
Column('host', String(length=255), index=True, nullable=False),
Column('image_id', String(length=36), index=True, nullable=False),
Column('volume_id', String(length=36), nullable=False),
Column('size', Integer, nullable=False),
Column('last_used', DateTime, nullable=False),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
image_volume_cache.create()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,30 +0,0 @@
# Copyright (c) 2015 EMC Corporation
# All Rights Reserved.
#
# 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, DateTime, MetaData, String, Table
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
backups = Table('backups', meta, autoload=True)
snapshot_id = Column('snapshot_id', String(length=36))
data_timestamp = Column('data_timestamp', DateTime)
backups.create_column(snapshot_id)
backups.create_column(data_timestamp)
backups.update().values(data_timestamp=backups.c.created_at).execute()

View File

@ -48,6 +48,10 @@ def define_tables(meta):
Column('availability_zone', String(255)),
Column('disabled_reason', String(255)),
Column('modified_at', DateTime(timezone=False)),
Column('rpc_current_version', String(36)),
Column('rpc_available_version', String(36)),
Column('object_current_version', String(36)),
Column('object_available_version', String(36)),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
@ -68,6 +72,7 @@ def define_tables(meta):
Column('volume_type_id', String(255)),
Column('status', String(255)),
Column('cgsnapshot_id', String(36)),
Column('source_cgid', String(36)),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
@ -128,6 +133,7 @@ def define_tables(meta):
ForeignKey('consistencygroups.id')),
Column('provider_id', String(255)),
Column('multiattach', Boolean),
Column('previous_status', String(255)),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
@ -176,6 +182,7 @@ def define_tables(meta):
Column('cgsnapshot_id', String(36),
ForeignKey('cgsnapshots.id')),
Column('provider_id', String(255)),
Column('provider_auth', String(255)),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
@ -283,6 +290,7 @@ def define_tables(meta):
Column('project_id', String(255)),
Column('resource', String(255), nullable=False),
Column('hard_limit', Integer),
Column('allocated', Integer, default=0),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
@ -396,6 +404,11 @@ def define_tables(meta):
Column('size', Integer()),
Column('object_count', Integer()),
Column('parent_id', String(36)),
Column('temp_volume_id', String(36)),
Column('temp_snapshot_id', String(36)),
Column('num_dependent_backups', Integer, default=0),
Column('snapshot_id', String(36)),
Column('data_timestamp', DateTime),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
@ -475,6 +488,19 @@ def define_tables(meta):
mysql_charset='utf8'
)
image_volume_cache = Table(
'image_volume_cache_entries', meta,
Column('image_updated_at', DateTime(timezone=False)),
Column('id', Integer, primary_key=True, nullable=False),
Column('host', String(255), index=True, nullable=False),
Column('image_id', String(36), index=True, nullable=False),
Column('volume_id', String(36), nullable=False),
Column('size', Integer, nullable=False),
Column('last_used', DateTime, nullable=False),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
return [consistencygroups,
cgsnapshots,
volumes,
@ -497,7 +523,8 @@ def define_tables(meta):
transfers,
encryption,
volume_admin_metadata,
initiator_data]
initiator_data,
image_volume_cache]
def upgrade(migrate_engine):
@ -535,7 +562,8 @@ def upgrade(migrate_engine):
"transfers",
"encryption",
"volume_admin_metadata",
"driver_initiator_data"]
"driver_initiator_data",
"image_volume_cache_entries"]
migrate_engine.execute("SET foreign_key_checks = 0")
for table in tables:
@ -572,3 +600,8 @@ def upgrade(migrate_engine):
'resource': 'consistencygroups',
'hard_limit': CONF.quota_consistencygroups,
'deleted': False, })
qci.execute({'created_at': CREATED_AT,
'class_name': CLASS_NAME,
'resource': 'per_volume_gigabytes',
'hard_limit': -1,
'deleted': False, })

View File

@ -0,0 +1,6 @@
---
upgrade:
- The Cinder database can now only be upgraded from changes since the
Liberty release. In order to upgrade from a version prior to that,
you must now upgrade to at least Liberty first, then to Ocata or
later.