Commands

Commands

This guide is the reference for every Ace command Lucid ships with. Commands fall into four families: make:* for scaffolding files, migration:* for applying and rolling back schema changes, db:* for managing the database lifecycle and its data, and schema:* for working with the generated database/schema.ts file and schema dumps.

Every command accepts the flags documented below alongside AdonisJS's standard command flags (like --help).

make:migration

Creates a new migration file inside database/migrations with a timestamped filename.

terminal
node ace make:migration posts --create=posts

name (argument)

Name of the migration file. Lucid prefixes the file with a timestamp automatically.

--connection, -c <name>

Select the database connection the migration belongs to. The file is created inside that connection's first configured migration path.

--folder <path>

Select the migration directory when the connection has multiple migration paths configured.

--create <table>

Scaffold a migration that creates the given table. This is the default action.

--alter <table>

Scaffold a migration that alters the given table instead of creating one.

--contents-from <path>

Use the contents of the given file as the generated migration source, bypassing the default template.

--force, -f

Overwrite the file if it already exists.

make:model

Creates a new Lucid model file inside app/models. The generated class extends the schema class for the corresponding table by default.

terminal
node ace make:model Post

name (argument)

Name of the model class. Lucid converts it to snake_case for the filename.

--migration

Generate a matching migration file alongside the model.

--controller

Generate a matching resourceful controller for the model.

--transformer

Generate a matching transformer file for the model.

--factory

Generate a matching factory file for the model.

--contents-from <path>

Use the contents of the given file as the generated model source.

--force

Overwrite the file if it already exists.

make:factory

Creates a new model factory inside database/factories.

terminal
node ace make:factory Post

model (argument)

Name of the model the factory produces. Lucid imports the model into the factory file.

--contents-from <path>

Use the contents of the given file as the generated factory source.

--force, -f

Overwrite the file if it already exists.

make:seeder

Creates a new seeder file inside database/seeders.

terminal
node ace make:seeder User

name (argument)

Name of the seeder class. The filename is derived from this name.

--contents-from <path>

Use the contents of the given file as the generated seeder source.

--force, -f

Overwrite the file if it already exists.

migration:run

Applies every pending migration in order, records each one in the adonis_schema table, and regenerates database/schema.ts when finished.

terminal
node ace migration:run
❯ migrated database/migrations/1720000000000_create_posts_table
❯ migrated database/migrations/1720000000001_create_comments_table
Migrated in 42 ms

--connection, -c <name>

Run migrations for the given connection instead of the default.

--force

Explicitly allow the command to run in production. Migration commands refuse to run in production unless this flag is present.

--dry-run

Print the SQL that would run without executing it. Useful for reviewing generated SQL in code review.

--compact-output

Emit a single-line summary instead of per-file progress lines.

--disable-locks

Skip the advisory lock that serializes concurrent migration runs. Only disable when you are certain no other process is migrating the same database.

--schema-path <path>

Load a schema dump file before running pending migrations. Used to bootstrap a fresh database from a schema dump without replaying the entire migration history. See the schema dumps guide.

--no-schema-generate

Skip regenerating database/schema.ts after the migrations apply. Default is to regenerate.

migration:rollback

Reverts the most recent batch of migrations. Pass --step to roll back a specific number of files, or --batch to roll back to a specific batch number.

terminal
node ace migration:rollback
node ace migration:rollback --step=2
node ace migration:rollback --batch=0

--connection, -c <name>

Roll back migrations on the given connection.

--force

Explicitly allow the command to run in production.

--dry-run

Print the SQL that would run without executing it.

--batch <number>

Roll back to the given batch number. Pass 0 to roll back every migration.

--step <number>

Roll back the given number of migration files regardless of batch.

--compact-output

Emit a single-line summary instead of per-file progress lines.

--disable-locks

Skip the advisory lock that serializes concurrent migration runs.

--no-schema-generate

Skip regenerating database/schema.ts after the rollback. Default is to regenerate.

migration:refresh

Rolls back every migration, then re-runs all migrations from scratch. Optionally runs seeders after the refresh when --seed is provided.

terminal
node ace migration:refresh
node ace migration:refresh --seed

--connection, -c <name>

Refresh migrations on the given connection.

--force

Explicitly allow the command to run in production.

--dry-run

Print the SQL that would run without executing it.

--seed

Run database seeders after the refresh completes.

--compact-output

Emit a single-line summary instead of per-file progress lines.

--disable-locks

Skip the advisory lock that serializes concurrent migration runs.

--no-schema-generate

Skip regenerating database/schema.ts after the refresh. Default is to regenerate.

migration:reset

Rolls back every migration without re-running them. Leaves the database with an empty migration history.

terminal
node ace migration:reset

--connection, -c <name>

Reset migrations on the given connection.

--force

Explicitly allow the command to run in production.

--dry-run

Print the SQL that would run without executing it.

--compact-output

Emit a single-line summary instead of per-file progress lines.

--disable-locks

Skip the advisory lock that serializes concurrent migration runs.

--no-schema-generate

Skip regenerating database/schema.ts after reset. Default is to regenerate.

migration:fresh

Drops every table in the database (plus views, types, and domains when flagged) and re-runs all migrations from scratch. Functionally similar to migration:refresh, but skips the rollback path in favor of dropping everything directly.

terminal
node ace migration:fresh
node ace migration:fresh --seed

--connection, -c <name>

Run on the given connection.

--force

Explicitly allow the command to run in production.

--seed

Run database seeders after migrations complete.

--drop-views

Drop all views before running migrations.

--drop-types

Drop all custom PostgreSQL types before running migrations. PostgreSQL only.

--drop-domains

Drop all PostgreSQL domains before running migrations. PostgreSQL only.

--disable-locks

Skip the advisory lock that serializes concurrent migration runs.

--schema-path <path>

Load a schema dump file before dropping and recreating the database. See the schema dumps guide.

migration:status

Lists every migration file and its status (pending, completed, or errored), grouped by batch.

terminal
node ace migration:status
┌───────────────────────────────────────────────┬───────────┬───────┬─────────┐
│ Name │ Status │ Batch │ Message │
├───────────────────────────────────────────────┼───────────┼───────┼─────────┤
│ 1720000000000_create_posts_table │ completed │ 1 │ │
│ 1720000000001_create_comments_table │ completed │ 1 │ │
│ 1720000000002_add_published_at_to_posts_table │ pending │ │ │
└───────────────────────────────────────────────┴───────────┴───────┴─────────┘

--connection, -c <name>

List status for the given connection.

db:create

Creates the database of the given connection when it does not exist yet. The command is a no-op when the database already exists, which makes it safe to run in bootstrap scripts and CI pipelines before migration:run.

Since the target database may not exist, Lucid does not use the regular connection. Instead, it connects to the maintenance database of the dialect (postgres on PostgreSQL, dev on Redshift, master on MSSQL, no database on MySQL) to issue the CREATE DATABASE statement. On SQLite and libSQL, the database file is created alongside any missing parent directories.

terminal
node ace db:create
❯ Created database "blog"

--connection, -c <name>

Create the database of the given connection instead of the default.

The database user must have the privilege to create databases (a global privilege on MySQL). The command is not supported on OracleDB.

db:drop

Drops the database of the given connection. Unlike db:wipe, which drops the tables inside the database, db:drop deletes the database itself. On SQLite and libSQL, the database file is removed from the disk.

In production, the command asks for confirmation unless the --force flag is provided.

terminal
node ace db:drop

--connection, -c <name>

Drop the database of the given connection instead of the default.

--force

Explicitly allow the command to run in production, skipping the confirmation prompt.

db:seed

Runs every seeder inside database/seeders. Pass --files to run a specific subset, or --interactive to pick seeders interactively.

terminal
node ace db:seed
node ace db:seed --interactive
node ace db:seed --files=./database/seeders/user_seeder.ts

--connection, -c <name>

Run seeders against the given connection.

--interactive, -i

Select seeders to run interactively instead of running every file.

--files <paths...>

Run only the listed seeder files. Pass the flag multiple times or use a comma-separated list.

--compact-output

Emit a single-line summary instead of per-seeder progress lines.

db:wipe

Drops every table in the database, along with optionally all views, custom types, and domains. Combine with migration:run or use migration:fresh when you want to rebuild.

terminal
node ace db:wipe

--connection, -c <name>

Target the given connection.

--drop-views

Drop all views.

--drop-types

Drop all custom PostgreSQL types. PostgreSQL only.

--drop-domains

Drop all PostgreSQL domains. PostgreSQL only.

--force

Explicitly allow the command to run in production.

Tables listed in wipe.ignoreTables inside your connection config are preserved. See the configuration guide.

db:truncate

Truncates every table in the database, preserving schema. Useful when you want to reset data between tests or dev runs without dropping tables.

terminal
node ace db:truncate

--connection, -c <name>

Target the given connection.

--force

Explicitly allow the command to run in production.

schema:dump

Writes the current database schema to a single SQL file, alongside a sidecar JSON manifest. The dump is used by migration:run --schema-path and migration:fresh --schema-path to bootstrap a database without replaying the full migration history, which is useful for applications with long migration histories. See the schema dumps guide for the end-to-end workflow.

terminal
node ace schema:dump
node ace schema:dump --path=./database/schema.sql

--connection, -c <name>

Dump the schema for the given connection.

--path <path>

Write the dump to a custom location. Defaults to database/schema/{connection}-schema.sql.

--prune

Delete every migration file from the configured migration paths after dumping. Use this when collapsing a long migration history into a single schema dump. See squashing a long migration history.

schema:generate

Regenerates database/schema.ts by introspecting the database. Migration commands run this automatically when they finish, so this command is mainly useful when adopting a legacy database for the first time or after manual schema changes.

terminal
node ace schema:generate
❯ Generated database/schema.ts

--connection, -c <name>

Generate schema classes from the given connection.

--compact-output

Emit a single-line summary instead of detailed progress.