1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 15:54:03 +00:00

Added support for migration parameters (#243)

This commit is contained in:
Jess Johannessen 2019-12-10 16:56:51 +01:00 committed by Samuel Štancl
parent 609b6f12cf
commit 5145b1f13e
3 changed files with 17 additions and 4 deletions

View file

@ -93,9 +93,13 @@ return [
'home_url' => '/app', 'home_url' => '/app',
'queue_database_creation' => false, 'queue_database_creation' => false,
'migrate_after_creation' => false, // run migrations after creating a tenant 'migrate_after_creation' => false, // run migrations after creating a tenant
'migration_parameters' => [
// '--force' => true, // force database migrations
],
'seed_after_migration' => false, // should the seeder run after automatic migration 'seed_after_migration' => false, // should the seeder run after automatic migration
'seeder_parameters' => [ 'seeder_parameters' => [
'--class' => 'DatabaseSeeder', // root seeder class to run after automatic migrations, e.g.: 'DatabaseSeeder' '--class' => 'DatabaseSeeder', // root seeder class to run after automatic migrations, e.g.: 'DatabaseSeeder'
// '--force' => true, // force database seeder
], ],
'queue_database_deletion' => false, 'queue_database_deletion' => false,
'delete_database_after_tenant_deletion' => false, // delete the tenant's database after deleting the tenant 'delete_database_after_tenant_deletion' => false, // delete the tenant's database after deleting the tenant

View file

@ -19,9 +19,13 @@ class QueuedTenantDatabaseMigrator implements ShouldQueue
/** @var string */ /** @var string */
protected $tenantId; protected $tenantId;
public function __construct(Tenant $tenant) /** @var array */
protected $migrationParameters = [];
public function __construct(Tenant $tenant, $migrationParameters = [])
{ {
$this->tenantId = $tenant->id; $this->tenantId = $tenant->id;
$this->migrationParameters = $migrationParameters;
} }
/** /**
@ -33,6 +37,6 @@ class QueuedTenantDatabaseMigrator implements ShouldQueue
{ {
Artisan::call('tenants:migrate', [ Artisan::call('tenants:migrate', [
'--tenants' => [$this->tenantId], '--tenants' => [$this->tenantId],
]); ] + $this->migrationParameters);
} }
} }

View file

@ -78,11 +78,11 @@ class TenantManager
if ($this->shouldMigrateAfterCreation()) { if ($this->shouldMigrateAfterCreation()) {
$afterCreating[] = $this->databaseCreationQueued() $afterCreating[] = $this->databaseCreationQueued()
? new QueuedTenantDatabaseMigrator($tenant) ? new QueuedTenantDatabaseMigrator($tenant, $this->getMigrationParameters())
: function () use ($tenant) { : function () use ($tenant) {
$this->artisan->call('tenants:migrate', [ $this->artisan->call('tenants:migrate', [
'--tenants' => [$tenant['id']], '--tenants' => [$tenant['id']],
]); ] + $this->getMigrationParameters());
}; };
} }
@ -401,6 +401,11 @@ class TenantManager
return $this->app['config']['tenancy.seeder_parameters'] ?? []; return $this->app['config']['tenancy.seeder_parameters'] ?? [];
} }
public function getMigrationParameters()
{
return $this->app['config']['tenancy.migration_parameters'] ?? [];
}
/** /**
* Add an event listener. * Add an event listener.
* *