~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to nova/db/sqlalchemy/migrate_repo/versions/116_drop_user_quotas_key_and_value.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 14:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20120816140411-0mr4n241wmk30t9l
Tags: upstream-2012.2~f3
ImportĀ upstreamĀ versionĀ 2012.2~f3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2012 Red Hat, Inc.
 
4
#
 
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
 
8
#
 
9
#         http://www.apache.org/licenses/LICENSE-2.0
 
10
#
 
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
 
15
#    under the License.
 
16
 
 
17
from nova.openstack.common import log as logging
 
18
from sqlalchemy import Boolean, Column, DateTime, Integer
 
19
from sqlalchemy import MetaData, String, Table
 
20
 
 
21
LOG = logging.getLogger(__name__)
 
22
 
 
23
 
 
24
def upgrade(migrate_engine):
 
25
    # Reverse the previous migration
 
26
    meta = MetaData()
 
27
    meta.bind = migrate_engine
 
28
 
 
29
    reservations = Table('reservations', meta, autoload=True)
 
30
    d = reservations.delete(reservations.c.deleted == True)
 
31
    d.execute()
 
32
    reservations.drop_column('user_id')
 
33
 
 
34
    quota_usages = Table('quota_usages', meta, autoload=True)
 
35
    d = quota_usages.delete(quota_usages.c.user_id != None)
 
36
    d.execute()
 
37
    quota_usages.drop_column('user_id')
 
38
 
 
39
    user_quotas = Table('user_quotas', meta, autoload=True)
 
40
    try:
 
41
        user_quotas.drop()
 
42
    except Exception:
 
43
        LOG.error(_("user_quotas table not dropped"))
 
44
        raise
 
45
 
 
46
 
 
47
def downgrade(migrate_engine):
 
48
    # Undo the reversal of the previous migration
 
49
    # (data is not preserved)
 
50
    meta = MetaData()
 
51
    meta.bind = migrate_engine
 
52
 
 
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)
 
60
 
 
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)
 
68
 
 
69
    # New table.
 
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),
 
76
                        Column('user_id',
 
77
                               String(length=255, convert_unicode=False,
 
78
                                      assert_unicode=None, unicode_error=None,
 
79
                                      _warn_on_bytestring=False)),
 
80
                        Column('project_id',
 
81
                               String(length=255, convert_unicode=False,
 
82
                                      assert_unicode=None, unicode_error=None,
 
83
                                      _warn_on_bytestring=False)),
 
84
                        Column('resource',
 
85
                               String(length=255, convert_unicode=False,
 
86
                                      assert_unicode=None, unicode_error=None,
 
87
                                      _warn_on_bytestring=False),
 
88
                               nullable=False),
 
89
                        Column('hard_limit', Integer(), nullable=True),
 
90
                        mysql_engine='InnoDB',
 
91
                        mysql_charset='utf8',
 
92
                        )
 
93
 
 
94
    try:
 
95
        user_quotas.create()
 
96
    except Exception:
 
97
        LOG.error(_("Table |%s| not created!"), repr(user_quotas))
 
98
        raise