File size: 3,410 Bytes
12eff8e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | #!/usr/bin/env bash
# MorphSQL β Local setup, test, and run script
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
echo "π MorphSQL β Local Setup"
echo "=========================================="
echo ""
# 1. Create virtual environment
if [ ! -d ".venv" ]; then
echo "π¦ Creating virtual environment..."
python3 -m venv .venv
fi
source .venv/bin/activate
# 2. Install package with all extras
echo "π¦ Installing dependencies..."
pip install -q -e ".[dev,demo]"
# 3. Run tests
echo ""
echo "π§ͺ Running tests..."
pytest tests/ -v --tb=short
# 4. Run CLI smoke test
echo ""
echo "π Running CLI analyze on example repo..."
morphsql analyze examples/vertica_legacy --source vertica --target snowflake --output ./migration-output
# 5. Run full migration pipeline
echo ""
echo "π Running full migration pipeline..."
morphsql migrate examples/vertica_legacy --source vertica --target snowflake --output ./migration-output
# 6. Verify outputs
echo ""
echo "β
Verifying outputs..."
test -f ./migration-output/migration_report.html && echo " β HTML report generated"
test -d ./migration-output/dbt && echo " β dbt projects generated"
DBT_COUNT=$(find ./migration-output/dbt -name "dbt_project.yml" | wc -l | tr -d ' ')
echo " β $DBT_COUNT dbt projects created"
# 7. Test app + handler surfaces
echo ""
echo "π Testing Gradio handlers..."
python -c "
from pathlib import Path
import pandas as pd
from demo.handlers import (
convert_for_ui,
analyze_sql_object,
get_sample_workbench,
run_feature_migration,
run_behavior_rag,
)
from app import _build_demo
# Simple SELECT β must produce a live sample preview DataFrame
simple = 'SELECT ZEROIFNULL(amount) AS amt FROM staging.orders WHERE id = 1'
notes, output, status, share, preview, path, nb, api = convert_for_ui(simple, 'vertica', 'pandas')
assert output.strip() and 'pandas' in output.lower()
assert isinstance(preview, pd.DataFrame) and not preview.empty
# Procedure β conversion must succeed (preview may be empty for procedural SQL)
proc = Path('examples/vertica_legacy/procedures/SP_BUILD_CUSTOMER_DAILY.sql').read_text()
notes2, output2, *_ = convert_for_ui(proc, 'vertica', 'pandas')
assert output2.strip()
analysis, fig, badge, out, notes3 = analyze_sql_object(proc, 'vertica', 'snowflake')
assert out.strip() and badge
wb = get_sample_workbench()
assert len(wb) == 12
md, feat = run_feature_migration('snowflake')
assert feat.strip()
rag = run_behavior_rag('ZEROIFNULL', 'vertica', 'snowflake')
assert 'ZEROIFNULL' in rag.upper() or len(rag) > 20
assert _build_demo() is not None
print(' β Convert, preview, assess, workbench, features, RAG, Gradio build OK')
"
echo ""
echo "=========================================="
echo "β
All checks passed! Ready to test."
echo ""
echo "Next steps:"
echo " 1. Launch the Gradio demo:"
echo " python app.py"
echo ""
echo " 2. Or use the CLI:"
echo " morphsql analyze examples/vertica_legacy --source vertica --target snowflake"
echo " morphsql convert examples/vertica_legacy/queries/customer_lifetime_value.sql --source vertica --target pandas -o migration-output/pandas"
echo " morphsql migrate examples/vertica_legacy --source vertica --target snowflake --output migration-output"
echo ""
echo " 3. Open the HTML report:"
echo " open migration-output/migration_report.html"
echo ""
|