fix: filter Exception output from DDL generation to prevent corrupting schema SQL

This commit is contained in:
yumoqing 2026-04-29 14:34:51 +08:00
parent b0de930324
commit d5c0fcb1cd

View File

@ -77,18 +77,27 @@ for module in rbac customer_management opportunity_management contract_managemen
MOD_DIR="$PKGS_DIR/$module"
if [ -d "$MOD_DIR/models" ]; then
cd "$MOD_DIR/models"
# Generate DDL to a temp file, filter out exception/error lines
TEMP_DDL=$(mktemp)
if ls *.xlsx >/dev/null 2>&1; then
xls2ddl mysql . > "$MOD_DIR/mysql.ddl.sql" 2>/dev/null || true
xls2ddl mysql . > "$TEMP_DDL" 2>/dev/null || true
elif ls *.json >/dev/null 2>&1; then
json2ddl mysql . > "$MOD_DIR/mysql.ddl.sql" 2>/dev/null || true
json2ddl mysql . > "$TEMP_DDL" 2>/dev/null || true
fi
if [ -f "$MOD_DIR/mysql.ddl.sql" ] && [ -s "$MOD_DIR/mysql.ddl.sql" ]; then
# Filter: only keep lines that look like valid SQL (CREATE TABLE, CREATE INDEX, comments, blank lines, semicolons)
if [ -f "$TEMP_DDL" ] && [ -s "$TEMP_DDL" ]; then
grep -v "^Exception:" "$TEMP_DDL" > "$MOD_DIR/mysql.ddl.sql" 2>/dev/null || true
if [ -s "$MOD_DIR/mysql.ddl.sql" ]; then
echo "-- Module: $module" >> "$APP_DIR/integrated_crm_app_schema.sql"
cat "$MOD_DIR/mysql.ddl.sql" >> "$APP_DIR/integrated_crm_app_schema.sql"
echo "" >> "$APP_DIR/integrated_crm_app_schema.sql"
echo " Generated DDL for $module"
else
echo " WARNING: No valid DDL generated for $module"
fi
fi
rm -f "$TEMP_DDL"
fi
done
cd "$APP_DIR"