Default to a second database connection for migrations only #36747
Unanswered
charleskhenry
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Sorry, new to Laravel. I'm currently using version 8.0 as a best practice. However, I'm having difficulty setting the default MySQL connection for migration activities.
I would like to default all database transactions to limited permissions; while automatically elevating permissions for all migration activities.
I would think this feature exists already, but I can't find it in the documentation or after a few hours of googling.
1. First I created a database and some user accounts.
I created a 'laravel-basic' MySQL user, granting: create temporary tables, delete, execute, insert, lock tables, select, and update permissions.
I then created a 'laravel-elevated' MySQL user with all permissions except grant.
2. I then edited my .env and config/database.php files to have multiple connections
.env file:
config/database.php file:
3. Finally, for all migrations, I'm sure to replace default MySQL connections to use the proper elevated connection.
database/migrations/2014_10_12_000000_create_users_table.php file:
The Problem:
When I run
php artisan migrate
, for the first time, laravel fails to create the database tables because it trys to execute the database commands from the default account (which has basic permissions).I verified this by changing the default connection in
config/database.php
to instead use the elevated account rather than the basic account... and it runs without any problems.Additionally, if I add the create permission to the basic account, everything works okay.
So, how can I tell laravel to use the second database connection for Migrations only?
It appears to me that
laravel\framework\src\Illuminate\Database\Connection.php:678
only uses the default MySQL connection. Is this correct? Maybe, I should submit a feature request?Thanks for the help, loving the framework already.
Beta Was this translation helpful? Give feedback.
All reactions