Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions __fixtures__/generated/generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -21256,6 +21256,12 @@
"misc/quotes_etc-28.sql": "DO $$\nBEGIN\n RAISE NOTICE 'Line one\\nLine two';\nEND;\n$$ LANGUAGE plpgsql",
"misc/quotes_etc-29.sql": "CREATE USER MAPPING FOR local_user SERVER \"foreign_server\" OPTIONS (user 'remote_user', password 'secret123')",
"misc/quotes_etc-30.sql": "CREATE USER MAPPING FOR local_user SERVER foreign_server OPTIONS (user 'remote_user', password 'secret123')",
"misc/policy-quoted-names-1.sql": "CREATE POLICY \"Users can view own data\" ON public.todos FOR SELECT TO authenticated USING (auth.uid() = user_id)",
"misc/policy-quoted-names-2.sql": "DROP POLICY \"Users can view own data\" ON public.todos",
"misc/policy-quoted-names-3.sql": "DROP POLICY IF EXISTS \"Users can view own data\" ON todos",
"misc/policy-quoted-names-4.sql": "COMMENT ON POLICY \"Users can view own data\" ON public.todos IS 'owner read'",
"misc/policy-quoted-names-5.sql": "COMMENT ON POLICY \"Users can view own data\" ON todos IS 'owner read'",
"misc/policy-quoted-names-6.sql": "ALTER POLICY \"Users can view own data\" ON public.todos RENAME TO \"Owners read\"",
"misc/pg_catalog-1.sql": "SELECT json_object('{}')",
"misc/pg_catalog-2.sql": "SELECT * FROM generate_series(1, 5)",
"misc/pg_catalog-3.sql": "SELECT get_byte(E'\\\\xDEADBEEF'::bytea, 1)",
Expand Down
7 changes: 7 additions & 0 deletions __fixtures__/kitchen-sink/misc/policy-quoted-names.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Policy names that need quoting (Supabase-style names with spaces)
CREATE POLICY "Users can view own data" ON public.todos FOR SELECT TO authenticated USING (auth.uid() = user_id);
DROP POLICY "Users can view own data" ON public.todos;
DROP POLICY IF EXISTS "Users can view own data" ON todos;
COMMENT ON POLICY "Users can view own data" ON public.todos IS 'owner read';
COMMENT ON POLICY "Users can view own data" ON todos IS 'owner read';
ALTER POLICY "Users can view own data" ON public.todos RENAME TO "Owners read";
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import { FixtureTestUtils } from '../../test-utils';
const fixtures = new FixtureTestUtils();

it('misc-policy-quoted-names', async () => {
await fixtures.runFixtureTests([
"misc/policy-quoted-names-1.sql",
"misc/policy-quoted-names-2.sql",
"misc/policy-quoted-names-3.sql",
"misc/policy-quoted-names-4.sql",
"misc/policy-quoted-names-5.sql",
"misc/policy-quoted-names-6.sql"
]);
});
9 changes: 7 additions & 2 deletions packages/deparser/src/deparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4699,7 +4699,7 @@ export class Deparser implements DeparserVisitor {
if (objList && (objList as any).List && (objList as any).List.items) {
const items = (objList as any).List.items.map((item: any) => {
if (item.String && item.String.sval) {
return item.String.sval;
return QuoteUtils.quoteIdentifier(item.String.sval);
}
return this.visit(item, context);
});
Expand Down Expand Up @@ -7156,7 +7156,12 @@ export class Deparser implements DeparserVisitor {
}
} else if (node.objtype === 'OBJECT_POLICY') {
// Handle POLICY syntax: COMMENT ON POLICY policy_name ON table_name IS 'comment'
if (objectParts.length === 2) {
if (objectParts.length === 3) {
const [schema, table, policy] = objectParts;
output.push(policy);
output.push('ON');
output.push(`${schema}.${table}`);
} else if (objectParts.length === 2) {
const [table, policy] = objectParts;
output.push(policy);
output.push('ON');
Expand Down
Loading