Add migration for synthetic image tables

This commit is contained in:
Joseph Schorr 2014-09-22 14:38:42 -04:00
parent 70e0aba257
commit f16878cce9

View file

@ -0,0 +1,57 @@
"""add support for squashing images
Revision ID: 3f6d26399bd2
Revises: 34fd69f63809
Create Date: 2014-09-22 14:37:30.821785
"""
# revision identifiers, used by Alembic.
revision = '3f6d26399bd2'
down_revision = '34fd69f63809'
from alembic import op
import sqlalchemy as sa
def upgrade(tables):
### commands auto generated by Alembic - please adjust! ###
op.create_table('imagestoragetransformation',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index('imagestoragetransformation_name', 'imagestoragetransformation', ['name'], unique=True)
op.create_table('derivedimagestorage',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('source_id', sa.Integer(), nullable=True),
sa.Column('derivative_id', sa.Integer(), nullable=False),
sa.Column('transformation_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['derivative_id'], ['imagestorage.id'], ),
sa.ForeignKeyConstraint(['source_id'], ['imagestorage.id'], ),
sa.ForeignKeyConstraint(['transformation_id'], ['imagestoragetransformation.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index('derivedimagestorage_derivative_id', 'derivedimagestorage', ['derivative_id'], unique=False)
op.create_index('derivedimagestorage_source_id', 'derivedimagestorage', ['source_id'], unique=False)
op.create_index('derivedimagestorage_source_id_transformation_id', 'derivedimagestorage', ['source_id', 'transformation_id'], unique=True)
op.create_index('derivedimagestorage_transformation_id', 'derivedimagestorage', ['transformation_id'], unique=False)
op.drop_index('image_repository_id_docker_image_id', table_name='image')
op.create_index('image_repository_id_docker_image_id', 'image', ['repository_id', 'docker_image_id'], unique=True)
op.add_column(u'imagestorage', sa.Column('uncompressed_size', sa.BigInteger(), nullable=True))
### end Alembic commands ###
def downgrade(tables):
### commands auto generated by Alembic - please adjust! ###
op.drop_column(u'imagestorage', 'uncompressed_size')
op.drop_index('image_repository_id_docker_image_id', table_name='image')
op.create_index('image_repository_id_docker_image_id', 'image', ['repository_id', 'docker_image_id'], unique=False)
op.drop_index('derivedimagestorage_transformation_id', table_name='derivedimagestorage')
op.drop_index('derivedimagestorage_source_id_transformation_id', table_name='derivedimagestorage')
op.drop_index('derivedimagestorage_source_id', table_name='derivedimagestorage')
op.drop_index('derivedimagestorage_derivative_id', table_name='derivedimagestorage')
op.drop_table('derivedimagestorage')
op.drop_index('imagestoragetransformation_name', table_name='imagestoragetransformation')
op.drop_table('imagestoragetransformation')
### end Alembic commands ###