Skip to main content

Intelligent SQL to NoSQL schema migration - analyzes query patterns to recommend optimal MongoDB/DynamoDB schema design with multi-LLM provider support

Project description

Schema Travels

PyPI version Python 3.10+ License: MIT

Schema Travels analyzes SQL database query patterns and recommends optimal NoSQL schema designs for MongoDB and DynamoDB migrations.

Features

  • 📊 Query Pattern Analysis — Parse PostgreSQL/MySQL logs to detect hot joins, access patterns, and read/write ratios
  • 🤖 Multi-Provider AI — Claude, OpenAI, Gemini, Grok, or local Ollama models
  • 🗃️ DynamoDB Single-Table Design — Algorithmic clustering with Union-Find, automatic PK/SK patterns, GSI optimization
  • 📄 Multiple Output Formats — JSON, Terraform HCL, NoSQL Workbench
  • 🔄 SQL → MongoDB Rewrites — Automatic query rewrite examples
  • 💾 Caching — Reproducible results with hash-based recommendation caching
  • 📈 Migration Simulation — Storage and latency impact estimation

Installation

# Core (includes Claude support)
pip install schema-travels

# With OpenAI support
pip install schema-travels[openai]

# With Google Gemini support
pip install schema-travels[gemini]

# All cloud providers
pip install schema-travels[all-providers]

LLM Providers (v2.3.0)

Provider Default Model API Key Install
Claude claude-sonnet-4-20250514 ANTHROPIC_API_KEY Built-in
OpenAI gpt-4o OPENAI_API_KEY [openai]
Gemini gemini-2.0-flash GOOGLE_API_KEY [gemini]
Grok grok-3 XAI_API_KEY [openai]
Ollama llama3.1:8b None (local) Built-in
# List available providers
schema-travels providers

Quick Start

MongoDB Migration

export ANTHROPIC_API_KEY=sk-ant-...

schema-travels analyze \
    --logs-dir ./postgresql_logs \
    --schema-file ./schema.sql \
    --target mongodb \
    --output results.json

DynamoDB Migration

schema-travels analyze \
    --logs-dir ./postgresql_logs \
    --schema-file ./schema.sql \
    --target dynamodb \
    --dynamodb-output terraform \
    --output results.json

Using Different LLM Providers

# OpenAI GPT-4o
export OPENAI_API_KEY=sk-...
schema-travels analyze --provider openai --logs-dir ./logs --schema-file ./schema.sql

# Google Gemini
export GOOGLE_API_KEY=...
schema-travels analyze --provider gemini --model gemini-2.5-pro ...

# xAI Grok
export XAI_API_KEY=...
schema-travels analyze --provider grok ...

# Local Ollama (free, private)
ollama serve  # Start Ollama server
schema-travels analyze --provider ollama --model llama3.1:70b ...

# Remote Ollama server
schema-travels analyze --provider ollama --model mistral:7b \
    --ollama-host http://192.168.1.100:11434 ...

Environment Variables

# Set default provider (instead of --provider flag)
export SCHEMA_TRAVELS_PROVIDER=openai

# Set default model (instead of --model flag)
export SCHEMA_TRAVELS_MODEL=gpt-4o-mini

# Ollama server URL
export OLLAMA_HOST=http://localhost:11434

How It Works

MongoDB Flow

LLM acts as architect — analyzes your access patterns and designs the schema:

SQL Schema + Query Logs → Pattern Analysis → LLM → EMBED/REFERENCE Decisions → MongoDB Schema

DynamoDB Flow

Local algorithm designs, LLM reviews:

SQL Schema + Query Logs → Pattern Analysis → DynamoDB Designer → LLM Review → Final Design
                                                    │
                                            Union-Find clustering
                                            PK/SK pattern generation
                                            GSI candidate detection

CLI Options

schema-travels analyze [OPTIONS]

Options:
  --logs-dir PATH              Directory with query logs [required]
  --schema-file PATH           SQL schema file [required]
  --target [mongodb|dynamodb]  Target database [default: mongodb]
  --output PATH                Output file
  
  # LLM Provider (v2.3.0)
  --provider [claude|openai|gemini|grok|ollama]  LLM provider
  --model TEXT                 Model to use (overrides provider default)
  --ollama-host TEXT           Ollama server URL
  
  # DynamoDB-specific
  --dynamodb-mode [auto|single|multi]     Design mode [default: auto]
  --dynamodb-output [json|terraform|nosql_workbench]  Output format
  
  # AI control
  --no-ai                      Skip AI (DynamoDB: algorithmic only)
  --no-cache                   Bypass recommendation cache
  --clear-cache                Clear all cached results
  --cache-mode [relaxed|strict]  Cache sensitivity
  
  # Filtering
  --min-confidence FLOAT       Filter by confidence threshold
  --show-rewrites              Show SQL  MongoDB query rewrites

Example Output

MongoDB

{
  "recommendations": [
    {
      "parent_table": "users",
      "child_table": "addresses",
      "decision": "embed",
      "confidence": 0.92,
      "reasoning": "High co-access (87%), bounded cardinality (<10 per user)"
    }
  ],
  "target_schema": {
    "collections": [
      {
        "name": "users",
        "embedded_documents": ["addresses"]
      }
    ]
  }
}

DynamoDB

{
  "target_schema": {
    "metadata": {
      "design_mode": "single_table",
      "confidence": 0.85,
      "dynamodb_design": {
        "table_name": "main_table",
        "partition_key": "PK",
        "sort_key": "SK",
        "entities": [
          {"name": "User", "pk_pattern": "USER#<id>", "sk_pattern": "PROFILE"},
          {"name": "Order", "pk_pattern": "USER#<user_id>", "sk_pattern": "ORDER#<id>"}
        ],
        "gsis": [
          {"name": "GSI1", "pk_attribute": "email", "projection_type": "KEYS_ONLY"}
        ],
        "ai_reviewed": true,
        "ai_review_applied": true
      }
    }
  }
}

Visualization

# Generate HTML visualization
python tools/visualize_schema.py \
    --input results.json \
    --output schema.html

open schema.html

Documentation

Requirements

  • Python 3.10+
  • LLM API key (Claude, OpenAI, Gemini, or Grok) OR local Ollama installation

License

MIT License — see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

schema_travels-2.3.0.tar.gz (116.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

schema_travels-2.3.0-py3-none-any.whl (108.1 kB view details)

Uploaded Python 3

File details

Details for the file schema_travels-2.3.0.tar.gz.

File metadata

  • Download URL: schema_travels-2.3.0.tar.gz
  • Upload date:
  • Size: 116.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for schema_travels-2.3.0.tar.gz
Algorithm Hash digest
SHA256 d16f077aecbec364b4afd975bcf12c5273faf76a7fdc39f24b126ec4b2521e1c
MD5 a71ab4082e8bb1aedbe8e396faf4137e
BLAKE2b-256 56fdb443fe6739bcbd4deedffaee889654c89d7088e77f212af20c7a5d344293

See more details on using hashes here.

File details

Details for the file schema_travels-2.3.0-py3-none-any.whl.

File metadata

  • Download URL: schema_travels-2.3.0-py3-none-any.whl
  • Upload date:
  • Size: 108.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for schema_travels-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e5cbccc1c2ad45990d84cb1bddebd3e8df3feb5691a96bb2ece857d945d3acc
MD5 e7216237f35cfc27834942163c233137
BLAKE2b-256 25f8c76d8e73198cccde08ffa7c5c099ab07d719ef74ab9640e92ad0fee68170

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page