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
oxide make:migration create_todos_tableCreates 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
| DSL | SQL |
|---|---|
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 INDEXt.string("nickname").null(); // NULL allowedt.integer("score").default(0); // DEFAULT clauseRunning migrations
oxide migrate # apply pendingoxide migrate:rollback [N] # undo last N (default 1)oxide migrate:fresh # drop all tables + re-apply (DEV ONLY)oxide migrate:status # applied / pending tableThe 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:
oxide vendor:publish sanctumoxide migratevendor: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.