Skip to content

feat(migrations): Enable recursive discovery of migrations in subdirectories #317

@usernane

Description

@usernane

Problem Statement

The CLI migration commands (migrations:run, migrations:fresh, migrations:rollback) discover migrations only from the top-level Database/Migrations/ directory. They do not scan subdirectories.

The underlying SchemaRunner::discoverFromPath() method already supports recursive scanning via a $recursive parameter, but the CLI commands never pass true:

// In RunMigrationsCommandNew, FreshMigrationsCommand, RollbackMigrationsCommand:
$count = $this->runner->discoverFromPath($migrationsPath, $namespace);
// $recursive defaults to false

This means organizing migrations in subdirectories by domain is silently ignored — no warning, no error:

Database/Migrations/
    Master/          ← not discovered
    Sustainability/  ← not discovered
    Lms/             ← not discovered

Proposed Solution

Pass true for the $recursive parameter in all CLI migration commands:

$count = $this->runner->discoverFromPath($migrationsPath, $namespace, true);

This applies to:

  • RunMigrationsCommandNew
  • FreshMigrationsCommand
  • RollbackMigrationsCommand
  • DryRunMigrationsCommand
  • MigrationsStatusCommand

And the same for seeders discovery in those commands.

Alternatives Considered

  • Adding a --recursive CLI flag — but subdirectory organization is a common pattern and should work by default.
  • Keeping migrations flat in one directory — works but doesn't scale for multi-domain projects.

Breaking Change

No

Additional Context

The discoverFromPath method already handles recursive namespace resolution correctly. The only change needed is passing true in the CLI commands. This was discovered while building a multi-domain project with Database/Migrations/Master/ subdirectory — migrations were silently not found until moved to the top-level directory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprove performace or existing feature.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions