1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright (c) 2011 Zadara Storage Inc.
4
# Copyright (c) 2011 OpenStack LLC.
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may
7
# not use this file except in compliance with the License. You may obtain
8
# a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
# License for the specific language governing permissions and limitations
18
from sqlalchemy import Column, DateTime, Integer, MetaData, String, Table
19
from sqlalchemy import Boolean, ForeignKey
21
from nova import log as logging
23
LOG = logging.getLogger(__name__)
26
def upgrade(migrate_engine):
28
meta.bind = migrate_engine
30
volumes = Table('volumes', meta, autoload=True)
35
volume_types = Table('volume_types', meta,
36
Column('created_at', DateTime(timezone=False)),
37
Column('updated_at', DateTime(timezone=False)),
38
Column('deleted_at', DateTime(timezone=False)),
39
Column('deleted', Boolean(create_constraint=True, name=None)),
40
Column('id', Integer(), primary_key=True, nullable=False),
42
String(length=255, convert_unicode=False,
44
unicode_error=None, _warn_on_bytestring=False),
47
volume_type_extra_specs_table = Table('volume_type_extra_specs', meta,
48
Column('created_at', DateTime(timezone=False)),
49
Column('updated_at', DateTime(timezone=False)),
50
Column('deleted_at', DateTime(timezone=False)),
51
Column('deleted', Boolean(create_constraint=True, name=None)),
52
Column('id', Integer(), primary_key=True, nullable=False),
53
Column('volume_type_id',
55
ForeignKey('volume_types.id'),
58
String(length=255, convert_unicode=False,
60
unicode_error=None, _warn_on_bytestring=False)),
62
String(length=255, convert_unicode=False,
64
unicode_error=None, _warn_on_bytestring=False)))
66
volume_metadata_table = Table('volume_metadata', meta,
67
Column('created_at', DateTime(timezone=False)),
68
Column('updated_at', DateTime(timezone=False)),
69
Column('deleted_at', DateTime(timezone=False)),
70
Column('deleted', Boolean(create_constraint=True, name=None)),
71
Column('id', Integer(), primary_key=True, nullable=False),
74
ForeignKey('volumes.id'),
77
String(length=255, convert_unicode=False,
79
unicode_error=None, _warn_on_bytestring=False)),
81
String(length=255, convert_unicode=False,
83
unicode_error=None, _warn_on_bytestring=False)))
85
new_tables = (volume_types,
86
volume_type_extra_specs_table,
87
volume_metadata_table)
89
for table in new_tables:
94
LOG.exception('Exception while creating table')
100
volume_type_id = Column('volume_type_id', Integer(), nullable=True)
101
volumes.create_column(volume_type_id)
104
def downgrade(migrate_engine):
106
meta.bind = migrate_engine
108
volumes = Table('volumes', meta, autoload=True)
110
volumes.drop_column('volume_type_id')
112
volume_types = Table('volume_types', meta, autoload=True)
113
volume_type_extra_specs_table = Table('volume_type_extra_specs',
116
volume_metadata_table = Table('volume_metadata', meta, autoload=True)
118
# table order matters, don't change
119
for table in (volume_type_extra_specs_table,
121
volume_metadata_table):