Skip to content

Commit

Permalink
Check DB existsance as config
Browse files Browse the repository at this point in the history
  • Loading branch information
oniz93 committed Feb 6, 2021
1 parent 192594c commit d4cfe40
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions assets/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* Database tenancy config. Used by DatabaseTenancyBootstrapper.
*/
'database' => [
'check_db_exists' => true,
'central_connection' => env('DB_CONNECTION', 'central'),

/**
Expand Down
2 changes: 1 addition & 1 deletion src/TenantDatabaseManagers/MySQLDatabaseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function deleteDatabase(TenantWithDatabase $tenant): bool

public function databaseExists(string $name): bool
{
return (bool) $this->database()->select("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '$name'");
return config('tenancy.database.check_db_exists') ? (bool) $this->database()->select("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '$name'") : true;
}

public function makeConnectionConfig(array $baseConfig, string $databaseName): array
Expand Down
2 changes: 1 addition & 1 deletion src/TenantDatabaseManagers/PostgreSQLDatabaseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function deleteDatabase(TenantWithDatabase $tenant): bool

public function databaseExists(string $name): bool
{
return (bool) $this->database()->select("SELECT datname FROM pg_database WHERE datname = '$name'");
return config('tenancy.database.check_db_exists') ? (bool)$this->database()->select("SELECT datname FROM pg_database WHERE datname = '$name'") : true;
}

public function makeConnectionConfig(array $baseConfig, string $databaseName): array
Expand Down
2 changes: 1 addition & 1 deletion src/TenantDatabaseManagers/PostgreSQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function deleteDatabase(TenantWithDatabase $tenant): bool

public function databaseExists(string $name): bool
{
return (bool) $this->database()->select("SELECT schema_name FROM information_schema.schemata WHERE schema_name = '$name'");
return config('tenancy.database.check_db_exists') ? (bool) $this->database()->select("SELECT schema_name FROM information_schema.schemata WHERE schema_name = '$name'") : true;
}

public function makeConnectionConfig(array $baseConfig, string $databaseName): array
Expand Down
2 changes: 1 addition & 1 deletion src/TenantDatabaseManagers/SQLiteDatabaseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function deleteDatabase(TenantWithDatabase $tenant): bool

public function databaseExists(string $name): bool
{
return file_exists(database_path($name));
return config('tenancy.database.check_db_exists') ? file_exists(database_path($name)) : true;
}

public function makeConnectionConfig(array $baseConfig, string $databaseName): array
Expand Down

0 comments on commit d4cfe40

Please sign in to comment.