-- 54_refresh_mv_concurrently.sql
-- Banking Pattern Pack — PostgreSQL
-- Purpose: Refresh MV concurrently (with unique index).
-- Context: Retail bank example with customers, accounts, transactions, cards, loans.
-- Date: 2025-08-18
-- Notes:
--   * Safe to read; run on a development DB.
--   * Requires: CREATE privileges; some files may need superuser for extensions.
--   * Search path set to 'bank' schema for clarity.
SET search_path = bank, public;

-- Unique index required for CONCURRENT refreshable MV keys
CREATE UNIQUE INDEX IF NOT EXISTS mv_customer_totals_uidx ON bank.mv_customer_totals (customer_id);
-- REFRESH MATERIALIZED VIEW CONCURRENTLY bank.mv_customer_totals;
