@rls
Row-level security policies for PostgreSQL tables
PostgresExample
Enable RLS and add a policy
Use @rls plus one or more @rls.policy tags on the table.
Input SQL
sql
-- @rls
-- @rls.policy(for: SELECT, to: authenticated, using: 'user_id = current_user_id()')
CREATE TABLE documents (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL,
title TEXT NOT NULL
);Compiled Output
sql
ALTER TABLE "documents" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "documents_authenticated_select" ON "documents"
FOR SELECT
TO authenticated
USING (user_id = current_user_id());Tags
@rls.policy
Create a row-level security policy (requires @rls on the table)
Targets: table
Arguments:
| Name | Type | Required | Values |
|---|---|---|---|
| for | string | No | — |
| to | string | No | — |
| using | string | No | — |
| check | string | No | — |
@rls
Enable row-level security on this table
Targets: table
Arguments: No arguments.
Lint Rules
rls.require-policy
Public tables should have RLS enabled
Default severity: warn
