"""accounts.timezone — tenant-local time anchor

Revision ID: 0085
Revises: 0084
Create Date: 2026-08-31

Adds the tenant's IANA timezone (e.g. "America/Toronto", "Asia/Kolkata").

Until now the platform had no tenant timezone at all: the only timezone value
anywhere was a hard-coded "America/Toronto" fallback returned by the public
tenant-config endpoint (src/apps/public/router.py) that nothing ever wrote and
nothing ever consumed. Every scheduled service is stored as a naive wall-clock
pair (service_date DATE + service_time TIME) with no zone attached, so the one
place those were combined into an instant assumed UTC — making the "24 hour"
family reminder fire 4-5 hours off, with the error flipping across DST.

This column is the anchor that makes those wall-clock values resolvable to a
real instant. See src/core/timezone.py for the only sanctioned conversion
helpers; services must not call datetime.combine() or date.today() directly.

Existing rows default to America/Toronto, which matches the fallback that the
public config endpoint has been serving all along — so no tenant's rendered
times change on deploy.

Chains off 0084 (records plot_id active unique index), the current develop head.

Renumbered twice, both times losing a race for the next free number:

  1. Authored as 0081; 0081_notifications landed on develop first, so two
     migrations declared revision "0081". Renumbered to 0082.
  2. 0082 was already taken by 0082_remove_record_archived_status, which had
     merged into develop from another branch. Both then declared revision
     "0082" and chained off 0081, which branched the DAG in two and made
     `alembic upgrade head` fail with "Multiple head revisions are present",
     alongside a "Revision 0082 is present more than once" warning.

Now renumbered to 0085 and re-chained onto 0084 — the tip of the other branch —
restoring a single linear chain rather than a fork. This file is the leaf, so no
other migration's down_revision changes.

The numeric prefix is not authoritative in this repo (several are duplicated);
`down_revision` is. But a duplicated *revision id* is fatal, not cosmetic —
check `alembic heads` before choosing one.

Idempotent (IF NOT EXISTS) so it is safe to re-run, including on a database
already stamped at the old "0082".
"""
from alembic import op

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


def upgrade() -> None:
    op.execute(
        """
        ALTER TABLE accounts
            ADD COLUMN IF NOT EXISTS timezone VARCHAR(64) NOT NULL
            DEFAULT 'America/Toronto'
        """
    )


def downgrade() -> None:
    op.execute("ALTER TABLE accounts DROP COLUMN IF EXISTS timezone")
