diff --git a/src/Schema/AbstractSchema.php b/src/Schema/AbstractSchema.php index cd1c89cb0..9f9ebf8a4 100644 --- a/src/Schema/AbstractSchema.php +++ b/src/Schema/AbstractSchema.php @@ -126,6 +126,11 @@ abstract protected function loadTableUniques(string $tableName): array; */ abstract protected function loadTableSchema(string $name): TableSchemaInterface|null; + public function defaultSchema(string $defaultSchema): void + { + $this->defaultSchema = $defaultSchema; + } + public function getDefaultSchema(): string|null { return $this->defaultSchema; diff --git a/src/Schema/SchemaInterface.php b/src/Schema/SchemaInterface.php index 684a11f6e..c93085270 100644 --- a/src/Schema/SchemaInterface.php +++ b/src/Schema/SchemaInterface.php @@ -404,4 +404,11 @@ public function enableCache(bool $value): void; * @return array All view names in the database. */ public function getViewNames(string $schema = '', bool $refresh = false): array; + + /** + * Set the default schema of the database. + * + * @param string $defaultSchema The default schema name. + */ + public function defaultSchema(string $defaultSchema): void; } diff --git a/tests/Db/Schema/SchemaTest.php b/tests/Db/Schema/SchemaTest.php index 7db253b30..4253ad6d5 100644 --- a/tests/Db/Schema/SchemaTest.php +++ b/tests/Db/Schema/SchemaTest.php @@ -434,6 +434,16 @@ public function testSetTableMetadata(): void $this->assertSame($checkConstraint, $schema->getTableChecks('T_constraints_1')); } + public function testDefaultSchema(): void + { + $db = $this->getConnection(); + + $schema = $db->getSchema(); + $schema->defaultSchema('yii'); + + $this->assertSame('yii', $schema->getDefaultSchema()); + } + private function createTableSchemaStub(): TableSchemaInterface { // defined column C_id