"""set null ondelete for task_records environment FK

Revision ID: a5b6c7d8e9f0
Revises: c4a3a2f74bfe
Create Date: 2026-05-21 18:55:00.000000

"""
from collections.abc import Sequence

from alembic import op

# revision identifiers, used by Alembic.
revision: str = 'a5b6c7d8e9f0'
down_revision: str | Sequence[str] | None = 'c4a3a2f74bfe'
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    """Upgrade schema."""
    op.drop_constraint(
        'task_records_environment_id_fkey',
        'task_records',
        type_='foreignkey',
    )
    op.create_foreign_key(
        'task_records_environment_id_fkey',
        'task_records',
        'environments',
        ['environment_id'],
        ['id'],
        ondelete='SET NULL',
    )


def downgrade() -> None:
    """Downgrade schema."""
    op.drop_constraint(
        'task_records_environment_id_fkey',
        'task_records',
        type_='foreignkey',
    )
    op.create_foreign_key(
        'task_records_environment_id_fkey',
        'task_records',
        'environments',
        ['environment_id'],
        ['id'],
    )
