refacto: add build and cleanup file structure

This commit is contained in:
2026-02-20 01:32:08 +01:00
parent 6adc62f9ec
commit d80b9f387b
31 changed files with 2234 additions and 2235 deletions
Executable
+66
View File
@@ -0,0 +1,66 @@
#!/bin/bash
# =============================================================================
# Build Script for morbac_pg Extension
# =============================================================================
# Concatenates SQL source files in src/ into a single morbac_pg.sql file
# Order: header first, then specific order for dependencies, footer last
# =============================================================================
set -e
SRC_DIR="src"
OUTPUT="morbac_pg.sql"
echo "Building morbac_pg.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)"
+61
View File
@@ -0,0 +1,61 @@
#!/bin/bash
# Installation script for morbac_pg extension
set -e
echo "=================================="
echo "morbac_pg Extension Installer"
echo "=================================="
echo ""
# Check if running as root or with sudo
if [ "$EUID" -ne 0 ] && [ -z "$SUDO_USER" ]; then
echo "This script needs to copy files to PostgreSQL extension directory."
echo "Please run with sudo or as root."
echo ""
echo "Usage: sudo ./install.sh"
exit 1
fi
# Check if pg_config is available
if ! command -v pg_config &> /dev/null; then
echo "Error: pg_config not found in PATH"
echo "Please install PostgreSQL development packages:"
echo " Ubuntu/Debian: sudo apt-get install postgresql-server-dev-all"
echo " RedHat/CentOS: sudo yum install postgresql-devel"
echo " macOS: brew install postgresql"
exit 1
fi
# Get PostgreSQL extension directory
EXTDIR=$(pg_config --sharedir)/extension
echo "PostgreSQL extension directory: $EXTDIR"
echo ""
# Check if directory exists
if [ ! -d "$EXTDIR" ]; then
echo "Error: Extension directory does not exist: $EXTDIR"
exit 1
fi
# Copy extension files
echo "Installing extension files..."
cp -v morbac_pg.control "$EXTDIR/"
cp -v morbac_pg--1.0.0.sql "$EXTDIR/"
echo ""
echo "=================================="
echo "Installation complete!"
echo "=================================="
echo ""
echo "To use the extension in your database:"
echo ""
echo " psql -d your_database -c 'CREATE EXTENSION morbac_pg;'"
echo ""
echo "To run tests:"
echo ""
echo " make test"
echo ""
echo "For more information, see README.md"
echo ""
Executable
+48
View File
@@ -0,0 +1,48 @@
#!/bin/bash
# =============================================================================
# Test Runner for morbac_pg Extension
# =============================================================================
# Runs all tests in order, loading setup data and executing each test file.
# Usage: ./tools/test.sh [database_name]
# =============================================================================
set -e
# Database name (default: morbac_test)
DB="${1:-morbac_test}"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
TEST_DIR="$PROJECT_DIR/tests"
echo "======================================"
echo "morbac_pg Extension Test Suite"
echo "======================================"
echo "Database: $DB"
echo ""
# Install extension
echo "=== Installing Extension ==="
psql -d "$DB" -f "$PROJECT_DIR/morbac_pg.sql"
# Load common setup
echo ""
echo "=== Loading Test Setup ==="
psql -d "$DB" -f "$TEST_DIR/00_setup.sql"
# Run all test files in order
echo ""
echo "=== Running Tests ==="
for test_file in "$TEST_DIR"/[0-9][0-9]_*.sql; do
if [ -f "$test_file" ]; then
test_name=$(basename "$test_file" .sql)
echo ""
echo "--- Running: $test_name ---"
psql -d "$DB" -f "$test_file"
fi
done
echo ""
echo "======================================"
echo "All Tests Completed"
echo "======================================"