-- 65_check_constraints_business_rules.sql
-- Banking Pattern Pack — PostgreSQL
-- Purpose: CHECK constraints for business rules.
-- 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;

-- CHECK business rules: non‑negative balances for savings/checking (simplified)
ALTER TABLE bank.accounts
  ADD CONSTRAINT chk_nonnegative_balance CHECK (
    account_type IN ('checking','savings') AND balance >= 0 OR account_type='loan'
  );
