-- 61_deferrable_constraints.sql
-- Banking Pattern Pack — PostgreSQL
-- Purpose: Deferrable FKs for circular refs.
-- 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;

-- Deferrable constraints for circular refs (toy example)
CREATE TABLE IF NOT EXISTS bank.node_a (
  id INT PRIMARY KEY,
  b_id INT REFERENCES bank.node_b(id) DEFERRABLE INITIALLY IMMEDIATE
);
CREATE TABLE IF NOT EXISTS bank.node_b (
  id INT PRIMARY KEY,
  a_id INT REFERENCES bank.node_a(id) DEFERRABLE INITIALLY IMMEDIATE
);
-- BEGIN; SET CONSTRAINTS ALL DEFERRED; -- do inserts; COMMIT;
