Skip to content

[13.x] Feat (Added): Provision to specify default connection for migration #58944

Closed
aagjalpankaj wants to merge 1 commit intolaravel:13.xfrom
aagjalpankaj:feat-default-migration-connection
Closed

[13.x] Feat (Added): Provision to specify default connection for migration #58944
aagjalpankaj wants to merge 1 commit intolaravel:13.xfrom
aagjalpankaj:feat-default-migration-connection

Conversation

@aagjalpankaj
Copy link

@aagjalpankaj aagjalpankaj commented Feb 20, 2026

Closes discussion #54035

What it does?

Allows provision to specify default connection for migrations (by specifying config value database.migrations.connection).

So the priority for connection will be as below (Highest to Lowest):

  1. Migration-specific connection: Set via $connection property or Schema::connection() in the migration file (Existing)
  2. CLI option: --database=<connection> when running php artisan migrate (Existing)
  3. Default migration connection: database.migrations.connection configuration value (new feature)
  4. Default connection: database.default configuration value (Existing)

Why?

I have seen Laravel applications following separate connection for application (DML permissions) and migration (DDL permissions) due to some architectural decisions.

  • Mentioning Schema::connection('connection')-> while writing each migration or running artisan migrate --database=<connection> is not always handy.
  • When we setup project initially, the migrations table is created using default application connection.
  • Some automation scripts like serversideup runs artisan migrate command without allowing --database option.

This feature provides a "set once, use everywhere" solution through configuration, eliminating manual overhead while maintaining full backward compatibility.

@aagjalpankaj aagjalpankaj marked this pull request as draft February 20, 2026 17:07
@github-actions
Copy link

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@aagjalpankaj aagjalpankaj marked this pull request as ready for review February 20, 2026 17:14
@aagjalpankaj aagjalpankaj force-pushed the feat-default-migration-connection branch 2 times, most recently from 47f6cc6 to f66b8f3 Compare February 20, 2026 17:48
@aagjalpankaj aagjalpankaj force-pushed the feat-default-migration-connection branch from f66b8f3 to 84d2e98 Compare February 20, 2026 17:53
@aagjalpankaj aagjalpankaj changed the title [13.x] Feat (WIP): Provision to specify default connection for migration [13.x] Feat (Added): Provision to specify default connection for migration Feb 20, 2026
@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

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.

2 participants