Skip to content

Commit 3fe608d

Browse files
committed
fix(lib/policies): syntax error on roles update
1 parent 0646f1e commit 3fe608d

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/lib/PostgresMetaPolicies.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export default class PostgresMetaPolicies {
9191
check,
9292
action = 'PERMISSIVE',
9393
command = 'ALL',
94-
roles = ['PUBLIC'],
94+
roles = ['public'],
9595
}: {
9696
name: string
9797
table: string
@@ -108,7 +108,7 @@ export default class PostgresMetaPolicies {
108108
CREATE POLICY ${ident(name)} ON ${ident(schema)}.${ident(table)}
109109
AS ${action}
110110
FOR ${command}
111-
TO ${roles.join(',')}
111+
TO ${roles.map(ident).join(',')}
112112
${definitionClause} ${checkClause};`
113113
const { error } = await this.query(sql)
114114
if (error) {
@@ -140,7 +140,7 @@ CREATE POLICY ${ident(name)} ON ${ident(schema)}.${ident(table)}
140140
const nameSql = name === undefined ? '' : `${alter} RENAME TO ${ident(name)};`
141141
const definitionSql = definition === undefined ? '' : `${alter} USING (${definition});`
142142
const checkSql = check === undefined ? '' : `${alter} WITH CHECK (${check});`
143-
const rolesSql = roles === undefined ? '' : `${alter} TO (${roles.join(',')});`
143+
const rolesSql = roles === undefined ? '' : `${alter} TO ${roles.map(ident).join(',')};`
144144

145145
// nameSql must be last
146146
const sql = `BEGIN; ${definitionSql} ${checkSql} ${rolesSql} ${nameSql} COMMIT;`

test/lib/policies.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ test('retrieve, create, update, delete', async () => {
8989
name: 'policy updated',
9090
definition: "current_setting('my.username') IN (name)",
9191
check: "current_setting('my.username') IN (name)",
92+
roles: ['postgres'],
9293
})
9394
expect(res).toMatchInlineSnapshot(
9495
{
@@ -107,7 +108,7 @@ test('retrieve, create, update, delete', async () => {
107108
"id": Any<Number>,
108109
"name": "policy updated",
109110
"roles": Array [
110-
"public",
111+
"postgres",
111112
],
112113
"schema": "public",
113114
"table": "memes",
@@ -135,7 +136,7 @@ test('retrieve, create, update, delete', async () => {
135136
"id": Any<Number>,
136137
"name": "policy updated",
137138
"roles": Array [
138-
"public",
139+
"postgres",
139140
],
140141
"schema": "public",
141142
"table": "memes",

0 commit comments

Comments
 (0)