"""Add placements and locations to the db.

Revision ID: bcdde200a1b
Revises: 201d55b38649
Create Date: 2014-06-18 13:32:42.907922

"""

# revision identifiers, used by Alembic.
revision = 'bcdde200a1b'
down_revision = '201d55b38649'

from alembic import op
import sqlalchemy as sa


def upgrade(tables):
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('imagestoragelocation',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('imagestoragelocation_name', 'imagestoragelocation', ['name'], unique=True)

    op.bulk_insert(tables.imagestoragelocation,
    [
        {'id':1, 'name':'s3_us_east_1'},
        {'id':2, 'name':'s3_eu_west_1'},
        {'id':3, 'name':'s3_ap_southeast_1'},
        {'id':4, 'name':'s3_ap_southeast_2'},
        {'id':5, 'name':'s3_ap_northeast_1'},
        {'id':6, 'name':'s3_sa_east_1'},
        {'id':7, 'name':'local'},
    ])

    op.create_table('imagestorageplacement',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('storage_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['location_id'], ['imagestoragelocation.id'], ),
    sa.ForeignKeyConstraint(['storage_id'], ['imagestorage.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('imagestorageplacement_location_id', 'imagestorageplacement', ['location_id'], unique=False)
    op.create_index('imagestorageplacement_storage_id', 'imagestorageplacement', ['storage_id'], unique=False)
    op.create_index('imagestorageplacement_storage_id_location_id', 'imagestorageplacement', ['storage_id', 'location_id'], unique=True)
    ### end Alembic commands ###


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