F
FasORM
v0.1.0

Step 1: Setup & Migrations

In this step, we will initialize our project structure, set up the database connection, and write Blueprint migration files for users, posts, and comments.

1. Initialize the Project

Terminal
fasorm init

Configure your .env file with your database connection URL:

.env
DB_URL=postgresql+asyncpg://postgres:secret@localhost:5432/blog_db

2. Create Migration Files

Generate migration files using the CLI:

Terminal
fasorm make:migration create_users_table
fasorm make:migration create_posts_table
fasorm make:migration create_comments_table

Users Table Migration

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

def up(table: Blueprint):
    table.id()
    table.string("name", 100)
    table.string("email", 255).unique()
    table.string("password", 255)
    table.timestamps()

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

Posts Table Migration (With Enum & Foreign Key)

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

def up(table: Blueprint):
    table.id()
    table.string("title", 200)
    table.text("body")
    table.enum("status", ["draft", "published", "archived", "in-review"]).default("draft")
    table.big_integer("user_id").foreign_key("users.id", ondelete="CASCADE")
    table.timestamps()

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

Comments Table Migration

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

def up(table: Blueprint):
    table.id()
    table.text("body")
    table.big_integer("post_id").foreign_key("posts.id", ondelete="CASCADE")
    table.big_integer("user_id").foreign_key("users.id", ondelete="CASCADE")
    table.timestamps()

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

3. Execute Migrations

Terminal
fasorm migrate
← Overview Step 2: Models →