~ubuntu-cloud-archive/ubuntu/precise/cinder/trunk

« back to all changes in this revision

Viewing changes to cinder/db/sqlalchemy/migrate_repo/versions/003_glance_metadata.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-11-23 08:39:28 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20121123083928-xvzet603cjfj9p1t
Tags: 2013.1~g1-0ubuntu1
* New upstream release.
* debian/patches/avoid_setuptools_git_dependency.patch:
  Avoid git installation. (LP: #1075948) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2012 OpenStack LLC.
 
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 sqlalchemy import Column, DateTime, Text, Boolean
 
18
from sqlalchemy import MetaData, Integer, String, Table, ForeignKey
 
19
 
 
20
from cinder.openstack.common import log as logging
 
21
 
 
22
LOG = logging.getLogger(__name__)
 
23
 
 
24
 
 
25
def upgrade(migrate_engine):
 
26
    meta = MetaData()
 
27
    meta.bind = migrate_engine
 
28
 
 
29
    # Just for the ForeignKey and column creation to succeed, these are not the
 
30
    # actual definitions of tables .
 
31
    #
 
32
    volumes = Table('volumes', meta,
 
33
           Column('id', Integer(), primary_key=True, nullable=False),
 
34
           mysql_engine='InnoDB'
 
35
           )
 
36
    snapshots = Table('snapshots', meta,
 
37
           Column('id', Integer(), primary_key=True, nullable=False),
 
38
           mysql_engine='InnoDB'
 
39
           )
 
40
    # Create new table
 
41
    volume_glance_metadata = Table('volume_glance_metadata', meta,
 
42
            Column('created_at', DateTime(timezone=False)),
 
43
            Column('updated_at', DateTime(timezone=False)),
 
44
            Column('deleted_at', DateTime(timezone=False)),
 
45
            Column('deleted', Boolean(create_constraint=True, name=None)),
 
46
            Column('id', Integer(), primary_key=True, nullable=False),
 
47
            Column('volume_id', String(length=36), ForeignKey('volumes.id')),
 
48
            Column('snapshot_id', String(length=36),
 
49
                   ForeignKey('snapshots.id')),
 
50
            Column('key', String(255)),
 
51
            Column('value', Text),
 
52
            mysql_engine='InnoDB'
 
53
    )
 
54
 
 
55
    try:
 
56
        volume_glance_metadata.create()
 
57
    except Exception:
 
58
        LOG.exception("Exception while creating table "
 
59
                      "'volume_glance_metedata'")
 
60
        meta.drop_all(tables=[volume_glance_metadata])
 
61
        raise
 
62
 
 
63
 
 
64
def downgrade(migrate_engine):
 
65
    meta = MetaData()
 
66
    meta.bind = migrate_engine
 
67
 
 
68
    volume_glance_metadata = Table('volume_glance_metadata',
 
69
                                   meta, autoload=True)
 
70
    try:
 
71
        volume_glance_metadata.drop()
 
72
    except Exception:
 
73
        LOG.error(_("volume_glance_metadata table not dropped"))
 
74
        raise