Squash all migrations into one

Migration #12 have fixed bug
https://bugs.launchpad.net/manila/+bug/1272303,
but introduced a new one. Because that bug
was rather architectural, we need to address
that architectural flaw instead of fixing
bugs as they come.
Closes-Bug: #1275044

Change-Id: I260a90abd1107c62b687118d5d4a01d7199ea56f
This commit is contained in:
Aleks Chirko 2014-02-04 14:13:11 +02:00
parent 9312341359
commit e8ade681b6
13 changed files with 275 additions and 1042 deletions

View File

@ -16,7 +16,7 @@
from oslo.config import cfg
from sqlalchemy import Boolean, Column, DateTime, ForeignKey
from sqlalchemy import Integer, MetaData, String, Table
from sqlalchemy import Integer, MetaData, String, Table, UniqueConstraint
from manila.openstack.common import log as logging
@ -35,7 +35,7 @@ def upgrade(migrate_engine):
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', Boolean),
Column('deleted', Integer, default=0),
Column('id', Integer, primary_key=True, nullable=False),
Column('source_compute', String(length=255)),
Column('dest_compute', String(length=255)),
@ -44,7 +44,8 @@ def upgrade(migrate_engine):
Column('instance_uuid', String(length=255)),
Column('old_instance_type_id', Integer),
Column('new_instance_type_id', Integer),
mysql_engine='InnoDB'
mysql_engine='InnoDB',
mysql_charset='utf8'
)
services = Table(
@ -52,7 +53,7 @@ def upgrade(migrate_engine):
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', Boolean),
Column('deleted', Integer, default=0),
Column('id', Integer, primary_key=True, nullable=False),
Column('host', String(length=255)),
Column('binary', String(length=255)),
@ -60,7 +61,8 @@ def upgrade(migrate_engine):
Column('report_count', Integer, nullable=False),
Column('disabled', Boolean),
Column('availability_zone', String(length=255)),
mysql_engine='InnoDB'
mysql_engine='InnoDB',
mysql_charset='utf8'
)
quotas = Table(
@ -69,18 +71,273 @@ def upgrade(migrate_engine):
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', Boolean),
Column('deleted', Integer, default=0),
Column('project_id', String(length=255)),
Column('resource', String(length=255), nullable=False),
Column('hard_limit', Integer),
mysql_engine='InnoDB'
mysql_engine='InnoDB',
mysql_charset='utf8'
)
quota_classes = Table(
'quota_classes', meta,
Column('created_at', DateTime(timezone=False)),
Column('updated_at', DateTime(timezone=False)),
Column('deleted_at', DateTime(timezone=False)),
Column('deleted', Integer, default=0),
Column('id', Integer(), primary_key=True),
Column('class_name',
String(length=255,
convert_unicode=True,
unicode_error=None,
_warn_on_bytestring=False),
index=True),
Column('resource',
String(length=255,
convert_unicode=True,
unicode_error=None,
_warn_on_bytestring=False)),
Column('hard_limit', Integer(), nullable=True),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
quota_usages = Table(
'quota_usages', meta,
Column('created_at', DateTime(timezone=False)),
Column('updated_at', DateTime(timezone=False)),
Column('deleted_at', DateTime(timezone=False)),
Column('deleted', Integer, default=0),
Column('id', Integer(), primary_key=True),
Column('user_id', String(length=255)),
Column('project_id',
String(length=255, convert_unicode=True,
unicode_error=None,
_warn_on_bytestring=False),
index=True),
Column('resource',
String(length=255, convert_unicode=True,
unicode_error=None,
_warn_on_bytestring=False)),
Column('in_use', Integer(), nullable=False),
Column('reserved', Integer(), nullable=False),
Column('until_refresh', Integer(), nullable=True),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
reservations = Table(
'reservations', meta,
Column('created_at', DateTime(timezone=False)),
Column('updated_at', DateTime(timezone=False)),
Column('deleted_at', DateTime(timezone=False)),
Column('deleted', Integer, default=0),
Column('id', Integer(), primary_key=True),
Column('user_id', String(length=255)),
Column('uuid',
String(length=36,
convert_unicode=True,
unicode_error=None,
_warn_on_bytestring=False),
nullable=False),
Column('usage_id',
Integer(),
ForeignKey('quota_usages.id'),
nullable=False),
Column('project_id',
String(length=255, convert_unicode=True,
unicode_error=None,
_warn_on_bytestring=False),
index=True),
Column('resource',
String(length=255, convert_unicode=True,
unicode_error=None,
_warn_on_bytestring=False)),
Column('delta', Integer(), nullable=False),
Column('expire', DateTime(timezone=False)),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
project_user_quotas = Table(
'project_user_quotas', meta,
Column('id', Integer, primary_key=True, nullable=False),
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', Integer, default=0),
Column('user_id', String(length=255), nullable=False),
Column('project_id', String(length=255), nullable=False),
Column('resource', String(length=25), nullable=False),
Column('hard_limit', Integer, nullable=True),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
shares = Table(
'shares', meta,
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', String(length=36), default='False'),
Column('id', String(length=36), primary_key=True, nullable=False),
Column('user_id', String(length=255)),
Column('project_id', String(length=255)),
Column('host', String(length=255)),
Column('size', Integer),
Column('availability_zone',
String(length=255)),
Column('status', String(length=255)),
Column('scheduled_at', DateTime),
Column('launched_at', DateTime),
Column('terminated_at', DateTime),
Column('display_name', String(length=255)),
Column('display_description', String(length=255)),
Column('snapshot_id', String(length=36)),
Column('share_network_id',
String(length=36),
ForeignKey('share_networks.id'),
nullable=True),
Column('share_proto', String(255)),
Column('export_location', String(255)),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
access_map = Table(
'share_access_map', meta,
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', String(length=36), default='False'),
Column('id', String(length=36), primary_key=True, nullable=False),
Column('share_id', String(36), ForeignKey('shares.id'),
nullable=False),
Column('access_type', String(255)),
Column('access_to', String(255)),
Column('state', String(255)),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
share_snapshots = Table(
'share_snapshots', meta,
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', String(length=36), default='False'),
Column('id', String(length=36), primary_key=True, nullable=False),
Column('user_id', String(length=255)),
Column('project_id', String(length=255)),
Column('share_id', String(36), ForeignKey('shares.id'),
nullable=False),
Column('size', Integer),
Column('status', String(length=255)),
Column('progress', String(length=255)),
Column('display_name', String(length=255)),
Column('display_description', String(length=255)),
Column('share_size', Integer),
Column('share_proto', String(length=255)),
Column('export_location', String(255)),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
share_metadata = Table(
'share_metadata', meta,
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', Integer, default=0),
Column('id', Integer, primary_key=True, nullable=False),
Column('share_id', String(length=36), ForeignKey('shares.id'),
nullable=False),
Column('key', String(length=255), nullable=False),
Column('value', String(length=1023), nullable=False),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
security_services = Table(
'security_services', meta,
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', String(length=36), default='False'),
Column('id', String(length=36), primary_key=True, nullable=False),
Column('project_id', String(length=36), nullable=False),
Column('type', String(length=32), nullable=False),
Column('dns_ip', String(length=64), nullable=True),
Column('server', String(length=255), nullable=True),
Column('domain', String(length=255), nullable=True),
Column('sid', String(length=255), nullable=True),
Column('password', String(length=255), nullable=True),
Column('name', String(length=255), nullable=True),
Column('description', String(length=255), nullable=True),
Column('status', String(length=16)),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
share_networks = Table(
'share_networks', meta,
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', String(length=36), default='False'),
Column('id', String(length=36), primary_key=True, nullable=False),
Column('project_id', String(length=36), nullable=False),
Column('neutron_net_id', String(length=36), nullable=True),
Column('neutron_subnet_id', String(length=36), nullable=True),
Column('network_type', String(length=32), nullable=True),
Column('segmentation_id', Integer, nullable=True),
Column('cidr', String(length=64), nullable=True),
Column('ip_version', Integer, nullable=True),
Column('name', String(length=255), nullable=True),
Column('description', String(length=255), nullable=True),
Column('status', String(length=32)),
UniqueConstraint('neutron_net_id', 'neutron_subnet_id', 'project_id',
'deleted', name='net_subnet_uc'),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
network_allocations = Table(
'network_allocations', meta,
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', String(length=36), default='False'),
Column('id', String(length=36), primary_key=True, nullable=False),
Column('ip_address', String(length=64), nullable=True),
Column('mac_address', String(length=32), nullable=True),
Column('share_network_id', String(length=36),
ForeignKey('share_networks.id'), nullable=False),
Column('status', String(length=32)),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
ss_nw_association = Table(
'share_network_security_service_association', meta,
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', Integer, default=0),
Column('id', Integer, primary_key=True, nullable=False),
Column('share_network_id', String(length=36),
ForeignKey('share_networks.id'), nullable=False),
Column('security_service_id', String(length=36),
ForeignKey('security_services.id'), nullable=False),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
# create all tables
# Take care on create order for those with FK dependencies
tables = [migrations,
quotas,
services]
tables = [migrations, quotas, services, quota_classes, quota_usages,
reservations, project_user_quotas, security_services,
share_networks, network_allocations, ss_nw_association,
shares, access_map, share_snapshots, share_metadata]
for table in tables:
try:
@ -91,10 +348,12 @@ def upgrade(migrate_engine):
raise
if migrate_engine.name == "mysql":
tables = ["migrate_version",
"migrations",
"quotas",
"services"]
tables = ["migrate_version", "migrations", "quotas", "services",
"quota_classes", "quota_usages", "reservations",
"project_user_quotas", "share_access_map", "share_snapshots",
"share_metadata", "security_services", "share_networks",
"network_allocations", "shares",
"share_network_security_service_association"]
sql = "SET foreign_key_checks = 0;"
for table in tables:
@ -107,4 +366,5 @@ def upgrade(migrate_engine):
def downgrade(migrate_engine):
LOG.exception(_('Downgrade from initial Manila install is unsupported.'))
raise NotImplementedError('Downgrade from initial Manila install is not'
' supported.')

View File

@ -1,150 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 OpenStack LLC.
#
# 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 Boolean, Column, DateTime
from sqlalchemy import MetaData, Integer, String, Table, ForeignKey
from manila.openstack.common import log as logging
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
# New table
quota_classes = Table('quota_classes', meta,
Column('created_at', DateTime(timezone=False)),
Column('updated_at', DateTime(timezone=False)),
Column('deleted_at', DateTime(timezone=False)),
Column('deleted', Boolean(create_constraint=True,
name=None)),
Column('id', Integer(), primary_key=True),
Column('class_name',
String(length=255,
convert_unicode=True,
unicode_error=None,
_warn_on_bytestring=False),
index=True),
Column('resource',
String(length=255,
convert_unicode=True,
unicode_error=None,
_warn_on_bytestring=False)),
Column('hard_limit', Integer(), nullable=True),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
try:
quota_classes.create()
except Exception:
LOG.error(_("Table |%s| not created!"), repr(quota_classes))
raise
quota_usages = Table('quota_usages', meta,
Column('created_at', DateTime(timezone=False)),
Column('updated_at', DateTime(timezone=False)),
Column('deleted_at', DateTime(timezone=False)),
Column('deleted', Boolean(create_constraint=True,
name=None)),
Column('id', Integer(), primary_key=True),
Column('project_id',
String(length=255, convert_unicode=True,
unicode_error=None,
_warn_on_bytestring=False),
index=True),
Column('resource',
String(length=255, convert_unicode=True,
unicode_error=None,
_warn_on_bytestring=False)),
Column('in_use', Integer(), nullable=False),
Column('reserved', Integer(), nullable=False),
Column('until_refresh', Integer(), nullable=True),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
try:
quota_usages.create()
except Exception:
LOG.error(_("Table |%s| not created!"), repr(quota_usages))
raise
reservations = Table('reservations', meta,
Column('created_at', DateTime(timezone=False)),
Column('updated_at', DateTime(timezone=False)),
Column('deleted_at', DateTime(timezone=False)),
Column('deleted', Boolean(create_constraint=True,
name=None)),
Column('id', Integer(), primary_key=True),
Column('uuid',
String(length=36,
convert_unicode=True,
unicode_error=None,
_warn_on_bytestring=False),
nullable=False),
Column('usage_id',
Integer(),
ForeignKey('quota_usages.id'),
nullable=False),
Column('project_id',
String(length=255, convert_unicode=True,
unicode_error=None,
_warn_on_bytestring=False),
index=True),
Column('resource',
String(length=255, convert_unicode=True,
unicode_error=None,
_warn_on_bytestring=False)),
Column('delta', Integer(), nullable=False),
Column('expire', DateTime(timezone=False)),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
try:
reservations.create()
except Exception:
LOG.error(_("Table |%s| not created!"), repr(reservations))
raise
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
quota_classes = Table('quota_classes', meta, autoload=True)
try:
quota_classes.drop()
except Exception:
LOG.error(_("quota_classes table not dropped"))
raise
quota_usages = Table('quota_usages', meta, autoload=True)
try:
quota_usages.drop()
except Exception:
LOG.error(_("quota_usages table not dropped"))
raise
reservations = Table('reservations', meta, autoload=True)
try:
reservations.drop()
except Exception:
LOG.error(_("reservations table not dropped"))
raise

View File

@ -1,79 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 NetApp
# 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 MetaData, Table, String, DateTime, Boolean
from sqlalchemy import Integer, Column, ForeignKey
from manila.openstack.common import log as logging
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine):
"""Create shares and share_access_map tables."""
meta = MetaData()
meta.bind = migrate_engine
shares = Table('shares', meta,
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', Boolean),
Column('id', String(length=36),
primary_key=True, nullable=False),
Column('user_id', String(length=255)),
Column('project_id', String(length=255)),
Column('host', String(length=255)),
Column('size', Integer),
Column('availability_zone',
String(length=255)),
Column('status', String(length=255)),
Column('scheduled_at', DateTime),
Column('launched_at', DateTime),
Column('terminated_at', DateTime),
Column('display_name', String(length=255)),
Column('display_description',
String(length=255)),
Column('snapshot_id', String(length=36)),
Column('share_proto', String(255)),
Column('export_location', String(255)),
mysql_engine='InnoDB')
access_map = Table('share_access_map', meta,
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', Boolean),
Column('id', String(length=36),
primary_key=True, nullable=False),
Column('share_id', String(36), ForeignKey('shares.id'),
nullable=False),
Column('access_type', String(255)),
Column('access_to', String(255)),
Column('state', String(255)),
mysql_engine='InnoDB')
shares.create()
access_map.create()
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
shares = Table('shares', meta, autoload=True)
access_map = Table('share_access_map', meta, autoload=True)
access_map.drop()
shares.drop()

View File

@ -1,70 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 NetApp
# 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.schema import Column, ForeignKey, MetaData, Table
from sqlalchemy.types import Boolean, DateTime, Integer, String
from manila.openstack.common import log as logging
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine):
"""Create shares and share_access_map tables."""
meta = MetaData()
meta.bind = migrate_engine
shares = Table('shares', meta, autoload=True)
share_snapshots = Table(
'share_snapshots', meta,
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', Boolean),
Column('id', String(length=36), primary_key=True, nullable=False),
Column('user_id', String(length=255)),
Column('project_id', String(length=255)),
Column('share_id', String(36), ForeignKey('shares.id'),
nullable=False),
Column('size', Integer),
Column('status', String(length=255)),
Column('progress', String(length=255)),
Column('display_name', String(length=255)),
Column('display_description', String(length=255)),
Column('share_size', Integer),
Column('share_proto', String(length=255)),
Column('export_location', String(255)),
mysql_engine='InnoDB')
try:
share_snapshots.create()
except Exception:
LOG.error(_("Table %r not created!"), share_snapshots)
raise
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
share_snapshots = Table('share_snapshots', meta, autoload=True)
try:
share_snapshots.drop()
except Exception:
LOG.error(_("share_snapshots table not dropped"))
raise

View File

@ -1,88 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 OpenStack Foundation
#
# 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 Index, UniqueConstraint, MetaData, String, Table
from manila.db.sqlalchemy import api as db
from manila.openstack.common.gettextutils import _
from manila.openstack.common import log as logging
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine):
# Upgrade operations go here. Don't create your own engine;
# bind migrate_engine to your metadata
meta = MetaData()
meta.bind = migrate_engine
# Add 'user_id' column to quota_usages table.
quota_usages = Table('quota_usages', meta, autoload=True)
user_id = Column('user_id',
String(length=255))
quota_usages.create_column(user_id)
# Add 'user_id' column to reservations table.
reservations = Table('reservations', meta, autoload=True)
user_id = Column('user_id',
String(length=255))
reservations.create_column(user_id)
project_user_quotas = Table('project_user_quotas', meta,
Column('id', Integer, primary_key=True,
nullable=False),
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', Integer),
Column('user_id',
String(length=255),
nullable=False),
Column('project_id',
String(length=255),
nullable=False),
Column('resource',
String(length=25),
nullable=False),
Column('hard_limit', Integer, nullable=True),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
try:
project_user_quotas.create()
except Exception:
LOG.exception("Exception while creating table 'project_user_quotas'")
meta.drop_all(tables=[project_user_quotas])
raise
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
quota_usages = Table('quota_usages', meta, autoload=True)
reservations = Table('reservations', meta, autoload=True)
quota_usages.drop_column('user_id')
reservations.drop_column('user_id')
project_user_quotas = Table('project_user_quotas', meta, autoload=True)
try:
project_user_quotas.drop()
except Exception:
LOG.error(_("project_user_quotas table not dropped"))
raise

View File

@ -1,61 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 OpenStack Foundation
#
# 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 Boolean, Column, DateTime, ForeignKey, Integer
from sqlalchemy import MetaData, String, Table
from manila.openstack.common.gettextutils import _
from manila.openstack.common import log as logging
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
shares = Table('shares', meta, autoload=True)
share_metadata = Table('share_metadata', meta,
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', Boolean),
Column('id', Integer, primary_key=True, nullable=False),
Column('share_id', String(length=36), ForeignKey('shares.id'),
nullable=False),
Column('key', String(length=255), nullable=False),
Column('value', String(length=1023), nullable=False),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
try:
share_metadata.create()
except Exception:
LOG.exception("Exception while creating table 'share_metadata'")
meta.drop_all(tables=[share_metadata])
raise
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
share_metadata = Table('share_metadata', meta, autoload=True)
try:
share_metadata.drop()
except Exception:
LOG.error(_("share_metadata table not dropped"))
raise

View File

@ -1,61 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 Mirantis 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 Boolean, Column, DateTime
from sqlalchemy import MetaData, String, Table
from manila.openstack.common.gettextutils import _
from manila.openstack.common import log as logging
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
security_services = Table(
'security_services', meta,
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', Boolean, default=False),
Column('id', String(length=36), primary_key=True, nullable=False),
Column('project_id', String(length=36), nullable=False),
Column('type', String(length=32), nullable=False),
Column('dns_ip', String(length=64), nullable=True),
Column('server', String(length=255), nullable=True),
Column('domain', String(length=255), nullable=True),
Column('sid', String(length=255), nullable=True),
Column('name', String(length=255), nullable=True),
Column('description', String(length=255), nullable=True),
Column('status', String(length=16)),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
try:
security_services.create()
except Exception:
LOG.exception(_("Exception while creating table"))
raise
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
security_services = Table('security_services', meta, autoload=True)
security_services.drop()

View File

@ -1,127 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 Mirantis 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 migrate import ForeignKeyConstraint
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer
from sqlalchemy import MetaData, String, Table, UniqueConstraint
from manila.openstack.common.gettextutils import _
from manila.openstack.common import log as logging
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
shares = Table('shares', meta, autoload=True)
Table('security_services', meta, autoload=True)
share_networks = Table(
'share_networks', meta,
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', Boolean, default=False),
Column('id', String(length=36), primary_key=True,
nullable=False),
Column('project_id', String(length=36), nullable=False),
Column('neutron_net_id', String(length=36), nullable=True),
Column('neutron_subnet_id', String(length=36), nullable=True),
Column('network_type', String(length=32), nullable=True),
Column('segmentation_id', Integer, nullable=True),
Column('cidr', String(length=64), nullable=True),
Column('ip_version', Integer, nullable=True),
Column('name', String(length=255), nullable=True),
Column('description', String(length=255), nullable=True),
Column('status', String(length=32)),
UniqueConstraint('neutron_net_id', 'neutron_subnet_id', 'project_id',
name='net_subnet_uc'),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
allocations = Table(
'network_allocations', meta,
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', Boolean, default=False),
Column('id', String(length=36), primary_key=True, nullable=False),
Column('ip_address', String(length=64), nullable=True),
Column('mac_address', String(length=32), nullable=True),
Column('share_network_id', String(length=36),
ForeignKey('share_networks.id'), nullable=False),
Column('status', String(length=32)),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
association = Table(
'share_network_security_service_association', meta,
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', Boolean, default=False),
Column('id', Integer, primary_key=True, nullable=False),
Column('share_network_id', String(length=36),
ForeignKey('share_networks.id'), nullable=False),
Column('security_service_id', String(length=36),
ForeignKey('security_services.id'), nullable=False),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
tables = [share_networks, allocations, association]
for table in tables:
try:
table.create()
except Exception:
LOG.exception(_("Exception while creating table"))
meta.drop_all(tables=tables)
raise
network_id = Column('share_network_id',
String(length=36),
ForeignKey('share_networks.id'),
nullable=True)
network_id.create(shares)
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
shares = Table('shares', meta, autoload=True)
share_networks = Table('share_networks', meta, autoload=True)
network_allocations = Table('network_allocations', meta, autoload=True)
association = Table('share_network_security_service_association',
meta,
autoload=True)
if migrate_engine.name == 'mysql':
fkeys = list(shares.c.share_network_id.foreign_keys)
params = {'columns': [shares.c['share_network_id']],
'refcolumns': [share_networks.c['id']],
'name': fkeys[0].constraint.name}
with migrate_engine.begin():
fkey = ForeignKeyConstraint(**params)
fkey.drop()
shares.c.share_network_id.drop()
network_allocations.drop()
association.drop()
share_networks.drop()

View File

@ -1,40 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 Mirantis 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, MetaData, String, Table
from manila.openstack.common.gettextutils import _
from manila.openstack.common import log as logging
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
security_services = Table('security_services', meta, autoload=True)
password = Column('password', String(length=255), nullable=True)
password.create(security_services)
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
security_services = Table('security_services', meta, autoload=True)
security_services.c.password.drop()

View File

@ -1,44 +0,0 @@
# Copyright 2013 Mirantis 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 Boolean, Column, DateTime
from sqlalchemy import MetaData, String, Table
from manila.openstack.common.gettextutils import _
from manila.openstack.common import log as logging
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
if migrate_engine.name != "sqlite":
project_user_quotas = Table('project_user_quotas', meta, autoload=True)
new_deleted = Column('new_deleted', Boolean, default=False)
new_deleted.create(project_user_quotas, populate_default=True)
project_user_quotas.update().\
where(project_user_quotas.c.deleted == 1).\
values(new_deleted=True).\
execute()
project_user_quotas.c.deleted.drop()
project_user_quotas.c.new_deleted.alter(name="deleted")
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine

View File

@ -1,216 +0,0 @@
# Copyright 2013 Mirantis 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 CheckConstraint
from sqlalchemy.engine import reflection
from sqlalchemy.ext.compiler import compiles
from sqlalchemy import MetaData, Table, Column, Index
from sqlalchemy import select
from sqlalchemy.sql.expression import UpdateBase
from sqlalchemy import Integer, Boolean
from sqlalchemy.types import NullType, BigInteger
all_tables = ['shares', 'share_snapshots', 'share_networks',
'share_network_security_service_association',
'share_metadata', 'share_access_map', 'services',
'security_services', 'reservations', 'quotas', 'quota_usages',
'project_user_quotas', 'network_allocations', 'migrations',
'quota_classes']
class InsertFromSelect(UpdateBase):
def __init__(self, table, select):
self.table = table
self.select = select
@compiles(InsertFromSelect)
def visit_insert_from_select(element, compiler, **kw):
return "INSERT INTO %s %s" % (
compiler.process(element.table, asfrom=True),
compiler.process(element.select))
def get_default_deleted_value(table):
if isinstance(table.c.id.type, Integer):
return 0
return "False"
def upgrade_enterprise_dbs(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
for table_name in all_tables:
table = Table(table_name, meta, autoload=True)
new_deleted = Column('new_deleted', table.c.id.type,
default=get_default_deleted_value(table))
new_deleted.create(table, populate_default=True)
table.update().\
where(table.c.deleted == True).\
values(new_deleted=table.c.id).\
execute()
table.c.deleted.drop()
table.c.new_deleted.alter(name="deleted")
def upgrade(migrate_engine):
if migrate_engine.name != "sqlite":
return upgrade_enterprise_dbs(migrate_engine)
insp = reflection.Inspector.from_engine(migrate_engine)
meta = MetaData()
meta.bind = migrate_engine
for table_name in all_tables:
table = Table(table_name, meta, autoload=True)
default_deleted_value = get_default_deleted_value(table)
columns = []
for column in table.columns:
column_copy = None
if column.name != "deleted":
# NOTE(boris-42): BigInteger is not supported by sqlite, so
# after copy it will have NullType, other
# types that are used in Nova are supported by
# sqlite.
if isinstance(column.type, NullType):
column_copy = Column(column.name, BigInteger(), default=0)
else:
column_copy = column.copy()
else:
column_copy = Column('deleted', table.c.id.type,
default=default_deleted_value)
columns.append(column_copy)
def is_deleted_column_constraint(constraint):
# NOTE(boris-42): There is no other way to check is CheckConstraint
# associated with deleted column.
if not isinstance(constraint, CheckConstraint):
return False
sqltext = str(constraint.sqltext)
return (sqltext.endswith("deleted in (0, 1)") or
sqltext.endswith("deleted IN (:deleted_1, :deleted_2)"))
constraints = []
for constraint in table.constraints:
if not is_deleted_column_constraint(constraint):
constraints.append(constraint.copy())
new_table = Table(table_name + "__tmp__", meta,
*(columns + constraints))
new_table.create()
indexes = []
for index in insp.get_indexes(table_name):
column_names = [new_table.c[c] for c in index['column_names']]
indexes.append(Index(index["name"],
*column_names,
unique=index["unique"]))
ins = InsertFromSelect(new_table, table.select())
migrate_engine.execute(ins)
table.drop()
[index.create(migrate_engine) for index in indexes]
new_table.rename(table_name)
new_table.update().\
where(new_table.c.deleted == True).\
values(deleted=new_table.c.id).\
execute()
# NOTE(boris-42): Fix value of deleted column: False -> "" or 0.
new_table.update().\
where(new_table.c.deleted == False).\
values(deleted=default_deleted_value).\
execute()
def downgrade_enterprise_dbs(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
for table_name in all_tables:
table = Table(table_name, meta, autoload=True)
old_deleted = Column('old_deleted', Boolean, default=False)
old_deleted.create(table, populate_default=False)
table.update().\
where(table.c.deleted == table.c.id).\
values(old_deleted=True).\
execute()
table.c.deleted.drop()
table.c.old_deleted.alter(name="deleted")
def downgrade(migrate_engine):
if migrate_engine.name != "sqlite":
return downgrade_enterprise_dbs(migrate_engine)
insp = reflection.Inspector.from_engine(migrate_engine)
meta = MetaData()
meta.bind = migrate_engine
for table_name in all_tables:
table = Table(table_name, meta, autoload=True)
columns = []
for column in table.columns:
column_copy = None
if column.name != "deleted":
if isinstance(column.type, NullType):
column_copy = Column(column.name, BigInteger(), default=0)
else:
column_copy = column.copy()
else:
column_copy = Column('deleted', Boolean, default=0)
columns.append(column_copy)
constraints = [constraint.copy() for constraint in table.constraints]
new_table = Table(table_name + "__tmp__", meta,
*(columns + constraints))
new_table.create()
indexes = []
for index in insp.get_indexes(table_name):
column_names = [new_table.c[c] for c in index['column_names']]
indexes.append(Index(index["name"],
*column_names,
unique=index["unique"]))
c_select = []
for c in table.c:
if c.name != "deleted":
c_select.append(c)
else:
c_select.append(table.c.deleted == table.c.id)
ins = InsertFromSelect(new_table, select(c_select))
migrate_engine.execute(ins)
table.drop()
[index.create(migrate_engine) for index in indexes]
new_table.rename(table_name)
new_table.update().\
where(new_table.c.deleted == new_table.c.id).\
values(deleted=True).\
execute()

View File

@ -1,51 +0,0 @@
# Copyright 2013 Mirantis 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 migrate.changeset import UniqueConstraint
from sqlalchemy import MetaData, Table
from manila.db.sqlalchemy import utils
from manila.openstack.common.gettextutils import _
from manila.openstack.common import log as logging
LOG = logging.getLogger(__name__)
UC_NAME = "net_subnet_uc"
OLD_COLUMNS = ('neutron_net_id', 'neutron_subnet_id', 'project_id')
NEW_COLUMNS = ('neutron_net_id', 'neutron_subnet_id', 'project_id', 'deleted')
TABLE_NAME = 'share_networks'
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
utils.drop_unique_constraint(migrate_engine, TABLE_NAME, UC_NAME,
*OLD_COLUMNS)
t = Table(TABLE_NAME, meta, autoload=True)
uc = UniqueConstraint(*NEW_COLUMNS, table=t, name=UC_NAME)
uc.create()
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
utils.drop_unique_constraint(migrate_engine, TABLE_NAME, UC_NAME,
*NEW_COLUMNS)
t = Table(TABLE_NAME, meta, autoload=True)
uc = UniqueConstraint(*OLD_COLUMNS, table=t, name=UC_NAME)
uc.create()

View File

@ -369,43 +369,3 @@ class TestMigrations(test.TestCase):
LOG.error("Failed to migrate to version %s on engine %s" %
(version, engine))
raise
def test_migration_006(self):
"""Test adding share_metadata table works correctly."""
for (key, engine) in self.engines.items():
migration_api.version_control(engine,
TestMigrations.REPOSITORY,
migration.INIT_VERSION)
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 5)
metadata = sqlalchemy.schema.MetaData()
metadata.bind = engine
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 6)
self.assertTrue(engine.dialect.has_table(engine.connect(),
"share_metadata"))
share_metadata = sqlalchemy.Table('share_metadata',
metadata,
autoload=True)
self.assertIsInstance(share_metadata.c.created_at.type,
sqlalchemy.types.DATETIME)
self.assertIsInstance(share_metadata.c.updated_at.type,
sqlalchemy.types.DATETIME)
self.assertIsInstance(share_metadata.c.deleted_at.type,
sqlalchemy.types.DATETIME)
self.assertIsInstance(share_metadata.c.deleted.type,
sqlalchemy.types.BOOLEAN)
self.assertIsInstance(share_metadata.c.id.type,
sqlalchemy.types.INTEGER)
self.assertIsInstance(share_metadata.c.share_id.type,
sqlalchemy.types.VARCHAR)
self.assertIsInstance(share_metadata.c.key.type,
sqlalchemy.types.VARCHAR)
self.assertIsInstance(share_metadata.c.value.type,
sqlalchemy.types.VARCHAR)
migration_api.downgrade(engine, TestMigrations.REPOSITORY, 5)
self.assertFalse(engine.dialect.has_table(engine.connect(),
"share_metadata"))