Files
HOA_Financial_Platform/db/seed/reseed.sh
olsch01 01502e07bc Implement Phase 2 features: roles, assessment groups, budget import, Kanban
- Add hierarchical roles: SuperUser Admin (is_superadmin flag), Tenant Admin,
  Tenant User with separate /admin route and admin panel
- Add Assessment Groups module for property type-based assessment rates
  (SFHs, Condos, Estate Lots with different regular/special rates)
- Enhance Chart of Accounts: initial balance on create (with journal entry),
  archive/restore accounts, edit all fields including account number & fund type
- Add Budget CSV import with downloadable template and account mapping
- Add Capital Projects Kanban board with drag-and-drop between year columns,
  table/kanban view toggle, and PDF export via browser print
- Update seed data with assessment groups, second test user, superadmin flag
- Create repeatable reseed.sh script for clean database population
- Fix AgingReportPage Mantine v7 Table prop compatibility

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 14:28:46 -05:00

85 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
# ============================================================
# HOA LedgerIQ - Repeatable Seed Data Script
# ============================================================
# Usage: ./db/seed/reseed.sh
#
# This script will:
# 1. Drop the tenant schema (if it exists)
# 2. Remove the test users and organization
# 3. Re-run the full seed SQL to recreate everything fresh
#
# Prerequisites:
# - PostgreSQL container must be running (docker compose up -d postgres)
# - DATABASE_URL or PGHOST/PGUSER etc must be configured
# ============================================================
set -e
# Configuration
DB_HOST="${DB_HOST:-localhost}"
DB_PORT="${DB_PORT:-5432}"
DB_NAME="${DB_NAME:-hoa_platform}"
DB_USER="${DB_USER:-hoa_admin}"
DB_PASS="${DB_PASS:-hoa_secure_pass}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SEED_FILE="$SCRIPT_DIR/seed.sql"
echo "============================================"
echo " HOA LedgerIQ - Reseed Database"
echo "============================================"
echo ""
echo "Host: $DB_HOST:$DB_PORT"
echo "Database: $DB_NAME"
echo ""
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "ERROR: Seed file not found at $SEED_FILE"
exit 1
fi
CLEANUP_SQL=$(cat <<'EOSQL'
DROP SCHEMA IF EXISTS tenant_sunrise_valley CASCADE;
DELETE FROM shared.user_organizations WHERE user_id IN (
SELECT id FROM shared.users WHERE email IN ('admin@sunrisevalley.org', 'viewer@sunrisevalley.org')
);
DELETE FROM shared.users WHERE email IN ('admin@sunrisevalley.org', 'viewer@sunrisevalley.org');
DELETE FROM shared.organizations WHERE schema_name = 'tenant_sunrise_valley';
EOSQL
)
# Check if we can connect directly
export PGPASSWORD="$DB_PASS"
if psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -c "SELECT 1" > /dev/null 2>&1; then
echo "Step 1: Cleaning existing tenant data..."
echo "$CLEANUP_SQL" | psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME"
echo "Step 2: Running seed SQL..."
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -f "$SEED_FILE"
else
# Try via docker
echo "Direct connection failed. Trying via Docker..."
DOCKER_CMD="docker compose exec -T postgres psql -U $DB_USER -d $DB_NAME"
echo "Step 1: Cleaning existing tenant data..."
echo "$CLEANUP_SQL" | $DOCKER_CMD
echo "Step 2: Running seed SQL..."
$DOCKER_CMD < "$SEED_FILE"
fi
echo ""
echo "============================================"
echo " Reseed complete!"
echo "============================================"
echo ""
echo " Test Accounts:"
echo " Admin: admin@sunrisevalley.org / password123"
echo " (SuperAdmin + President role)"
echo ""
echo " Viewer: viewer@sunrisevalley.org / password123"
echo " (Homeowner role)"
echo "============================================"