1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 14:54:03 +00:00

Use Schema::getAllTables() instead of the migration file names

This commit is contained in:
lukinovec 2023-04-24 11:10:06 +02:00
parent 91936bc5ab
commit 2d75f185b8

View file

@ -6,8 +6,7 @@ namespace Stancl\Tenancy\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Schema;
use Symfony\Component\Finder\SplFileInfo;
class CreateRLSPoliciesForTenantTables extends Command class CreateRLSPoliciesForTenantTables extends Command
{ {
@ -28,15 +27,8 @@ class CreateRLSPoliciesForTenantTables extends Command
protected function getTenantTables(): array protected function getTenantTables(): array
{ {
$files = array_filter(File::files('./database/migrations/tenant'), function (SplFileInfo $migration) { $tables = array_map(fn ($table) => $table->tablename, Schema::getAllTables());
return str($migration->getFilename())->contains('create_');
});
return array_map(function (SplFileInfo $migration) { return array_filter($tables, fn ($table) => Schema::hasColumn($table, config('tenancy.models.tenant_key_column')));
return str($migration->getFilename())
->after('create_')
->before('_table')
->toString();
}, $files);
} }
} }