nnjeim / world

A Laravel package which provides a list of the countries, states, cities, currencies, timezones and languages.
MIT License
773 stars 108 forks source link

Feature: added way to specify a custom database connection #79

Closed rinodrummer closed 9 months ago

rinodrummer commented 9 months ago

I had the necessity to move this incredible dataset on a different database to improve performance on the main DB, so I decided to contribute directly on the package to give the possibility to do it.

This new feature doesn't introduce any breaking changes since, by default, it works with the default connection.

To customize the database connection it's just needed to add a new variable in the .env file name WORLD_DB_CONNECTION.

The only issue is that to make it work properly, the user must specify the connection when seeding via the --database option, I came with a solution to this problem: add a world:install command I already wrote (but not pushed yet) which I'll better explain in a comment on this PR.

rinodrummer commented 9 months ago

As said in the PR description, I felt the urge to make the installation process as simple as possible, so I added a world:install command that I think should come out in pair with this feature.

This new command corresponds to these ones:

// publish migrations
Artisan::call('vendor:publish --tag=world');
// migrate new tables
Artisan::call('migrate');
// re-seed the world data
Artisan::call('db:seed --class=WorldSeeder --database=' . config('world.connection'), array(), $this->getOutput());

By calling this command, the user should never worry about manually selecting the database when seeding.

I'm even thinking to to add the --database option to the migration too, so only the selected connection will be migrated, without messing with other user migrations.

nnjeim commented 9 months ago

@rinodrummer thank you for this major contribution. this addition makes sense, however please help in formatting the code. i have noticed some wrong code formatting. please help on fixing this. i would suggest that you push the World:install helper i would like to pull the branch and test it locally before merging it.

thank you

rinodrummer commented 9 months ago

@nnjeim I committed the world:install command!

I take the opportunity with this comment to ask you an opinion on adding the --database option to the php artisan migrate command too, so only the selected connection will be migrated, without messing with other user migrations.