a2way / laravel-tenant-migrate
A2Way Laravel Tenant Migrate
Installs: 6 196
Dependents: 0
Suggesters: 0
Security: 0
Stars: 24
Watchers: 5
Forks: 10
Open Issues: 1
Requires
- laravel/framework: ^5.8 || ^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.14
README
A2Way Laravel Tenant Migrate is a Laravel package that can be used to migrate different databases without editing database configuration files.
This is specially useful for SaaS (Software as a Service) web applications that stores data of each tenant in different databases. Migrating databases like that can be very hard because you might have to change your database configuration for each tenant database. As you can imagine, this is not a very scalable solution.
A2Way Laravel Tenant Migrate can help you overcome this problem.
Financial Support
Consider financially supporting this project at https://www.patreon.com/budhajeewa.
Commands Available
Installing A2Way Laravel Tenant Migrate on your Laravel project will add following commands to your artisan tool.
migrate:tenant [connection-name] [database-name]
migrate:tenant:all [connection-name] [database-prefix]
migrate:tenant:install [connection-name] [database-name]
migrate:tenant:refresh [connection-name] [database-name]
migrate:tenant:reset [connection-name] [database-name]
migrate:tenant:rollback [connection-name] [database-name]
Each of above commands (Except migrate:tenant:all
.) will perform the task of their cousin commands that has the similar name but for “tenant”. For an example, migrate:tenant:refresh myConnection myDatabase
will run migrate:refresh
on myDatabase
, accessing it through connection details given in myConnection
.
migrate:tenant:all
will help you to migrate multiple tenant databases at once by specifying their prefix. For an example, if you have tenant databases named tnt_a, tnt_b, and tnt_c, executing migrate:tenant:all myConnection tnt_
will migrate all three databases.
Installing
- Issue the following command:
composer require a2way/laravel-tenant-migrate ^1.0
- Then add the following line to your Laravel app’s
app/config/app.php
file'sproviders
sub-array.
A2way\LaravelTenantMigrate\LaravelTenantMigrateServiceProvider::class,
- Check the installation by issuing
php artisan
command. If you are able to see the above commands in your list of commands, installation was successful.
Development Setup
- Have Docker and Docker Compose.
- Clone this repo.
- Copy
tmp.env
file into.env
and fill in values. - Copy
laravel/tmp.env
file into.env
and fill in values (App Key and DB settings.). - Run
docker-compose up
.