Adding image_properties migration
This commit is contained in:
parent
757a155ac6
commit
d923a04175
@ -20,7 +20,7 @@ Various conveniences used for migration scripts
|
||||
"""
|
||||
|
||||
import sqlalchemy.types
|
||||
|
||||
from sqlalchemy.schema import MetaData
|
||||
|
||||
String = lambda length: sqlalchemy.types.String(
|
||||
length=length, convert_unicode=False, assert_unicode=None,
|
||||
@ -39,3 +39,6 @@ DateTime = lambda: sqlalchemy.types.DateTime(timezone=False)
|
||||
|
||||
|
||||
Integer = lambda: sqlalchemy.types.Integer()
|
||||
|
||||
|
||||
meta = MetaData()
|
||||
|
@ -16,37 +16,43 @@
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
from sqlalchemy.schema import (MetaData, Table, Column)
|
||||
from sqlalchemy.schema import (Column, MetaData, Table)
|
||||
|
||||
from glance.registry.db.migrate_repo.schema import (String,
|
||||
Boolean,
|
||||
Text,
|
||||
from glance.registry.db.migrate_repo.schema import (Boolean,
|
||||
DateTime,
|
||||
Integer)
|
||||
Integer,
|
||||
String,
|
||||
Text,
|
||||
meta)
|
||||
|
||||
|
||||
meta = MetaData()
|
||||
def define_tables():
|
||||
images = Table('images', meta,
|
||||
Column('id', Integer(), primary_key=True, nullable=False),
|
||||
Column('name', String(255)),
|
||||
Column('type', String(30)),
|
||||
Column('size', Integer()),
|
||||
Column('status', String(30), nullable=False),
|
||||
Column('is_public', Boolean(), nullable=False, default=False),
|
||||
Column('location', Text()),
|
||||
Column('created_at', DateTime(), nullable=False),
|
||||
Column('updated_at', DateTime()),
|
||||
Column('deleted_at', DateTime()),
|
||||
Column('deleted', Boolean(), nullable=False, default=False),
|
||||
mysql_engine='InnoDB')
|
||||
|
||||
|
||||
images = Table('images', meta,
|
||||
Column('id', Integer(), primary_key=True, nullable=False),
|
||||
Column('name', String(255)),
|
||||
Column('type', String(30)),
|
||||
Column('size', Integer()),
|
||||
Column('status', String(30), nullable=False),
|
||||
Column('is_public', Boolean(), nullable=False, default=False),
|
||||
Column('location', Text()),
|
||||
Column('created_at', DateTime(), nullable=False),
|
||||
Column('updated_at', DateTime()),
|
||||
Column('deleted_at', DateTime()),
|
||||
Column('deleted', Boolean(), nullable=False, default=False))
|
||||
return [images]
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta.bind = migrate_engine
|
||||
images.create()
|
||||
tables = define_tables()
|
||||
for table in tables:
|
||||
table.create()
|
||||
|
||||
|
||||
def downgrade(migrate_engine):
|
||||
meta.bind = migrate_engine
|
||||
images.drop()
|
||||
tables = define_tables()
|
||||
for table in reversed(tables):
|
||||
table.drop()
|
||||
|
@ -0,0 +1,57 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2011 OpenStack LLC.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import logging
|
||||
from sqlalchemy.schema import (Column, ForeignKey, MetaData, Table,
|
||||
UniqueConstraint)
|
||||
|
||||
from glance.registry.db.migrate_repo.schema import (Boolean,
|
||||
DateTime,
|
||||
Integer,
|
||||
String,
|
||||
Text,
|
||||
meta)
|
||||
|
||||
|
||||
def define_tables():
|
||||
image_properties = Table('image_properties', meta,
|
||||
Column('id', Integer(), primary_key=True, nullable=False),
|
||||
Column('image_id', Integer(), ForeignKey('images.id'), nullable=False),
|
||||
Column('key', String(255), nullable=False, index=True),
|
||||
Column('value', Text()),
|
||||
Column('created_at', DateTime(), nullable=False),
|
||||
Column('updated_at', DateTime()),
|
||||
Column('deleted_at', DateTime()),
|
||||
Column('deleted', Boolean(), nullable=False, default=False),
|
||||
UniqueConstraint('image_id', 'key'),
|
||||
mysql_engine='InnoDB')
|
||||
|
||||
return [image_properties]
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta.bind = migrate_engine
|
||||
tables = define_tables()
|
||||
for table in tables:
|
||||
table.create()
|
||||
|
||||
|
||||
def downgrade(migrate_engine):
|
||||
meta.bind = migrate_engine
|
||||
tables = define_tables()
|
||||
for table in reversed(tables):
|
||||
table.drop()
|
@ -42,10 +42,11 @@ class ModelBase(object):
|
||||
__protected_attributes__ = set([
|
||||
"created_at", "updated_at", "deleted_at", "deleted"])
|
||||
|
||||
created_at = Column(DateTime, default=datetime.datetime.utcnow)
|
||||
created_at = Column(DateTime, default=datetime.datetime.utcnow,
|
||||
nullable=False)
|
||||
updated_at = Column(DateTime, onupdate=datetime.datetime.utcnow)
|
||||
deleted_at = Column(DateTime)
|
||||
deleted = Column(Boolean, default=False)
|
||||
deleted = Column(Boolean, nullable=False, default=False)
|
||||
|
||||
def save(self, session=None):
|
||||
"""Save this object"""
|
||||
@ -96,8 +97,8 @@ class Image(BASE, ModelBase):
|
||||
name = Column(String(255))
|
||||
type = Column(String(30))
|
||||
size = Column(Integer)
|
||||
status = Column(String(30))
|
||||
is_public = Column(Boolean, default=False)
|
||||
status = Column(String(30), nullable=False)
|
||||
is_public = Column(Boolean, nullable=False, default=False)
|
||||
location = Column(Text)
|
||||
|
||||
@validates('type')
|
||||
@ -123,5 +124,7 @@ class ImageProperty(BASE, ModelBase):
|
||||
image_id = Column(Integer, ForeignKey('images.id'), nullable=False)
|
||||
image = relationship(Image, backref=backref('properties'))
|
||||
|
||||
key = Column(String(255), index=True)
|
||||
# FIXME(sirp): KEY is a reserved word in SQL, might be a good idea to
|
||||
# rename this column
|
||||
key = Column(String(255), index=True, nullable=False)
|
||||
value = Column(Text)
|
||||
|
Loading…
x
Reference in New Issue
Block a user