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."
}
Metadata
Release files for slm-db-migration 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| slm_db_migration-0.1.0.tar.gz | 3.5 kB | Without provenance | Details for slm_db_migration-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| slm_db_migration-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for slm_db_migration-0.1.0-py3-none-any.whl |
Total release size: 7.4 kB
Release files / slm_db_migration-0.1.0.tar.gz
| Download URL | slm_db_migration-0.1.0.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f1fb7ce73ae37065950d3b47c09d7bdfa5115cd0ad28324ec4e00bd3e82167cb
|
|
BLAKE2b-256 checksum How to use checksums |
8b85f0392519408380dbc8ee7d7166755e4e47f5cf40ffddc973b6793a5bab21
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Release files / slm_db_migration-0.1.0-py3-none-any.whl
| Download URL | slm_db_migration-0.1.0-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0c6fef158f8ad4f398a5bdc75e0d3aaa0391c8b86aaa1be00a696cf70e6e0ece
|
|
BLAKE2b-256 checksum How to use checksums |
c54d2d5c56e645093a28c9039e49078a811bd14d6b7d1bea15ba84ce7e4d22c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Security for slm-db-migration 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.