1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 18: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\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use Symfony\Component\Finder\SplFileInfo;
use Illuminate\Support\Facades\Schema;
class CreateRLSPoliciesForTenantTables extends Command
{
@ -28,15 +27,8 @@ class CreateRLSPoliciesForTenantTables extends Command
protected function getTenantTables(): array
{
$files = array_filter(File::files('./database/migrations/tenant'), function (SplFileInfo $migration) {
return str($migration->getFilename())->contains('create_');
});
$tables = array_map(fn ($table) => $table->tablename, Schema::getAllTables());
return array_map(function (SplFileInfo $migration) {
return str($migration->getFilename())
->after('create_')
->before('_table')
->toString();
}, $files);
return array_filter($tables, fn ($table) => Schema::hasColumn($table, config('tenancy.models.tenant_key_column')));
}
}