| # MorphSQL β Project Context Document |
|
|
| > **Purpose:** Give this file to any AI assistant or new developer to continue work without prior conversation context. |
|
|
| ## Naming |
|
|
| | Layer | Name | |
| |-------|------| |
| | **Product (UI, docs, Hugging Face Space title)** | **MorphSQL** | |
| | Python import | `morphsql` | |
| | PyPI package | `morphsql` | |
| | GitHub repo | `morphsql` | |
| | HF Space / model slug | `dgvj-work/morphsql` | |
|
|
| Always use **MorphSQL** / `morphsql` consistently (product, package, CLI, Hub). |
|
|
| ## What this project is |
|
|
| **MorphSQL** is an open-source **SQL migration toolkit** (package import: `morphsql`). |
|
|
| It is **not** only a single-query converter. It analyzes legacy SQL repositories and produces: |
|
|
| 1. **Discovery** β scan zip files/directories for SQL, procedures, views, dbt models |
| 2. **Lineage** β dependency graphs (table/object level) |
| 3. **Risk assessment** β complexity scoring, unsupported syntax, downstream impact |
| 4. **Workload rationalization** β migrate / review / rewrite / retire per object |
| 5. **Hybrid translation** β rule-based + sqlglot dialect conversion (pandas / PySpark / warehouse / dbt) |
| 6. **dbt architecture** β decompose procedures into staging/intermediate/mart |
| 7. **Validation** β reconciliation tests (row count, null rate, checksums) |
| 8. **Migration runbook** β phased cutover plan with object action table |
| 9. **Migration copilot** β LLM advisor grounded in scan context (HF Inference API) |
|
|
| ## Repository layout |
|
|
| ``` |
| morphsql/ |
| βββ app.py # Hugging Face Gradio Space (MorphSQL UI) |
| βββ demo/ |
| β βββ handlers.py # Gradio event handlers |
| β βββ theme.py # Dark theme CSS/constants |
| βββ morphsql/ # Core Python package |
| β βββ scanner/ # Repository discovery |
| β βββ parser/ # SQL parsing (sqlglot) |
| β βββ lineage/ # Dependency graphs (networkx) |
| β βββ translator/ # Hybrid SQL conversion (+ pandas/pyspark codegen) |
| β βββ risk/ # Complexity & risk scoring |
| β βββ dbt_generator/ # dbt project decomposition |
| β βββ validation/ # Reconciliation tests |
| β βββ knowledge/ # Platform behavior differences KB |
| β βββ intelligence/ # Runbook, rationalization, lineage viz |
| β βββ assistant/ # LLM copilot (huggingface_hub) |
| β βββ report/ # HTML report generation |
| β βββ pipeline.py # Agent orchestration |
| β βββ models.py # Pydantic data models |
| β βββ cli.py # `morphsql` CLI |
| βββ examples/vertica_legacy/ # Sample legacy Vertica repository |
| βββ tests/ |
| βββ PROJECT.md # This file |
| βββ README.md |
| βββ README_HF_SPACE.md # HF Space card (title: MorphSQL) |
| βββ MODEL_CARD.md |
| βββ pyproject.toml |
| ``` |
|
|
| ## Architecture |
|
|
| ``` |
| Repository (zip / directory) |
| β |
| MigrationPipeline.analyze() β Discovery + Lineage + Risk |
| β |
| MigrationPipeline.convert() β Hybrid SQL translation |
| β |
| MigrationPipeline.validate() β Reconciliation tests |
| β |
| generate_runbook() β Cutover plan |
| generate_rationalization() β Migrate/retire recommendations |
| decompose_to_dbt() β dbt scaffold |
| MigrationCopilot.respond() β LLM Q&A grounded in report |
| ``` |
|
|
| ## Key modules |
|
|
| | Module | File | Purpose | |
| |--------|------|---------| |
| | Pipeline | `morphsql/pipeline.py` | Orchestrates full workflow | |
| | Translator | `morphsql/translator/engine.py` | ZEROIFNULL, DATEADD, procedure wrappers, sqlglot | |
| | Pandas / PySpark | `morphsql/translator/*_codegen.py` | Notebook / Spark DataFrame codegen | |
| | Copilot | `morphsql/assistant/copilot.py` | HF Inference API + fallback KB | |
| | Runbook | `morphsql/intelligence/runbook.py` | Migration runbook markdown | |
| | Lineage viz | `morphsql/intelligence/lineage_viz.py` | Plotly network graph | |
| | Rationalization | `morphsql/intelligence/rationalization.py` | Workload action plan | |
|
|
| ## CLI commands |
|
|
| ```bash |
| morphsql analyze PATH -s vertica -t snowflake |
| morphsql convert PATH -s snowflake -t pandas |
| morphsql migrate PATH -s vertica -t snowflake -o migration-output |
| morphsql version |
| ``` |
|
|
| ## Hugging Face |
|
|
| - Space title: **MorphSQL** |
| - Space URL: https://huggingface.co/spaces/dgvj-work/morphsql |
| - Deploy: `./scripts/deploy_hf.sh` |
| - Preflight: `python scripts/check_space.py` |
| - Copilot model env: `MORPHSQL_MODEL` |
|
|
| ## Gradio UI tabs |
|
|
| 1. **Convert** β primary: paste/upload SQL β pandas/PySpark/SQL/dbt + preview + download |
| 2. **Guide** β how-to for DS / AI users |
| 3. **More** β object assess, repo workbench, feature SQL, copilot, RAG, eval |
|
|