mirror of
https://github.com/archtechx/tenancy.git
synced 2026-08-06 04:54:04 +00:00
Merge 61410b52d4 into e0990a438c
This commit is contained in:
commit
8a8f5a6189
4 changed files with 11 additions and 11 deletions
|
|
@ -528,7 +528,7 @@ class TableRLSManager implements RLSPolicyManager
|
|||
|
||||
if ($table === tenancy()->model()->getTable()) {
|
||||
// Convert tenant key to text to match the session variable type
|
||||
$query .= "{$column}::text = current_setting('{$sessionTenantKey}')\n";
|
||||
$query .= "{$column}::text = (select current_setting('{$sessionTenantKey}'))\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ class TraitRLSManager implements RLSPolicyManager
|
|||
|
||||
return <<<SQL
|
||||
CREATE POLICY {$table}_rls_policy ON {$table} USING (
|
||||
{$tenantKeyColumn}::text = current_setting('{$sessionTenantKey}')
|
||||
{$tenantKeyColumn}::text = (select current_setting('{$sessionTenantKey}'))
|
||||
);
|
||||
SQL;
|
||||
}
|
||||
|
|
@ -87,7 +87,7 @@ class TraitRLSManager implements RLSPolicyManager
|
|||
{$parentRelationship->getForeignKeyName()} IN (
|
||||
SELECT {$parent->getKeyName()}
|
||||
FROM {$parent->getTable()}
|
||||
WHERE {$tenantKeyColumn}::text = current_setting('{$sessionTenantKey}')
|
||||
WHERE {$tenantKeyColumn}::text = (select current_setting('{$sessionTenantKey}'))
|
||||
)
|
||||
);
|
||||
SQL;
|
||||
|
|
|
|||
|
|
@ -582,7 +582,7 @@ test('table rls manager generates queries correctly', function() {
|
|||
expect(array_values(app(TableRLSManager::class)->generateQueries()))->toEqualCanonicalizing([
|
||||
<<<SQL
|
||||
CREATE POLICY authors_rls_policy ON authors USING (
|
||||
tenant_id::text = current_setting('my.current_tenant')
|
||||
tenant_id::text = (select current_setting('my.current_tenant'))
|
||||
);
|
||||
SQL,
|
||||
<<<SQL
|
||||
|
|
@ -590,7 +590,7 @@ test('table rls manager generates queries correctly', function() {
|
|||
author_id IN (
|
||||
SELECT id
|
||||
FROM authors
|
||||
WHERE tenant_id::text = current_setting('my.current_tenant')
|
||||
WHERE tenant_id::text = (select current_setting('my.current_tenant'))
|
||||
)
|
||||
);
|
||||
SQL,
|
||||
|
|
@ -602,7 +602,7 @@ test('table rls manager generates queries correctly', function() {
|
|||
WHERE author_id IN (
|
||||
SELECT id
|
||||
FROM authors
|
||||
WHERE tenant_id::text = current_setting('my.current_tenant')
|
||||
WHERE tenant_id::text = (select current_setting('my.current_tenant'))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
|
@ -652,7 +652,7 @@ test('table rls manager generates queries correctly', function() {
|
|||
expect(app(TableRLSManager::class)->generateQueries($paths))->toContain(
|
||||
<<<SQL
|
||||
CREATE POLICY primaries_rls_policy ON primaries USING (
|
||||
tenant_id::text = current_setting('my.current_tenant')
|
||||
tenant_id::text = (select current_setting('my.current_tenant'))
|
||||
);
|
||||
SQL,
|
||||
<<<SQL
|
||||
|
|
@ -660,7 +660,7 @@ test('table rls manager generates queries correctly', function() {
|
|||
primary_id IN (
|
||||
SELECT id
|
||||
FROM primaries
|
||||
WHERE tenant_id::text = current_setting('my.current_tenant')
|
||||
WHERE tenant_id::text = (select current_setting('my.current_tenant'))
|
||||
)
|
||||
);
|
||||
SQL,
|
||||
|
|
@ -672,7 +672,7 @@ test('table rls manager generates queries correctly', function() {
|
|||
WHERE primary_id IN (
|
||||
SELECT id
|
||||
FROM primaries
|
||||
WHERE tenant_id::text = current_setting('my.current_tenant')
|
||||
WHERE tenant_id::text = (select current_setting('my.current_tenant'))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -279,7 +279,7 @@ test('trait rls manager generates queries correctly', function() {
|
|||
expect($manager->generateQueries())->toContain(
|
||||
<<<SQL
|
||||
CREATE POLICY posts_rls_policy ON posts USING (
|
||||
tenant_id::text = current_setting('my.current_tenant')
|
||||
tenant_id::text = (select current_setting('my.current_tenant'))
|
||||
);
|
||||
SQL,
|
||||
<<<SQL
|
||||
|
|
@ -287,7 +287,7 @@ test('trait rls manager generates queries correctly', function() {
|
|||
post_id IN (
|
||||
SELECT id
|
||||
FROM posts
|
||||
WHERE tenant_id::text = current_setting('my.current_tenant')
|
||||
WHERE tenant_id::text = (select current_setting('my.current_tenant'))
|
||||
)
|
||||
);
|
||||
SQL,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue