"""Add SnapshotImage

Revision ID: 30c86cc72856
Revises: 17d61d9621cb
Create Date: 2014-08-13 16:24:07.482438

"""

# revision identifiers, used by Alembic.
revision = '30c86cc72856'
down_revision = '17d61d9621cb'

from alembic import op
import sqlalchemy as sa


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'snapshot_image',
        sa.Column('id', sa.GUID(), nullable=False),
        sa.Column('snapshot_id', sa.GUID(), nullable=False),
        sa.Column('plan_id', sa.GUID(), nullable=False),
        sa.Column('job_id', sa.GUID(), nullable=True, unique=True),
        sa.Column('date_created', sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(['job_id'], ['job.id'], ondelete='CASCADE'),
        sa.ForeignKeyConstraint(['plan_id'], ['plan.id'], ondelete='CASCADE'),
        sa.ForeignKeyConstraint(['snapshot_id'], ['snapshot.id'], ondelete='CASCADE'),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('snapshot_id', 'plan_id', name='unq_snapshotimage_plan')
    )

    op.create_unique_constraint(None, 'snapshot', ['build_id'])


def downgrade():
    op.drop_constraint(None, 'snapshot')
    op.drop_table('snapshot_image')
