mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 13:54:03 +00:00
Merge branch 'master' of github.com:archtechx/tenancy
This commit is contained in:
commit
9a8e95c9f6
3 changed files with 38 additions and 0 deletions
|
|
@ -258,6 +258,7 @@ return [
|
||||||
'migration_parameters' => [
|
'migration_parameters' => [
|
||||||
'--force' => true, // This needs to be true to run migrations in production.
|
'--force' => true, // This needs to be true to run migrations in production.
|
||||||
'--path' => [database_path('migrations/tenant')],
|
'--path' => [database_path('migrations/tenant')],
|
||||||
|
'--schema-path' => database_path('schema/tenant-schema.dump'),
|
||||||
'--realpath' => true,
|
'--realpath' => true,
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,10 @@ class TenantDump extends DumpCommand
|
||||||
|
|
||||||
public function handle(ConnectionResolverInterface $connections, Dispatcher $dispatcher): int
|
public function handle(ConnectionResolverInterface $connections, Dispatcher $dispatcher): int
|
||||||
{
|
{
|
||||||
|
if (is_null($this->option('path'))) {
|
||||||
|
$this->input->setOption('path', database_path('schema/tenant-schema.dump'));
|
||||||
|
}
|
||||||
|
|
||||||
$tenant = $this->option('tenant')
|
$tenant = $this->option('tenant')
|
||||||
?? tenant()
|
?? tenant()
|
||||||
?? $this->ask('What tenant do you want to dump the schema for?')
|
?? $this->ask('What tenant do you want to dump the schema for?')
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,39 @@ test('dump command works', function () {
|
||||||
expect('tests/Etc/tenant-schema-test.dump')->toBeFile();
|
expect('tests/Etc/tenant-schema-test.dump')->toBeFile();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('tenant dump file gets created as tenant-schema.dump in the database schema folder by default', function() {
|
||||||
|
config(['tenancy.migration_parameters.--schema-path' => $schemaPath = database_path('schema/tenant-schema.dump')]);
|
||||||
|
|
||||||
|
$tenant = Tenant::create();
|
||||||
|
Artisan::call('tenants:migrate');
|
||||||
|
|
||||||
|
tenancy()->initialize($tenant);
|
||||||
|
|
||||||
|
Artisan::call('tenants:dump');
|
||||||
|
|
||||||
|
expect($schemaPath)->toBeFile();
|
||||||
|
unlink($schemaPath);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('migrate command uses the correct schema path by default', function () {
|
||||||
|
config(['tenancy.migration_parameters.--schema-path' => 'tests/Etc/tenant-schema.dump']);
|
||||||
|
$tenant = Tenant::create();
|
||||||
|
|
||||||
|
expect(Schema::hasTable('schema_users'))->toBeFalse();
|
||||||
|
expect(Schema::hasTable('users'))->toBeFalse();
|
||||||
|
|
||||||
|
Artisan::call('tenants:migrate');
|
||||||
|
|
||||||
|
expect(Schema::hasTable('schema_users'))->toBeFalse();
|
||||||
|
expect(Schema::hasTable('users'))->toBeFalse();
|
||||||
|
|
||||||
|
tenancy()->initialize($tenant);
|
||||||
|
|
||||||
|
// Check for both tables to see if missing migrations also get executed
|
||||||
|
expect(Schema::hasTable('schema_users'))->toBeTrue();
|
||||||
|
expect(Schema::hasTable('users'))->toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
test('rollback command works', function () {
|
test('rollback command works', function () {
|
||||||
$tenant = Tenant::create();
|
$tenant = Tenant::create();
|
||||||
Artisan::call('tenants:migrate');
|
Artisan::call('tenants:migrate');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue