Reputation: 268
I need to set in my application multiple connection to multiple database, one for development, one for tests and other for production. I have found on stack overflow some tips, to get by url and pass many and different settings, so I've improved it on my app, but I realized that when I try to run migrations that don't work because that has no url to pass, Is there another way to do that? Or do you intend to manage app mode different from what is it today? This could also define debug as false if production or test and true if development.
Upvotes: 0
Views: 56
Reputation: 268
I've done something like, in my path.php I defined APP_MODE variable as 'development' then in my app.php I create a case option if development this database, and app will have this behaviour if 'tests' this variables database and this another beahviour, if 'production' then another one. This help me to create many branches one for each APP_MODE, then when I need to send to tests or production I just make a merge and then send to jenkins deploy it
Upvotes: 0
Reputation: 54731
Check what the hostname of your development computer is.
On linux or Windows:
hostname
Make a copy of your app/config/app.default.php
to a file with that hostname instead of the word default
.
Edit the app/Console/Installer.php
file can change the createAppConfig
function as follows:
public static function createAppConfig($dir, $io)
{
$appConfig = $dir . '/config/app.php';
$defaultConfigPath = $dir . '/config/app.default.php';
$hostnameConfigPath = $dir . '/config/app.' . gethostname() . '.php';
$defaultConfig = file_exists($hostnameConfigPath) ? $hostnameConfigPath : $defaultConfigPath;
if (!file_exists($appConfig)) {
copy($defaultConfig, $appConfig);
$io->write('Created `config/app.php` file');
}
}
Now when you run composer install
on your project it will use either the app.default.php
configuration, or another configuration that matches the hostname of the current machine.
This couples all the configuration settings to an environment or a default. That might solve some of your issues, but if you want to switch databases on your development workstation. It's just easier to manually edit the app.php
file yourself. If you have to do anything more complicated than that.
Upvotes: 1