Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Schema/AbstractSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ public function introspectSchema(): Schema
$schemaNames = [];

if ($this->platform->supportsSchemas()) {
$schemaNames = $this->listSchemaNames();
$schemaNames = $this->filterAssetNames($this->listSchemaNames());
}

$sequences = [];
Expand Down
42 changes: 42 additions & 0 deletions tests/Functional/Schema/SchemaManagerFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,42 @@ public function testMigrateSchema(): void
self::assertTrue($schema->hasTable('table_to_create'));
}

#[DataProvider('schemaFilterProvider')]
public function testIntrospectSchemaWithFilter(string $prefix, int $expectedCount): void
{
if (! $this->connection->getDatabasePlatform()->supportsSchemas()) {
self::markTestSkipped('Platform does not support schemas.');
}

// Create test schemas
$this->createTestSchema('filter_schema_1');
$this->createTestSchema('filter_schema_2');

$this->markConnectionNotReusable();

$this->connection->getConfiguration()->setSchemaAssetsFilter(
static function (string|AbstractAsset $assetName) use ($prefix): bool {
if ($assetName instanceof AbstractAsset) {
$assetName = $assetName->getName();
}

return str_starts_with(strtolower($assetName), $prefix);
},
);

$schema = $this->schemaManager->introspectSchema();

// Test that only filtered schemas are included in the introspection
self::assertCount($expectedCount, $schema->getNamespaces());
}

/** @return iterable<string, array{string, int}> */
public static function schemaFilterProvider(): iterable
{
yield 'One schema' => ['filter_schema_1', 1];
yield 'Two schemas' => ['filter_schema_', 2];
}

/** @throws Exception */
public function testAlterTableScenario(): void
{
Expand Down Expand Up @@ -1020,6 +1056,12 @@ protected function createTestTable(string $name, array $data = []): Table
return $table;
}

/** @param non-empty-string $name */
protected function createTestSchema(string $name): void
{
$this->dropAndCreateSchema(UnqualifiedName::unquoted($name));
}

/**
* @param non-empty-string $unquotedName
* @param mixed[] $options
Expand Down