"""fix recurring override cascade

Revision ID: 6e5b154d917
Revises: 41f957b595fc
Create Date: 2015-05-25 16:23:40.563050

"""

# revision identifiers, used by Alembic.
revision = '6e5b154d917'
down_revision = '4ef055945390'

from alembic import op
import sqlalchemy as sa
from sqlalchemy.sql import text


def upgrade():
    conn = op.get_bind()
    conn.execute(text("set @@lock_wait_timeout = 20;"))
    conn.execute(text("SET FOREIGN_KEY_CHECKS=0;"))
    conn.execute(text("ALTER TABLE recurringeventoverride DROP FOREIGN KEY "
                      "`recurringeventoverride_ibfk_2`"))
    conn.execute(text("ALTER TABLE recurringeventoverride ADD CONSTRAINT recurringeventoverride_ibfk_2"
                      " FOREIGN KEY (`master_event_id`) REFERENCES `event` (`id`) ON DELETE CASCADE"))


def downgrade():
    conn = op.get_bind()
    conn.execute(text("set @@lock_wait_timeout = 20;"))
    conn.execute(text("SET FOREIGN_KEY_CHECKS=0;"))
    conn.execute(text("ALTER TABLE recurringeventoverride DROP FOREIGN KEY "
                      "`recurringeventoverride_ibfk_2`"))
    conn.execute(text("ALTER TABLE recurringeventoverride ADD CONSTRAINT recurringeventoverride_ibfk_2"
                      " FOREIGN KEY (`master_event_id`) REFERENCES `event` (`id`)"))

Fix cascades for RecurringEventOverride table
Fix cascades for RecurringEventOverride table

Summary: We weren't defining an `ON DELETE CASCADE` cascade on the RecurringEventOverride table. This made it impossible to run the account reset script for accounts which had recurring event overrides. Fix this.

Test Plan: Ran the migration, checked that the account reset script worked.

Reviewers: jennie, kav-ya

Projects: #eas

Maniphest Tasks: T1383

Differential Revision: https://phab.nylas.com/D1557
