#!/bin/bash
# Dua role tetap khusus demonstrasi.
psql -X -d postgres -v ON_ERROR_STOP=1 \
  -c "DROP ROLE IF EXISTS bk_operator" \
  -c "DROP ROLE IF EXISTS bk_pelaporan" \
  -c "CREATE ROLE bk_operator LOGIN" \
  -c "CREATE ROLE bk_pelaporan LOGIN" > /dev/null

# --globals-only: hanya role dan tablespace, tanpa data database sama sekali.
pg_dumpall --globals-only | grep '^CREATE ROLE bk_'

# Varian --clean --if-exists: siap diputar ulang di cluster yang sudah terisi.
pg_dumpall --globals-only --clean --if-exists \
  | grep -E '^(DROP ROLE IF EXISTS|CREATE ROLE) bk_'

# Bersih-bersih role demo.
psql -X -d postgres -c "DROP ROLE bk_operator" -c "DROP ROLE bk_pelaporan" > /dev/null
