Merge "db: Use 'import sqlalchemy as sa' pattern"
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -10,7 +10,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from sqlalchemy import MetaData, Table
|
||||
import sqlalchemy as sa
|
||||
|
||||
from cinder import exception
|
||||
from cinder.i18n import _
|
||||
@@ -19,11 +19,11 @@ from cinder.i18n import _
|
||||
def upgrade(migrate_engine):
|
||||
"""Make volume_type columns non-nullable"""
|
||||
|
||||
meta = MetaData(bind=migrate_engine)
|
||||
meta = sa.MetaData(bind=migrate_engine)
|
||||
|
||||
# Update volume_type columns in tables to not allow null value
|
||||
|
||||
volumes = Table('volumes', meta, autoload=True)
|
||||
volumes = sa.Table('volumes', meta, autoload=True)
|
||||
|
||||
try:
|
||||
volumes.c.volume_type_id.alter(nullable=False)
|
||||
@@ -34,7 +34,7 @@ def upgrade(migrate_engine):
|
||||
'There are still untyped volumes unmigrated.'))
|
||||
raise exception.ValidationError(msg)
|
||||
|
||||
snapshots = Table('snapshots', meta, autoload=True)
|
||||
snapshots = sa.Table('snapshots', meta, autoload=True)
|
||||
|
||||
try:
|
||||
snapshots.c.volume_type_id.alter(nullable=False)
|
||||
@@ -45,7 +45,7 @@ def upgrade(migrate_engine):
|
||||
'There are still %(count)i untyped snapshots unmigrated.'))
|
||||
raise exception.ValidationError(msg)
|
||||
|
||||
encryption = Table('encryption', meta, autoload=True)
|
||||
encryption = sa.Table('encryption', meta, autoload=True)
|
||||
# since volume_type is a mandatory arg when creating encryption
|
||||
# volume_type_id column won't contain any null values so we can directly
|
||||
# alter it
|
||||
|
@@ -13,28 +13,33 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from sqlalchemy import Boolean, Column, DateTime
|
||||
from sqlalchemy import MetaData, String, Table, ForeignKey
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta = MetaData()
|
||||
meta = sa.MetaData()
|
||||
meta.bind = migrate_engine
|
||||
|
||||
# This is required to establish foreign key dependency between
|
||||
# volume_type_id and volume_types.id columns. See L#34-35
|
||||
Table('volume_types', meta, autoload=True)
|
||||
sa.Table('volume_types', meta, autoload=True)
|
||||
|
||||
default_volume_types = Table(
|
||||
default_volume_types = sa.Table(
|
||||
'default_volume_types', meta,
|
||||
Column('created_at', DateTime),
|
||||
Column('updated_at', DateTime),
|
||||
Column('deleted_at', DateTime),
|
||||
Column('volume_type_id', String(36),
|
||||
ForeignKey('volume_types.id'), index=True),
|
||||
Column('project_id', String(length=255), primary_key=True,
|
||||
nullable=False),
|
||||
Column('deleted', Boolean(create_constraint=True, name=None)),
|
||||
sa.Column('created_at', sa.DateTime),
|
||||
sa.Column('updated_at', sa.DateTime),
|
||||
sa.Column('deleted_at', sa.DateTime),
|
||||
sa.Column(
|
||||
'volume_type_id',
|
||||
sa.String(36),
|
||||
sa.ForeignKey('volume_types.id'),
|
||||
index=True),
|
||||
sa.Column(
|
||||
'project_id',
|
||||
sa.String(length=255),
|
||||
primary_key=True,
|
||||
nullable=False),
|
||||
sa.Column('deleted', sa.Boolean(create_constraint=True, name=None)),
|
||||
mysql_engine='InnoDB',
|
||||
mysql_charset='utf8'
|
||||
)
|
||||
|
@@ -13,8 +13,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from sqlalchemy import Boolean, Column, MetaData, Table
|
||||
from migrate.changeset import constraint
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
@@ -25,12 +25,13 @@ def upgrade(migrate_engine):
|
||||
"""
|
||||
# There's no need to set the race_preventer field for existing DB entries,
|
||||
# since the race we want to prevent is only on creation.
|
||||
meta = MetaData(bind=migrate_engine)
|
||||
quota_usages = Table('quota_usages', meta, autoload=True)
|
||||
meta = sa.MetaData(bind=migrate_engine)
|
||||
quota_usages = sa.Table('quota_usages', meta, autoload=True)
|
||||
|
||||
if not hasattr(quota_usages.c, 'race_preventer'):
|
||||
quota_usages.create_column(Column('race_preventer', Boolean,
|
||||
nullable=True))
|
||||
quota_usages.create_column(
|
||||
sa.Column('race_preventer', sa.Boolean, nullable=True))
|
||||
|
||||
unique = constraint.UniqueConstraint(
|
||||
'project_id', 'resource', 'race_preventer',
|
||||
table=quota_usages)
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user