#!/bin/bash # ============================================================================= # Build Script for pg_morbac Extension # ============================================================================= # Concatenates SQL source files in src/ into a single pg_morbac.sql file # Order: header first, then specific order for dependencies, footer last # ============================================================================= set -e SRC_DIR="src" OUTPUT="pg_morbac.sql" echo "Building pg_morbac.sql from source files..." # Check if src directory exists if [ ! -d "$SRC_DIR" ]; then echo "Error: $SRC_DIR directory not found" exit 1 fi # Remove old output file rm -f "$OUTPUT" # Define build order (dependencies matter) BUILD_ORDER=( "header.sql" "types.sql" "config.sql" "organizations.sql" "roles.sql" "activities.sql" "views.sql" "contexts.sql" "rules.sql" "cross_org_rules.sql" "admin_rules.sql" "audit.sql" "hierarchy_functions.sql" "materialized_views.sql" "validation.sql" "auth_cache.sql" "authorization.sql" "policy_dsl.sql" "rls.sql" "obligations.sql" "admin_helpers.sql" "footer.sql" ) file_count=0 # Build in specified order for filename in "${BUILD_ORDER[@]}"; do filepath="$SRC_DIR/$filename" if [ -f "$filepath" ]; then echo " Adding: $filename" cat "$filepath" >> "$OUTPUT" echo "" >> "$OUTPUT" ((file_count++)) else echo " Warning: $filename not found, skipping" fi done echo "Built $OUTPUT successfully ($file_count source files)"