From 966e2149e2ddb06d8cde3c0490781d38f386aa5c Mon Sep 17 00:00:00 2001 From: Dmitriy Gritsenko Date: Wed, 25 Dec 2024 20:58:06 +0500 Subject: [PATCH] Fix issue #762 --- src/Schema/AbstractSchema.php | 12 ++++++------ src/Schema/SchemaInterface.php | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/Schema/AbstractSchema.php b/src/Schema/AbstractSchema.php index 264c8902d..890835e1c 100644 --- a/src/Schema/AbstractSchema.php +++ b/src/Schema/AbstractSchema.php @@ -578,9 +578,9 @@ public function getViewNames(string $schema = '', bool $refresh = false): array /** * @throws Throwable */ - public function hasTable(string $tableName, string $schema = ''): bool + public function hasTable(string $tableName, string $schema = '', bool $refresh = false): bool { - $tables = $this->getTableNames($schema); + $tables = $this->getTableNames($schema, $refresh); return in_array($tableName, $tables); } @@ -588,9 +588,9 @@ public function hasTable(string $tableName, string $schema = ''): bool /** * @throws Throwable */ - public function hasSchema(string $schema): bool + public function hasSchema(string $schema, bool $refresh = false): bool { - $schemas = $this->getSchemaNames(); + $schemas = $this->getSchemaNames($refresh); return in_array($schema, $schemas); } @@ -598,9 +598,9 @@ public function hasSchema(string $schema): bool /** * @throws Throwable */ - public function hasView(string $viewName, string $schema = ''): bool + public function hasView(string $viewName, string $schema = '', bool $refresh = false): bool { - $views = $this->getViewNames($schema); + $views = $this->getViewNames($schema, $refresh); return in_array($viewName, $views); } diff --git a/src/Schema/SchemaInterface.php b/src/Schema/SchemaInterface.php index 422518564..2d4216127 100644 --- a/src/Schema/SchemaInterface.php +++ b/src/Schema/SchemaInterface.php @@ -423,17 +423,23 @@ public function getViewNames(string $schema = '', bool $refresh = false): array; * @param string $tableName The table name to search for * @param string $schema The schema of the tables. Defaults to empty string, meaning the current or default schema * name. If not empty, the table will be searched in the specified schema. + * @param bool $refresh Whether to fetch the latest available table names. If this is false, view names fetched + * before (if available) will be returned. + * * @return bool Whether table exists or not */ - public function hasTable(string $tableName, string $schema = ''): bool; + public function hasTable(string $tableName, string $schema = '', bool $refresh = false): bool; /** * Determines if a specified schema exists in the database. * * @param string $schema The table name to search for + * @param bool $refresh Whether to fetch the latest available schema names. If this is false, view names fetched + * before (if available) will be returned. + * * @return bool Whether schema exists or not */ - public function hasSchema(string $schema): bool; + public function hasSchema(string $schema, bool $refresh = false): bool; /** * Determines if a specified view exists in the database. @@ -441,7 +447,10 @@ public function hasSchema(string $schema): bool; * @param string $viewName The table name to search for * @param string $schema The schema of the tables. Defaults to empty string, meaning the current or default schema * name. If not empty, the table will be searched in the specified schema. + * @param bool $refresh Whether to fetch the latest available view names. If this is false, view names fetched + * before (if available) will be returned. + * * @return bool Whether view exists or not */ - public function hasView(string $viewName, string $schema = ''): bool; + public function hasView(string $viewName, string $schema = '', bool $refresh = false): bool; }