Skip to content

[12.x] Improve db:seed command output formatting and add database connection name with -v option #56315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 12.x
Choose a base branch
from

Conversation

amirhshokri
Copy link
Contributor

@amirhshokri amirhshokri commented Jul 16, 2025

This PR continues the work started in #56310, improving php artisan db:seed command output when using seeders, and adds the ability to show the database connection name next to each seeder when the -v flag is provided.

Problem

When running php artisan db:seed command, if DatabaseSeeder.php calls multiple seeders using $this->call(), the output becomes difficult to follow. Specifically, the RUNNING and DONE lines from seeders appear in the middle of the Database\Seeders\DatabaseSeeder progress line:

Example (current behavior):

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        $this->call([
            TestSeeder::class,
            TestSeeder2::class,
        ]);
    }
}
INFO  Seeding database.

  Database\Seeders\DatabaseSeeder   Database\Seeders\TestSeeder .......................................................... RUNNING
  Database\Seeders\TestSeeder .......................................................... 0 ms DONE
  Database\Seeders\TestSeeder2 .......................................................... RUNNING
  Database\Seeders\TestSeeder2 .......................................................... 0 ms DONE
.................................................................................................. 3.12ms DONE

Solution

  • Adjust SeedCommand.php so that output lines for seeders are clearly separated.
  • Ensure each seeder's RUNNING and DONE messages wrap its own execution.
  • Add display of the database connection name next to the seeder class when running with -v mode.

Example (improved behavior):

INFO  Seeding database.

  Database\Seeders\DatabaseSeeder .................................................................. RUNNING

  Database\Seeders\TestSeeder ...................................................................... RUNNING
  Database\Seeders\TestSeeder ...................................................................... 0 ms DONE

  Database\Seeders\TestSeeder2 ..................................................................... RUNNING
  Database\Seeders\TestSeeder2 ..................................................................... 0 ms DONE

  Database\Seeders\DatabaseSeeder .................................................................. 5 ms DONE

With -v flag:

INFO  Seeding database.

  Database\Seeders\DatabaseSeeder mysql ............................................................ RUNNING

  Database\Seeders\TestSeeder ...................................................................... RUNNING
  Database\Seeders\TestSeeder ...................................................................... 0 ms DONE

  Database\Seeders\TestSeeder2 ..................................................................... RUNNING
  Database\Seeders\TestSeeder2 ..................................................................... 0 ms DONE

  Database\Seeders\DatabaseSeeder mysql .......................................................... 4 ms DONE

Benefits:

  • Cleaner CLI output for developers running seeders.
  • Easier debugging and monitoring of which seeders ran and on which connection (especially useful in multi-database environments).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant