SLM Database Migrator
Analyzes legacy database schemas and generates zero-downtime, CPU-optimized migrations and modern ORM model definitions offline.
🚀 Overview & Capabilities
Analyzes legacy database schemas and generates zero-downtime, CPU-optimized migrations and modern ORM model definitions offline.
Key Features
- Direct SQL table schema analysis and dependency mapping
- Automatic compatibility matching for migrations
- Generates modern SQLAlchemy and Django ORM models
- Suggests structural indexing plans for performance improvement
💻 Installation
Install the local CPU-optimized package using pip:
# Install local CPU-optimized package
pip install slm-db-migration
🐙 Checkout from GitHub
Clone only this agent's folder from the monorepo using Git sparse-checkout — no need to download the full repository:
Option 1 — Sparse Checkout (Recommended)
Option 2 — Full Repository Clone
💡 Tip: After checkout, install the package locally with pip install -e ./slm_db_migration to run in editable mode without publishing to PyPI.
⚙️ Configuration API
Constructor Parameters
Instantiate SLMDBMigrator with performance options:
| Parameter | Type / Default | Description |
|---|---|---|
| model_path | str | None | Explicit path to ONNX model weights. If omitted, downloads standard checkpoints. |
| cache_dir | str | None | Directory to store model weights offline. Defaults to ~/.cache/slm-db-migration/. Also settable via SLM_DATABASE_MIGRATOR_CACHE_DIR. |
| n_threads | int | 4 | CPU thread count for ONNX inference. Optimize for CPU core count. Also settable via SLM_DATABASE_MIGRATOR_N_THREADS. |
Methods
| Method Signature | Return Type | Description |
|---|---|---|
generate_migration(from_schema, to_schema, system_prompt=None, user_input=None) | str | Compares two SQL schemas and outputs ALTER TABLE SQL migration commands. |
Method Parameters (Execution Customization)
All main execution methods accept optional system routing parameters:
| Parameter | Type / Default | Description |
|---|---|---|
| system_prompt | str | None | Optional custom system prompt instruction to override the default system template response parameters. |
| user_input | str | None | Optional additional user-supplied target text variables or contextual keys. |
Quick Start
from slm_db_migration import SLMDBMigrator
migrator = SLMDBMigrator()
migration_sql = migrator.generate_migration(
from_schema=from_schema,
to_schema=to_schema,
system_prompt="Strict zero-downtime rules",
user_input="Postgres compatibility"
)
print(migration_sql)
Environment Variables
Configure agent parameters globally using environment values:
| Environment Variable | Default | Purpose |
|---|---|---|
| SLM_DATABASE_MIGRATOR_N_THREADS | 4 | Sets CPU inference execution threads. |
| SLM_DATABASE_MIGRATOR_CACHE_DIR | ~/.cache/slm-db-migration/ | Default directory to store downloaded ONNX weights. |
CPU Performance Tuning
To run the SLMDBMigrator engine efficiently on CPU under 1.5 GB memory footprint:
- Match Threads to Core Count: Set
n_threadsorSLM_DATABASE_MIGRATOR_N_THREADSto match the physical CPU core count. - Sequential Processing: Avoid concurrent processing when batch files are large.
- Garbage Collection: Clear variables and run
gc.collect()to release model RAM blocks after execution.
Verified Input & Output Logs
Diagnostic execution console response running locally on CPU:
→ INPUT (To-Schema):
CREATE TABLE users (id INT PRIMARY KEY, name TEXT, email TEXT);
← OUTPUT:
{
'migration_sql': 'ALTER TABLE users ADD COLUMN email TEXT;',
'sandbox_result': 'Migration verified successfully in SQLite sandbox.'
}