mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-15 23:54:04 +00:00
Refactor DatabaseConfig, minor DB manager improvements, resolve todos
Notable changes: - CreateUserWithRLSPolicies: Clarify why we're creating a custom DatabaseConfing instance - HasDatabase: Clarify why we're ignoring tenancy_db_connection - DatabaseConfig: General refactor, clarify the role of the host conn - SQLiteDatabaseManager: Handle trailing DIRECTORY_SEPARATOR in static::$path - DisallowSqliteAttach: Don't throw any exceptions, just silently fail since the class isn't 100% portable - Clean up todos that are no longer relevant - Clean up dead code or comments in some database managers
This commit is contained in:
parent
3846fe88ec
commit
a0a9b85982
8 changed files with 33 additions and 32 deletions
|
|
@ -81,12 +81,19 @@ class CreateUserWithRLSPolicies extends Command
|
|||
#[\SensitiveParameter]
|
||||
string $password,
|
||||
): DatabaseConfig {
|
||||
// This is a bit of a hack. We want to use our existing createUser() logic.
|
||||
// That logic needs a DatabaseConfig instance. However, we aren't really working
|
||||
// with any specific tenant here. We also *don't* want to use anything tenant-specific
|
||||
// here. We are creating the SHARED "RLS user". Therefore, we need a custom DatabaseConfig
|
||||
// instance for this purpose. The easiest way to do that is to grab an empty Tenant model
|
||||
// (we use TenantWithDatabase in RLS) and manually create the host connection, just like
|
||||
// DatabaseConfig::manager() would. We don't call that method since we want to use our existing
|
||||
// PermissionControlledPostgreSQLSchemaManager $manager instance, rather than the "tenant's manager".
|
||||
|
||||
/** @var TenantWithDatabase $tenantModel */
|
||||
$tenantModel = tenancy()->model();
|
||||
|
||||
// Use a temporary DatabaseConfig instance to set the host connection
|
||||
$temporaryDbConfig = $tenantModel->database();
|
||||
|
||||
$temporaryDbConfig->purgeHostConnection();
|
||||
|
||||
$tenantHostConnectionName = $temporaryDbConfig->getTenantHostConnectionName();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue