package mantra.sql.orm
Migration
CLASS
public class
Schema migration versioning system and fluent SchemaBuilder DDL generator for database backends. NEW in v0.2.0.
🏗️ Constructor Summary
Constructor Signature
def __init__(self, version: Int, name: String, up_sql: String, down_sql: String)
⚙️ Method Summary
| Modifier & Return Type | Method Signature | Description |
|---|---|---|
SchemaBuilder |
static def create_table(table: String) |
Starts fluent schema builder for generating CREATE TABLE statements. |
SchemaBuilder |
pub def column(def: ColumnDef) |
Appends a typed column definition to the schema specification. |
String |
pub def build_ddl() |
Compiles column specifications into database CREATE TABLE DDL SQL. |
MigrationRunner |
pub def register(m: Migration) |
Registers a migration instance into the execution runner. |
List |
pub def run_all(adapter: DatabaseAdapter) |
Executes all pending migrations in order against the target database adapter. |
🔍 Detailed Method Specifications
static def create_table(table: String) -> SchemaBuilder
Starts fluent schema builder for generating CREATE TABLE statements.
pub def column(def: ColumnDef) -> SchemaBuilder
Appends a typed column definition to the schema specification.
pub def build_ddl() -> String
Compiles column specifications into database CREATE TABLE DDL SQL.
pub def register(m: Migration) -> MigrationRunner
Registers a migration instance into the execution runner.
pub def run_all(adapter: DatabaseAdapter) -> List
Executes all pending migrations in order against the target database
adapter.
💡 Example Usage
migration_example.mantra
let ddl = SchemaBuilder.create_table("users")
.column(ColumnDef("id", "INTEGER").primary().auto_inc().not_null())
.column(ColumnDef("name", "TEXT").not_null())
.column(ColumnDef("email", "TEXT").not_null())
.build_ddl()
print(ddl)