"""flag_card_template_sub_cards

Revision: 0241
Revision ID: 6372d988531f
Revises: 130b5c21c344
Create Date: 2022-06-07 19:15:53.636735

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


# revision identifiers, used by Alembic.
revision = '6372d988531f'
down_revision = '130b5c21c344'
branch_labels = None
depends_on = None


def upgrade():
    op.execute("""
        WITH template_cards AS (
            SELECT *
            FROM cards AS c
            WHERE c.is_template = True
        )
        UPDATE cards AS c
        SET is_template = True
        FROM template_cards AS tc WHERE tc.id = ANY (c.parents_ids)
    """)


def downgrade():
    pass
