1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012 Red Hat, Inc.
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
# not use this file except in compliance with the License. You may obtain
7
# a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations
17
from nova.openstack.common import log as logging
18
from sqlalchemy import Boolean, Column, DateTime, Integer
19
from sqlalchemy import MetaData, String, Table
21
LOG = logging.getLogger(__name__)
24
def upgrade(migrate_engine):
25
# Reverse the previous migration
27
meta.bind = migrate_engine
29
reservations = Table('reservations', meta, autoload=True)
30
d = reservations.delete(reservations.c.deleted == True)
32
reservations.drop_column('user_id')
34
quota_usages = Table('quota_usages', meta, autoload=True)
35
d = quota_usages.delete(quota_usages.c.user_id != None)
37
quota_usages.drop_column('user_id')
39
user_quotas = Table('user_quotas', meta, autoload=True)
43
LOG.error(_("user_quotas table not dropped"))
47
def downgrade(migrate_engine):
48
# Undo the reversal of the previous migration
49
# (data is not preserved)
51
meta.bind = migrate_engine
53
# Add 'user_id' column to quota_usages table.
54
quota_usages = Table('quota_usages', meta, autoload=True)
55
user_id = Column('user_id',
56
String(length=255, convert_unicode=False,
57
assert_unicode=None, unicode_error=None,
58
_warn_on_bytestring=False))
59
quota_usages.create_column(user_id)
61
# Add 'user_id' column to reservations table.
62
reservations = Table('reservations', meta, autoload=True)
63
user_id = Column('user_id',
64
String(length=255, convert_unicode=False,
65
assert_unicode=None, unicode_error=None,
66
_warn_on_bytestring=False))
67
reservations.create_column(user_id)
70
user_quotas = Table('user_quotas', meta,
71
Column('id', Integer(), primary_key=True),
72
Column('created_at', DateTime(timezone=False)),
73
Column('updated_at', DateTime(timezone=False)),
74
Column('deleted_at', DateTime(timezone=False)),
75
Column('deleted', Boolean(), default=False),
77
String(length=255, convert_unicode=False,
78
assert_unicode=None, unicode_error=None,
79
_warn_on_bytestring=False)),
81
String(length=255, convert_unicode=False,
82
assert_unicode=None, unicode_error=None,
83
_warn_on_bytestring=False)),
85
String(length=255, convert_unicode=False,
86
assert_unicode=None, unicode_error=None,
87
_warn_on_bytestring=False),
89
Column('hard_limit', Integer(), nullable=True),
90
mysql_engine='InnoDB',
97
LOG.error(_("Table |%s| not created!"), repr(user_quotas))