SLM Database Migrator
A lightweight, local CPU-optimized Database Schema Migrator and ORM Generator. It allows developers to diff SQL schemas, generate database migrations, produce SQLAlchemy/SQLModel classes, and verify safety inside an isolated SQLite memory sandbox.
Features
- Schema Diffing & Migration SQL: Generates exact DDL migration queries (e.g.
ALTER TABLE,CREATE INDEX) to reconcile schemas. - ORM Declarative Mapping: Auto-generates SQLAlchemy/SQLModel classes representing the target database schema.
- SQLite Sandbox Verification: Runs generated DDL statements inside an in-memory sandboxed database connection to catch syntax errors or constraint violations before applying.
- 100% Offline & Local: Relies on local structural matching and offline verification loops.
Installation
pip install -e ./slm_db_migration
API Reference
SLMDBMigrator
from slm_db_migration import SLMDBMigrator
migrator = SLMDBMigrator()
generate_migration(from_schema_sql: str, to_schema_sql: str) -> dict
Generates migration SQL, SQLAlchemy classes, and validates execution inside a sandbox database.
- Arguments:
from_schema_sql(str): DDL for the source schema.to_schema_sql(str): DDL for the target schema.
- Returns:
dict:{ "success": True/False, "migration_sql": str, # Generated DDL Migration statements "sqlalchemy_code": str, # SQLAlchemy model classes "sandbox_result": str # Status message from SQLite sandbox verification }
Usage Example
from slm_db_migration import SLMDBMigrator
migrator = SLMDBMigrator()
source_ddl = "CREATE TABLE users (id INT PRIMARY KEY, name TEXT);"
target_ddl = "CREATE TABLE users (id INT PRIMARY KEY, name TEXT, email TEXT);"
result = migrator.generate_migration(source_ddl, target_ddl)
print(f"Success: {result['success']}")
print(f"Migration DDL:\n{result['migration_sql']}")
print(f"SQLAlchemy Models:\n{result['sqlalchemy_code']}")
print(f"Sandbox Verification: {result['sandbox_result']}")
Input & Output Example
Input (Source Schema):
CREATE TABLE users (id INT PRIMARY KEY, name TEXT);
Input (Target Schema):
CREATE TABLE users (id INT PRIMARY KEY, name TEXT, email TEXT);
Output:
{
"success": true,
"migration_sql": "ALTER TABLE users ADD COLUMN email TEXT;",
"sqlalchemy_code": "from sqlalchemy import Column, Integer, String\nfrom sqlalchemy.orm import declarative_base\n...\nclass User(Base):\n __tablename__ = 'users'\n id = Column(Integer, primary_key=True)\n name = Column(String)\n email = Column(String)",
"sandbox_result": "Migration verified successfully in SQLite sandbox."
}
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file slm_db_migration-0.1.0.tar.gz.
File metadata
- Download URL: slm_db_migration-0.1.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1fb7ce73ae37065950d3b47c09d7bdfa5115cd0ad28324ec4e00bd3e82167cb
|
|
| MD5 |
a1dc94519b58680061db106a5fc7f0ee
|
|
| BLAKE2b-256 |
8b85f0392519408380dbc8ee7d7166755e4e47f5cf40ffddc973b6793a5bab21
|
File details
Details for the file slm_db_migration-0.1.0-py3-none-any.whl.
File metadata
- Download URL: slm_db_migration-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c6fef158f8ad4f398a5bdc75e0d3aaa0391c8b86aaa1be00a696cf70e6e0ece
|
|
| MD5 |
6aae812044d8bc2add7ba557380db517
|
|
| BLAKE2b-256 |
c54d2d5c56e645093a28c9039e49078a811bd14d6b7d1bea15ba84ce7e4d22c7
|