"""sales: add plot_id to contact_inquiries

Revision ID: 0086
Revises: 0085
Create Date: 2026-09-01

A plot-availability inquiry (POST /plot-inquiries) already knew which plot
was inquired about — it denormalized plot_number/section_name/listed_price
onto the ContactInquiry row and flipped the Plot to `hold` — but never kept
the actual plot_id FK. That made the linkage impossible to follow back once
the inquiry was converted to an Opportunity (Opportunity.plot_id was left
NULL), so the "Plot Selection" step of composing a proposal had no way to
know which plot the family had actually asked about, and it never showed up
there since it lists vacant plots only and this plot is on hold.

Mirrors the existing Opportunity.plot_id / Proposal.plot_id FK pattern
(ON DELETE SET NULL — a deleted plot never cascades into deleting the
inquiry/sales history).
"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

revision = "0086"
down_revision = "0085"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.add_column(
        "contact_inquiries",
        sa.Column(
            "plot_id",
            postgresql.UUID(as_uuid=True),
            sa.ForeignKey("plots.id", ondelete="SET NULL"),
            nullable=True,
        ),
    )
    op.create_index("ix_contact_inquiries_plot_id", "contact_inquiries", ["plot_id"])


def downgrade() -> None:
    op.drop_index("ix_contact_inquiries_plot_id", table_name="contact_inquiries")
    op.drop_column("contact_inquiries", "plot_id")
