data-table includes a first-class migration system with schema builders, runner controls, and dry-run planning.
Setup
Create a migrations directory and runner script:- Keep migration files in one directory (e.g.,
app/db/migrations) - Name each file as
YYYYMMDDHHmmss_name.ts(or.js,.mjs,.cjs,.cts) - Each file must
defaultexportcreateMigration(...) idandnameare inferred from the filename
Migration File
Migration Context
Theup and down handlers receive a context object:
Runner Script
Custom Journal Table
By default, migrations are tracked in a table nameddata_table_migrations. Customize this:
Running Migrations
Step-based Migration
Apply or revert a specific number of migrations:to and step are mutually exclusive.
Dry Run
Compile and inspect SQL without applying:Schema API
Theschema object provides DDL operations:
Create Table
Alter Table
Rename Table
Drop Table
Create Index
Drop Index
Rename Index
Foreign Keys
Check Constraints
Raw SQL in Migrations
Schema Introspection
Run defensive checks inside migrations:dryRun mode, introspection methods check the live database state, not the pending plan.
Constraint Naming
Constraint and index names are optional. When omitted,data-table generates deterministic names:
Transaction Mode
Control migration transaction behavior:'auto'(default) - Use transactions when adapter supports them'required'- Fail if adapter doesn’t support transactions'none'- Never use transactions
Non-Filesystem Runtimes
For environments without filesystem access, register migrations manually:Migration Status
Check migration status:'applied'- Migration has been applied'pending'- Migration has not been applied'drifted'- Migration checksum doesn’t match (file changed after applying)