Skip to content

Commit 43d8333

Browse files
committed
Apply asset filtering to schema name retrieval
1 parent 97b89a7 commit 43d8333

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/Schema/AbstractSchemaManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ public function introspectSchema(): Schema
939939
$schemaNames = [];
940940

941941
if ($this->platform->supportsSchemas()) {
942-
$schemaNames = $this->listSchemaNames();
942+
$schemaNames = $this->filterAssetNames($this->listSchemaNames());
943943
}
944944

945945
$sequences = [];

tests/Functional/Schema/SchemaManagerFunctionalTestCase.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,42 @@ public function testMigrateSchema(): void
570570
self::assertTrue($schema->hasTable('table_to_create'));
571571
}
572572

573+
#[DataProvider('schemaFilterProvider')]
574+
public function testIntrospectSchemaWithFilter(string $prefix, int $expectedCount): void
575+
{
576+
if (! $this->connection->getDatabasePlatform()->supportsSchemas()) {
577+
self::markTestSkipped('Platform does not support schemas.');
578+
}
579+
580+
// Create test schemas
581+
$this->createTestSchema('filter_schema_1');
582+
$this->createTestSchema('filter_schema_2');
583+
584+
$this->markConnectionNotReusable();
585+
586+
$this->connection->getConfiguration()->setSchemaAssetsFilter(
587+
static function (string|AbstractAsset $assetName) use ($prefix): bool {
588+
if ($assetName instanceof AbstractAsset) {
589+
$assetName = $assetName->getName();
590+
}
591+
592+
return str_starts_with(strtolower($assetName), $prefix);
593+
},
594+
);
595+
596+
$schema = $this->schemaManager->introspectSchema();
597+
598+
// Test that only filtered schemas are included in the introspection
599+
self::assertCount($expectedCount, $schema->getNamespaces());
600+
}
601+
602+
/** @return iterable<string, array{string, int}> */
603+
public static function schemaFilterProvider(): iterable
604+
{
605+
yield 'One schema' => ['filter_schema_1', 1];
606+
yield 'Two schemas' => ['filter_schema_', 2];
607+
}
608+
573609
/** @throws Exception */
574610
public function testAlterTableScenario(): void
575611
{
@@ -1020,6 +1056,12 @@ protected function createTestTable(string $name, array $data = []): Table
10201056
return $table;
10211057
}
10221058

1059+
/** @param non-empty-string $name */
1060+
protected function createTestSchema(string $name): void
1061+
{
1062+
$this->dropAndCreateSchema(UnqualifiedName::unquoted($name));
1063+
}
1064+
10231065
/**
10241066
* @param non-empty-string $unquotedName
10251067
* @param mixed[] $options

0 commit comments

Comments
 (0)