gendesign/data/sql/99b_grant_quarter_price_index_fdw.sql
bot-backend 76baf8011d feat(db): quarter_price_index FDW foreign table + monthly refresh (Refs #762)
#647-2 (P0, инфра — клиентскую цену НЕ меняет). Делает mv_quarter_price_index
(#760) читаемым estimator'ом за O(1) + периодический refresh.

- tradein 085_quarter_price_index_fdw.sql: FOREIGN TABLE quarter_price_index
  над main public.mv_quarter_price_index через существующий server
  gendesign_remote (паттерн 060_postgres_fdw_extension.sql, per-table). Колонки
  1:1 с MV (varchar(30)/float8/bigint/text/timestamptz). DROP IF EXISTS идемпот.
- main 99b_grant_quarter_price_index_fdw.sql: GRANT SELECT на MV роли
  tradein_fdw_reader (иначе foreign table падает; зеркало 122_grant_rosreestr).
- main refresh: Celery beat (pg_cron нет). quarter_price_index_refresh.py —
  chained REFRESH mv_quarter_price_per_m2 → mv_quarter_price_index CONCURRENTLY;
  task refresh_quarter_price_index.py; beat-entry 'refresh-quarter-price-index'
  cron '0 2 5 * *' (05:00 MSK 5-го, после ekb-districts-medians).

Lookup-индекс: MV уже несёт UNIQUE mv_quarter_price_index_uq (O(1) remote);
foreign table не нуждается в локальном. Валидация (postgres-gendesign): MV
1972 строки, 0 NULL, UNIQUE indisunique=true, REFRESH CONCURRENTLY валиден.

Разблокирует #647-3 (estimator integration, за гейтом #763).
2026-05-30 20:13:02 +03:00

16 lines
733 B
PL/PgSQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 99b_grant_quarter_price_index_fdw.sql
-- Issue #762 (#647-2) — grant SELECT on mv_quarter_price_index to the tradein
-- FDW reader role so the tradein foreign table (085_quarter_price_index_fdw.sql)
-- can read it. Mirrors 122_grant_rosreestr_to_fdw_reader.sql.
--
-- Ordering: '99b_' sorts AFTER '99a_quarter_price_index.sql' (which CREATEs the MV)
-- because 'a' < 'b'. The MV must exist before the GRANT. Files 100_122_ sort
-- BEFORE 99_ lexicographically ('1' < '9'), so they cannot grant on this object.
-- Idempotent: GRANT is repeatable; role tradein_fdw_reader created in
-- 100_tradein_fdw_role.sql (REVOKE ALL baseline there).
BEGIN;
GRANT SELECT ON public.mv_quarter_price_index TO tradein_fdw_reader;
COMMIT;