"""Add recurrence_rule and recurrence_next_spawn_at to notes."""

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

revision = "0033"
down_revision = "0032"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.add_column("notes", sa.Column("recurrence_rule", JSONB(), nullable=True))
    op.add_column(
        "notes",
        sa.Column("recurrence_next_spawn_at", sa.DateTime(timezone=True), nullable=True),
    )
    op.create_index(
        "ix_notes_recurrence_next_spawn_at",
        "notes",
        ["recurrence_next_spawn_at"],
        postgresql_where=sa.text("recurrence_next_spawn_at IS NOT NULL"),
    )


def downgrade() -> None:
    op.drop_index("ix_notes_recurrence_next_spawn_at", table_name="notes")
    op.drop_column("notes", "recurrence_next_spawn_at")
    op.drop_column("notes", "recurrence_rule")
