"""unique_user_org

Revision: 0182
Revision ID: 47ecf6e8811b
Revises: 27a56466f9a7
Create Date: 2020-05-07 15:36:26.299226

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql


# revision identifiers, used by Alembic.
revision = '47ecf6e8811b'
down_revision = '27a56466f9a7'
branch_labels = None
depends_on = None


def upgrade():
    op.execute("""
        CREATE UNIQUE INDEX user_org_id
        ON organizations (created_by_id, is_user_org)
        WHERE name IS NULL AND is_user_org IS TRUE;
    """)


def downgrade():
    op.execute("""DROP INDEX IF EXISTS user_org_id""")
