1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012 OpenStack LLC.
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
# Upgrade operations go here. Don't create your own engine;
26
# bind migrate_engine to your metadata
28
meta.bind = migrate_engine
30
# Add 'user_id' column to quota_usages table.
31
quota_usages = Table('quota_usages', meta, autoload=True)
32
user_id = Column('user_id',
33
String(length=255, convert_unicode=False,
34
assert_unicode=None, unicode_error=None,
35
_warn_on_bytestring=False))
36
quota_usages.create_column(user_id)
38
# Add 'user_id' column to reservations table.
39
reservations = Table('reservations', meta, autoload=True)
40
user_id = Column('user_id',
41
String(length=255, convert_unicode=False,
42
assert_unicode=None, unicode_error=None,
43
_warn_on_bytestring=False))
44
reservations.create_column(user_id)
47
user_quotas = Table('user_quotas', meta,
48
Column('id', Integer(), primary_key=True),
49
Column('created_at', DateTime(timezone=False)),
50
Column('updated_at', DateTime(timezone=False)),
51
Column('deleted_at', DateTime(timezone=False)),
52
Column('deleted', Boolean(), default=False),
54
String(length=255, convert_unicode=False,
55
assert_unicode=None, unicode_error=None,
56
_warn_on_bytestring=False)),
58
String(length=255, convert_unicode=False,
59
assert_unicode=None, unicode_error=None,
60
_warn_on_bytestring=False)),
62
String(length=255, convert_unicode=False,
63
assert_unicode=None, unicode_error=None,
64
_warn_on_bytestring=False),
66
Column('hard_limit', Integer(), nullable=True),
67
mysql_engine='InnoDB',
74
LOG.error(_("Table |%s| not created!"), repr(user_quotas))
78
def downgrade(migrate_engine):
79
# Operations to reverse the above upgrade go here.
81
meta.bind = migrate_engine
83
quota_usages = Table('quota_usages', meta, autoload=True)
84
quota_usages.drop_column('user_id')
86
reservations = Table('reservations', meta, autoload=True)
87
reservations.drop_column('user_id')
89
user_quotas = Table('user_quotas', meta, autoload=True)
93
LOG.error(_("user_quotas table not dropped"))