Database commands
This page lists the commands that run module migrations and seeders.
Shared behaviour
Section titled “Shared behaviour”Every command on this page extends BaseCommand, the package base class of the commands that run one action for each selected module (see Contracts and base classes). The behaviour below applies to all of them. The full description is in Module management commands.
Arguments and options
Section titled “Arguments and options”| Name | Shortcut | Default | Description |
|---|---|---|---|
module (argument) |
none | One or more module names. Optional, variadic. | |
--all |
-a |
false |
Run the action for every module. |
Module selection
Section titled “Module selection”- With names, the command runs the action once per name.
- With
--all(orAllin the prompt), commands with--directionselect enabled modules ordered bypriorityin that direction.module:migrate-refreshhas no--directionoption and selects enabled modules in ascending order. The interactive list shows the same modules. --directionhas no effect on modules given by name. Named modules run regardless of status (module:migrate-refresh Shoprefreshes a disabledShop).- With no module and no interactive input, the command prints
No module given. Pass a module name or --all.and exits with1. - Unknown names print
Module [Nope] does not exist.(orModules [Nope, Typo] do not exist.) and exit with1before any action runs.module:migrate-freshdoes not wipe the database.
Exit status
Section titled “Exit status”An action that fails does not stop the remaining modules. The command exits with 1 if the action failed for at least one module.
Confirmation and prohibition
Section titled “Confirmation and prohibition”module:migrate-fresh, module:migrate-refresh, module:migrate-reset, and module:migrate-rollback implement ConfirmableCommand. They accept --force, ask for confirmation in production, and respect Module::prohibitDestructiveCommands() and per-command prohibit() (for example MigrateFreshCommand::prohibit()). See ConfirmableCommand and Destructive commands.
Migration paths
Section titled “Migration paths”A module migration path is paths.generator.migration.path (default database/migrations) inside the module, or migration.path in module.json. Module commands also include paths registered on Laravel’s migrator inside the module folder.
Module migrations and php artisan migrate
Section titled “Module migrations and php artisan migrate”php artisan migrate runs pending migrations for the application and every enabled module in one pass and one batch. Enabled module folders (paths.generator.migration.path) reach Laravel’s migrator through two deduplicated registrations:
LaravelModulesServiceProvider, whenauto-discover.migrationsistrue(default).ModuleServiceProvider::boot()vialoadMigrationsFrom().
Neither registration reads migration.path from module.json or includes disabled modules. With auto-discover.migrations set to false, php artisan migrate still runs migrations for enabled modules extending ModuleServiceProvider, but skips modules without it (such as --plain modules).
module:migrate calls migrate --path=<module paths> --realpath once per selected module (one batch per module). Unlike php artisan migrate, it supports --all with --direction, disabled modules passed by name, migration.path in module.json, --subpath, and --seed. Setting auto-discover.migrations to false does not affect module:migrate.
For migration workflows, see Run module migrations.
module:migrate
Section titled “module:migrate”Runs the migrations of the given modules through Laravel migrate.
php artisan module:migrate [<module>...] [-d|--direction=DIRECTION] [--database=DATABASE] [--pretend] [--force] [--seed] [--subpath=SUBPATH] [-a|--all]Arguments
| Name | Required | Description |
|---|---|---|
module |
no | Module names. See Shared behaviour. |
Options
| Name | Shortcut | Default | Description |
|---|---|---|---|
--direction |
-d |
asc |
Order of the modules selected with --all. |
--database |
none | Database connection. | |
--pretend |
false |
Dump the SQL queries instead of running them. | |
--force |
false |
Run in production without the Laravel confirmation. | |
--seed |
false |
Run module:seed for the module after its migrations. |
|
--subpath |
none | A directory, a file or a glob pattern, relative to the module migration path. | |
--all |
-a |
false |
Migrate every enabled module. |
Notes
- This command is not confirmable. It passes
--forcetomigrate, which does its own production confirmation. See Module migrations andphp artisan migrate. - For each module the command calls
migrate --path=<module paths> --realpathwith--database,--pretendand--forcewhen given. - A
--subpaththat matches no directory and no file printsMigration subpath [<subpath>] does not exist in module [<name>].and counts as a failure. --seedcallsmodule:seed <module>with--databaseand--force.
php artisan module:migrate Blog --seedmodule:migrate-fresh
Section titled “module:migrate-fresh”Drops all tables of the database, then runs the application migrations and the migrations of the given modules.
php artisan module:migrate-fresh [<module>...] [-d|--direction=DIRECTION] [--database=DATABASE] [--seed] [--pretend] [--drop-views] [--drop-types] [-a|--all] [--force]Arguments
| Name | Required | Description |
|---|---|---|
module |
no | Module names. See Shared behaviour. |
Options
| Name | Shortcut | Default | Description |
|---|---|---|---|
--direction |
-d |
asc |
Order of the modules selected with --all. |
--database |
none | Database connection. | |
--seed |
false |
Run module:seed for each module after its migrations. |
|
--pretend |
false |
Not supported. The command refuses to run. | |
--drop-views |
false |
Drop the views too. | |
--drop-types |
false |
Drop the types too (PostgreSQL only). | |
--all |
-a |
false |
Migrate every enabled module. |
--force |
false |
Skip the production confirmation. |
Notes
--pretendprints--pretend is not supported by module:migrate-fresh: it would still drop all tables.and exits with1before anything runs.- The command is confirmable. See Confirmation and prohibition.
- Execution order:
- Validate module names.
- Confirm in production (unless
--force). - Run
db:wipe(silent, forced). - Run
migrate:install. - Run
migratefor rootdatabase/migrationsand non-module migration paths. - Run
module:migrate --forcefor each selected module.
db:wipedrops every table of the connection, not only the tables of the selected modules. Unselected modules are not migrated again.- The command stops with
1whendb:wipe,migrate:installor the rootmigratefails.
php artisan module:migrate-fresh --all --seed --forcemodule:migrate-refresh
Section titled “module:migrate-refresh”Resets and runs again the migrations of the given modules.
php artisan module:migrate-refresh [<module>...] [--database=DATABASE] [--seed] [-a|--all] [--force]Arguments
| Name | Required | Description |
|---|---|---|
module |
no | Module names. See Shared behaviour. |
Options
| Name | Shortcut | Default | Description |
|---|---|---|---|
--database |
none | Database connection. | |
--seed |
false |
Run module:seed for each module at the end. |
|
--all |
-a |
false |
Refresh every enabled module. |
--force |
false |
Skip the production confirmation. |
Notes
- The command is confirmable. See Confirmation and prohibition.
- It has no
--direction,--pretendor--subpathoption.--allselects the enabled modules in ascending order ofpriority. - For each module the command runs
module:migrate-reset,module:migrateand, with--seed,module:seed, each with--force. It stops the module at the first call that fails.
php artisan module:migrate-refresh Blog --seedmodule:migrate-reset
Section titled “module:migrate-reset”Rolls back every migration of the given modules that ran.
php artisan module:migrate-reset [<module>...] [-d|--direction=DIRECTION] [--database=DATABASE] [--pretend] [--subpath=SUBPATH] [-a|--all] [--force]Arguments
| Name | Required | Description |
|---|---|---|
module |
no | Module names. See Shared behaviour. |
Options
| Name | Shortcut | Default | Description |
|---|---|---|---|
--direction |
-d |
desc |
Order of the modules selected with --all. |
--database |
none | Database connection. | |
--pretend |
false |
Print the SQL queries instead of running them. | |
--subpath |
none | A directory, a file or a glob pattern, relative to the module migration path. | |
--all |
-a |
false |
Reset every enabled module. |
--force |
false |
Skip the production confirmation. |
Notes
- The command is confirmable. See Confirmation and prohibition.
- It prints
Rollback: <migration>for each migration, orNothing to rollback on module <name>. - A
--subpaththat matches nothing prints an error and counts as a failure.
php artisan module:migrate-reset Blog --pretendmodule:migrate-rollback
Section titled “module:migrate-rollback”Rolls back the last batch of migrations of the given modules.
php artisan module:migrate-rollback [<module>...] [-d|--direction=DIRECTION] [--database=DATABASE] [--pretend] [--subpath=SUBPATH] [-a|--all] [--force]Arguments
| Name | Required | Description |
|---|---|---|
module |
no | Module names. See Shared behaviour. |
Options
| Name | Shortcut | Default | Description |
|---|---|---|---|
--direction |
-d |
desc |
Order of the modules selected with --all. |
--database |
none | Database connection. | |
--pretend |
false |
Print the SQL queries instead of running them. | |
--subpath |
none | A directory, a file or a glob pattern, relative to the module migration path. | |
--all |
-a |
false |
Roll back every enabled module. |
--force |
false |
Skip the production confirmation. |
Notes
- The command is confirmable. See Confirmation and prohibition.
- The last batch is the highest batch number among the migrations of the module (and the subpath, when given).
- It prints
Rollback: <migration>for each migration, orNothing to rollback on module <name>.
php artisan module:migrate-rollback Blogmodule:migrate-status
Section titled “module:migrate-status”Shows which migrations of the given modules ran.
php artisan module:migrate-status [<module>...] [-d|--direction=DIRECTION] [--database=DATABASE] [-a|--all]Arguments
| Name | Required | Description |
|---|---|---|
module |
no | Module names. See Shared behaviour. |
Options
| Name | Shortcut | Default | Description |
|---|---|---|---|
--direction |
-d |
asc |
Order of the modules selected with --all. |
--database |
none | Database connection. | |
--all |
-a |
false |
Show migration status for every enabled module. |
Notes
- The command calls Laravel
migrate:status --path=<module paths> --realpathfor each module. - It uses the same paths as
module:migrate,module:migrate-rollbackandmodule:migrate-reset.
php artisan module:migrate-status Blogmodule:seed
Section titled “module:seed”Runs the seeders of the given modules through Laravel db:seed.
php artisan module:seed [<module>...] [-d|--direction=DIRECTION] [--class=CLASS] [--database=DATABASE] [--force] [-a|--all]Arguments
| Name | Required | Description |
|---|---|---|
module |
no | Module names. See Shared behaviour. |
Options
| Name | Shortcut | Default | Description |
|---|---|---|---|
--direction |
-d |
asc |
Order of the modules selected with --all. |
--class |
none | Class name of the root seeder. | |
--database |
none | Database connection. | |
--force |
false |
Pass --force to db:seed. |
|
--all |
-a |
false |
Seed every enabled module. |
Notes
- This command is not confirmable.
db:seeddoes its own production confirmation. - Seeder lookup order for a module:
- Classes listed in
migration.seedsofmodule.json. <modules.namespace>\<Module>\<seeder namespace>\<Module>DatabaseSeeder(where<seeder namespace>comes frompaths.generator.seeder).- The same class name under the last folder of each
scan.pathsentry.
- Classes listed in
- A missing class in
migration.seedsprints a warning and is skipped. A module with no seeder prints a warning and succeeds. - With
--class, the command replaces the short class name of each seeder found with the given class name in the same namespace. - A seeder that throws an exception is reported through the exception handler and counts as a failure.
- Each module starts with
Seeding <Name> Module ......, followed bydb:seedoutput and any warnings. - When every seeder succeeds, the command prints
INFO Module [Blog] seeded.. - On a
db:seedfailure, exception, or cancelled confirmation, the command printsERROR Module [Blog] seeding failed.and exits with1. Remaining modules still run.
php artisan module:seed Blog --class=PostSeeder