Skip to content

Migrations

Oxide wraps sea-orm-migration with a Laravel-style DSL. Migrations live under src/database/migrations/ and are applied via oxide migrate.

Generate a migration

Terminal window
oxide make:migration create_todos_table

Creates src/database/migrations/m<timestamp>_create_todos_table.rs and wires it into the Migrator.

Schema DSL

use oxide_db::migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
Schema::create(manager, "todos", |t| {
t.id();
t.string("title");
t.boolean("done").default(false);
t.text("notes").null();
t.timestamps();
})
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
Schema::drop_if_exists(manager, "todos").await
}
}

Common column helpers

DSLSQL
t.id()id BIGINT PRIMARY KEY AUTO_INCREMENT (signed)
t.string("x")VARCHAR(255) NOT NULL
t.string_len("x", 64)VARCHAR(64) NOT NULL
t.text("x")TEXT NOT NULL
t.boolean("x")BOOLEAN NOT NULL
t.timestamp("x")TIMESTAMP NOT NULL
t.big_integer("x")BIGINT NOT NULL
t.timestamps()created_at + updated_at (both nullable TIMESTAMP)
t.morphs("tokenable")tokenable_type VARCHAR + tokenable_id BIGINT
t.remember_token()remember_token VARCHAR(100) NULL

Chain modifiers:

t.string("email").unique_key(); // UNIQUE INDEX
t.string("nickname").null(); // NULL allowed
t.integer("score").default(0); // DEFAULT clause

Running migrations

Terminal window
oxide migrate # apply pending
oxide migrate:rollback [N] # undo last N (default 1)
oxide migrate:fresh # drop all tables + re-apply (DEV ONLY)
oxide migrate:status # applied / pending table

The tracking table is named migrations (not seaql_migrations).

Publishing framework migrations

Packages may ship migrations for consumers to publish. For example, oxide-auth ships the personal_access_tokens table:

Terminal window
oxide vendor:publish sanctum
oxide migrate

vendor:publish copies the stub into your project’s migrations folder with a fresh timestamp. The published file is now owned by your project and may be edited freely.