central/tests/test_migration_042.py
malice 4bbe7d61a6 v0.14.5: migration 042 re-asserts central ownership of config.monitoring_areas
During the v0.14.0 prod deploy (2026-06-12) migration 042 was applied as
`sudo -u postgres`, leaving config.monitoring_areas + its SERIAL sequence owned
by postgres while the `central` app role expects ownership-based access. We
patched prod inline at the time with ALTER ... OWNER TO central, but the
migration FILE was never updated -- so a fresh install (dev clone, eventual prod
rebuild) would hit the same footgun.

Append two idempotent ALTERs (table + sequence OWNER TO central) so 042 is
self-healing. No-op when already central-owned. No new fields/event-types/
behavior, no migration re-apply, nothing to deploy (live prod table is already
central-owned via the earlier inline fix).

Test: test_grants_table_and_sequence_ownership_to_central asserts both ALTERs
are present (whitespace-insensitive, matching the existing static checks).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-15 18:09:33 -06:00

47 lines
1.8 KiB
Python

"""v0.14.0 migration 042: single config.system bbox -> config.monitoring_areas.
The suite has no live Postgres (it runs identically as zvx or central), so this
asserts the migration's shape statically: it creates the table, enforces the
union-filter invariants, seeds 'default' from the existing config.system bbox to
preserve current bounds, and -- deliberately for v0.14.0 -- does NOT drop the old
columns (that lands in v0.14.1).
"""
from pathlib import Path
_SQL = Path("sql/migrations/042_monitoring_area_to_multi_areas.sql").read_text()
_NORM = " ".join(_SQL.split()) # whitespace-insensitive matching
def test_creates_monitoring_areas_table():
assert "CREATE TABLE IF NOT EXISTS config.monitoring_areas" in _NORM
def test_name_is_unique():
assert "name TEXT NOT NULL UNIQUE" in _NORM
def test_check_constraints_enforce_bbox_ordering():
assert "CHECK (north > south)" in _NORM
assert "CHECK (east > west)" in _NORM
def test_seeds_default_from_config_system_preserving_bounds():
assert "INSERT INTO config.monitoring_areas" in _NORM
assert "FROM config.system" in _NORM
assert "'default'" in _NORM
# Idempotent re-run / already-seeded installs must not error or duplicate.
assert "ON CONFLICT (name) DO NOTHING" in _NORM
def test_does_not_drop_old_columns_in_v0_14_0():
upper = _NORM.upper()
assert "DROP COLUMN" not in upper
assert "DROP TABLE" not in upper
def test_grants_table_and_sequence_ownership_to_central():
# v0.14.5: applied-as-postgres left the table/sequence postgres-owned; the
# file now re-asserts central ownership so fresh installs are self-healing.
assert "ALTER TABLE config.monitoring_areas OWNER TO central" in _NORM
assert "ALTER SEQUENCE config.monitoring_areas_id_seq OWNER TO central" in _NORM