"""cleanup_duplicate_user_orgs

Revision: 0108
Revision ID: 7583b4a2428
Revises: 3b7c458d8852
Create Date: 2017-11-14 13:41:45.249608

"""

# revision identifiers, used by Alembic.
revision = '7583b4a2428'
down_revision = '3b7c458d8852'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa


def upgrade():
    op.execute("""
        DELETE FROM organizations WHERE
            is_user_org AND
            id != (select user_org_id from users where users.id = organizations.created_by_id)
    """)


def downgrade():
    pass
