#!/bin/bash # Sage_datamart module build script # Generates DDL from models and links wwwroot to Sage set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Find Sage root SAGE_ROOT="" for candidate in "$SCRIPT_DIR/../.." "$HOME/repos/sage" "$HOME/sage"; do if [ -d "$candidate/wwwroot" ] && [ -d "$candidate/py3/bin" ]; then SAGE_ROOT="$(cd "$candidate" && pwd)" break fi done if [ -z "$SAGE_ROOT" ]; then echo "ERROR: Sage root not found" exit 1 fi echo "Sage root: $SAGE_ROOT" # Generate DDL from models if present if [ -d "$SCRIPT_DIR/models" ]; then echo "Generating DDL from models..." cd "$SCRIPT_DIR/models" if ls *.json 1>/dev/null 2>&1; then "$SAGE_ROOT/py3/bin/json2ddl" mysql . > mysql.ddl.sql echo "DDL generated: models/mysql.ddl.sql" fi fi # Link wwwroot to Sage echo "Linking wwwroot to Sage..." rm -f "$SAGE_ROOT/wwwroot/sage_datamart" ln -sf "$SCRIPT_DIR/wwwroot" "$SAGE_ROOT/wwwroot/sage_datamart" echo "[sage_datamart] build done"