"""Add a unique constraint on tenant_id and ha_vr_id of l3 ha router

Revision ID: efcfc172aca4
Revises: efcfc171aca4
Create Date: 2014-06-27 18:35:28.148680

"""

revision = 'efcfc172aca4'
down_revision = 'efcfc171aca4'

migration_for_plugins = [
    '*'
]

from alembic import op

from neutron.db import migration


TABLE_NAME = 'routers'
UC_NAME = 'uniq_l3router0tenant_id0ha_vr_id'


def upgrade(active_plugins=None, options=None):
    if not migration.should_run(active_plugins, migration_for_plugins):
        return

    op.create_unique_constraint(
        name=UC_NAME,
        source=TABLE_NAME,
        local_cols=['tenant_id', 'ha_vr_id']
    )


def downgrade(active_plugins=None, options=None):
    if not migration.should_run(active_plugins, migration_for_plugins):
        return

    op.drop_constraint(
        name=UC_NAME,
        table_name=TABLE_NAME,
        type_='unique'
    )
