morphsql / PROJECT.md
waghelad's picture
Upload folder using huggingface_hub
12eff8e verified
|
Raw
History Blame Contribute Delete
4.8 kB

A newer version of the Gradio SDK is available: 6.22.0

Upgrade

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

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

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