"""repo_owners

Revision ID: 1fd74fb6ef0a
Revises: 89a25650d379
Create Date: 2017-07-16 19:41:54.300374

"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = "1fd74fb6ef0a"
down_revision = "89a25650d379"
branch_labels = ()
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "repository", sa.Column("owner_name", sa.String(length=200), nullable=False)
    )
    op.create_unique_constraint(
        "unq_repo_external_id", "repository", ["provider", "external_id"]
    )
    op.create_unique_constraint("unq_repo_name", "repository", ["owner_name", "name"])
    op.drop_constraint("repository_name_key", "repository", type_="unique")
    op.drop_constraint("repository_url_key", "repository", type_="unique")
    op.drop_constraint("unq_external_id", "repository", type_="unique")


# ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_unique_constraint(
        "unq_external_id", "repository", ["provider", "external_id"]
    )
    op.create_unique_constraint("repository_url_key", "repository", ["url"])
    op.create_unique_constraint("repository_name_key", "repository", ["name"])
    op.drop_constraint("unq_repo_name", "repository", type_="unique")
    op.drop_constraint("unq_repo_external_id", "repository", type_="unique")
    op.drop_column("repository", "owner_name")


# ### end Alembic commands ###
