F
FasORM
v0.1.0

Schema Builder & Migrations

FasORM provides a clean Blueprint schema builder for database migration files, powered by Alembic under the hood.

Migration File Anatomy

Migration files located in app/migrations/ define an up(table: Blueprint) function (and optional down(table: Blueprint)):

app/migrations/2026_07_25_143000_create_posts_table.py
from fasorm.schema import Blueprint

def up(table: Blueprint):
    table.id()
    table.string("title", 200)
    table.text("body")
    table.big_integer("user_id").foreign_key("users.id", ondelete="CASCADE")
    table.boolean("is_published").default(False)
    table.timestamps()

def down(table: Blueprint):
    table.drop()

Blueprint Column Methods

Method SQL Column Definition Example Usage
table.id() Auto-increment Primary Key table.id("custom_id")
table.string(name, length=255) VARCHAR(length) table.string("email").unique()
table.text(name) TEXT table.text("description")
table.integer(name), table.big_integer(name) INTEGER / BIGINT table.big_integer("views").default(0)
table.boolean(name) BOOLEAN table.boolean("is_active").default(True)
table.decimal(name, precision, scale) NUMERIC(p, s) table.decimal("price", 10, 2)
table.timestamps(), table.timestamps_tz() created_at & updated_at table.timestamps()
table.soft_deletes(), table.soft_deletes_tz() deleted_at TIMESTAMP NULL table.soft_deletes()
table.jsonb(name), table.uuid(name), table.ulid(name) JSONB / UUID / ULID table.jsonb("settings")
table.foreign_uuid(name), table.foreign_ulid(name) Foreign Key UUID / ULID table.foreign_uuid("user_id")

Foreign Keys with Referential Actions

Chain .foreign_key() onto a column definition to specify reference tables and referential actions (ondelete and onupdate):

Python
# CASCADE delete when target user is deleted
table.big_integer("user_id").foreign_key(
    "users.id",
    ondelete="CASCADE",
    onupdate="CASCADE"
)

# SET NULL when parent category is deleted
table.big_integer("category_id").nullable().foreign_key(
    "categories.id",
    ondelete="SET NULL"
)