def define_image_tags_table(meta): # Load the images table so the foreign key can be set up properly schema.Table('images', meta, autoload=True) image_tags = schema.Table('image_tags', meta, schema.Column('id', glance_schema.Integer(), primary_key=True, nullable=False), schema.Column('image_id', glance_schema.String(36), schema.ForeignKey('images.id'), nullable=False), schema.Column('value', glance_schema.String(255), nullable=False), mysql_engine='InnoDB') schema.Index('ix_image_tags_image_id', image_tags.c.image_id) schema.Index('ix_image_tags_image_id_tag_value', image_tags.c.image_id, image_tags.c.value) return image_tags
def upgrade(migrate_engine): meta = sqlalchemy.schema.MetaData(migrate_engine) #NOTE(bcwaldon): load the images table for the ForeignKey below sqlalchemy.Table('images', meta, autoload=True) image_locations_table = sqlalchemy.Table( 'image_locations', meta, sqlalchemy.Column('id', schema.Integer(), primary_key=True, nullable=False), sqlalchemy.Column('image_id', schema.String(36), sqlalchemy.ForeignKey('images.id'), nullable=False, index=True), sqlalchemy.Column('value', schema.Text(), nullable=False), sqlalchemy.Column('created_at', schema.DateTime(), nullable=False), sqlalchemy.Column('updated_at', schema.DateTime()), sqlalchemy.Column('deleted_at', schema.DateTime()), sqlalchemy.Column('deleted', schema.Boolean(), nullable=False, default=False, index=True), ) schema.create_tables([image_locations_table])
def upgrade(migrate_engine): meta = sqlalchemy.schema.MetaData() meta.bind = migrate_engine images_table = sqlalchemy.Table('images', meta, autoload=True) image_locations_table = sqlalchemy.Table('image_locations', meta, autoload=True) # Create 'status' column for image_locations table status = sqlalchemy.Column('status', schema.String(30), server_default='active', nullable=False) status.create(image_locations_table) # Set 'status' column initial value for image_locations table mapping = { 'active': 'active', 'pending_delete': 'pending_delete', 'deleted': 'deleted', 'killed': 'deleted' } for src, dst in six.iteritems(mapping): subq = sqlalchemy.sql.select([images_table.c.id])\ .where(images_table.c.status == src) image_locations_table.update(values={'status': dst})\ .where(image_locations_table.c.image_id.in_(subq))\ .execute()
def define_image_tags_table(meta): # Load the images table so the foreign key can be set up properly schema.Table('images', meta, autoload=True) image_tags = schema.Table('image_tags', meta, schema.Column('id', glance_schema.Integer(), primary_key=True, nullable=False), schema.Column('image_id', glance_schema.String(36), schema.ForeignKey('images.id'), nullable=False), schema.Column('value', glance_schema.String(255), nullable=False), schema.Column('created_at', glance_schema.DateTime(), nullable=False), schema.Column('updated_at', glance_schema.DateTime()), schema.Column('deleted_at', glance_schema.DateTime()), schema.Column('deleted', glance_schema.Boolean(), nullable=False, default=False), mysql_engine='InnoDB', mysql_charset='utf8') schema.Index('ix_image_tags_image_id', image_tags.c.image_id) schema.Index('ix_image_tags_image_id_tag_value', image_tags.c.image_id, image_tags.c.value) return image_tags