"""Remove price observations recorded in the wrong currency.

One store displays US dollars beside the local currency and declares USD in its
microdata. The collector took the dollar figure but labelled it with the store's
local currency, so every price it published was off by the exchange rate. The
collector now reads the declared currency; these rows are not old prices, they
are wrong records of what was observed, and leaving them would corrupt the price
history the tracker will draw from.

Revision ID: c9d0e1f2a3b4
Revises: b8c9d0e1f2a3
"""

from alembic import op

revision = "c9d0e1f2a3b4"
down_revision = "b8c9d0e1f2a3"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.execute(
        """
        DELETE FROM price_observations po
        USING listings l, locations loc
        WHERE po.listing_id = l.id
          AND l.location_id = loc.id
          AND loc.code = 'MEX'
          AND po.currency = 'MXN'
        """
    )


def downgrade() -> None:
    # The deleted rows were never correct; there is nothing to restore.
    pass
