Skip to content

Commit 0a87d53

Browse files
committed
Apply asset filtering to schema name retrieval
1 parent 97b89a7 commit 0a87d53

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,41 @@ 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+
return str_starts_with(strtolower($assetName), $prefix);
592+
},
593+
);
594+
595+
$schema = $this->schemaManager->introspectSchema();
596+
597+
// Test that only filtered schemas are included in the introspection
598+
self::assertCount($expectedCount, $schema->getNamespaces());
599+
}
600+
601+
/** @return iterable<string, array{string, int}> */
602+
public static function schemaFilterProvider(): iterable
603+
{
604+
yield 'One schema' => ['filter_schema_1', 1];
605+
yield 'Two schemas' => ['filter_schema_', 2];
606+
}
607+
573608
/** @throws Exception */
574609
public function testAlterTableScenario(): void
575610
{
@@ -1020,6 +1055,12 @@ protected function createTestTable(string $name, array $data = []): Table
10201055
return $table;
10211056
}
10221057

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

0 commit comments

Comments
 (0)