# vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright 2011 OpenStack LLC.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from sqlalchemy import Column, Integer, MetaData, String, Table

from nova import utils


meta = MetaData()

instances = Table("instances", meta,
        Column("id", Integer(), primary_key=True, nullable=False))
config_drive_column = Column("config_drive", String(255)) # matches image_ref


def upgrade(migrate_engine):
    meta.bind = migrate_engine
    instances.create_column(config_drive_column)

    rows = migrate_engine.execute(instances.select())
    for row in rows:
        instance_config_drive = None # pre-existing instances don't have one.
        migrate_engine.execute(instances.update()\
                .where(instances.c.id == row[0])\
                .values(config_drive=instance_config_drive))


def downgrade(migrate_engine):
    meta.bind = migrate_engine
    instances.drop_column(config_drive_column)

@@ -857,16 +857,52 @@
 =False))
+%0A%0A# matches the size of an image_ref
 %0Aconfig_
@@ -954,29 +954,24 @@
 255)
-) # matches image_ref
+, nullable=True)
 %0A%0A%0Ad
@@ -1083,324 +1083,8 @@
 n)%0A%0A
-    rows = migrate_engine.execute(instances.select())%0A    for row in rows:%0A        instance_config_drive = None # pre-existing instances don't have one.%0A        migrate_engine.execute(instances.update()%5C%0A                .where(instances.c.id == row%5B0%5D)%5C%0A                .values(config_drive=instance_config_drive))%0A%0A
 %0Adef

Fix config_drive migration, per Matt Dietz.