"""Add support for squashed images

Revision ID: 3b4d3a4461dc
Revises: b1d41e2071b
Create Date: 2014-10-07 14:49:13.105746

"""

# revision identifiers, used by Alembic.
revision = '3b4d3a4461dc'
down_revision = 'b1d41e2071b'

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', name=op.f('pk_imagestoragetransformation'))
    )
    op.create_index('imagestoragetransformation_name', 'imagestoragetransformation', ['name'], unique=True)
    op.bulk_insert(tables.imagestoragetransformation,
    [
        {'id':1, 'name':'squash'},
    ])
    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'], name=op.f('fk_derivedimagestorage_derivative_id_imagestorage')),
    sa.ForeignKeyConstraint(['source_id'], ['imagestorage.id'], name=op.f('fk_derivedimagestorage_source_id_imagestorage')),
    sa.ForeignKeyConstraint(['transformation_id'], ['imagestoragetransformation.id'], name=op.f('fk_dis_transformation_id_ist')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_derivedimagestorage'))
    )
    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)
    ### end Alembic commands ###


def downgrade(tables):
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('derivedimagestorage')
    op.drop_table('imagestoragetransformation')
    ### end Alembic commands ###
