NAME

DBIO::PostgreSQL::Diff::Policy - Diff operations for PostgreSQL Row Level Security policies

VERSION

version 0.900007

DESCRIPTION

Represents a Row Level Security diff operation: CREATE POLICY, DROP POLICY, ENABLE ROW LEVEL SECURITY, or DISABLE ROW LEVEL SECURITY. RLS enable/disable changes on tables are detected by comparing the rls_enabled flag from table introspection.

ATTRIBUTES

table_key

The schema.table key identifying the table. It is where the model files the table, and what "summary" prints; it is not SQL.

schema_name

The schema of that table.

table_name

The name of that table. "as_sql" writes the table from schema_name and table_name, each quoted for itself -- the key cannot be taken apart again, a schema or a table may have a dot in its name. "diff" takes both from the policy entry or the tables sections. An operation built by hand without them falls back to the key ("key_names" in DBIO::PostgreSQL::Introspect).

policy_name

The policy name (not set for enable_rls / disable_rls operations).

policy_info

Policy metadata hashref (command, permissive, using_expr, check_expr, roles).

METHODS

diff

my @ops = DBIO::PostgreSQL::Diff::Policy->diff(
    $source_pol, $target_pol, $source_tables, $target_tables,
);

Compares RLS state and policy sets. Detects RLS enable/disable changes on existing tables, new policies, and dropped policies.

A table that only the target has, with row level security enabled, gets its ENABLE ROW LEVEL SECURITY here as well, ahead of its policies: DBIO::PostgreSQL::Diff::Table creates the table and no more, and policies on a table without row level security apply to nobody.

as_sql

Returns the SQL for this operation: ALTER TABLE ... ENABLE/DISABLE ROW LEVEL SECURITY, CREATE POLICY ..., or DROP POLICY ... ON ....

CREATE POLICY writes what the policy's entry holds: AS RESTRICTIVE when permissive is defined and false, FOR the command unless it is ALL, TO the roles, USING and WITH CHECK. A policy without roles -- the catalog has none for a policy that is for everybody -- gets no TO, which is PUBLIC.

Policy and table are identifiers by the server's rule ("quote_ident" in DBIO::PostgreSQL::Util), and so is every role ("quote_role" in DBIO::PostgreSQL::Util, which leaves PUBLIC and the other key words that stand for a role as they are). The USING and WITH CHECK expressions come from the catalog (pg_get_expr) and are written as given.

For an action this class does not know it dies ("throw" in DBIO::PostgreSQL::Diff::NoStatement).

summary

Returns a one-line description such as +policy: users_own_data on auth.users or enable_rls on auth.users.

AUTHOR

DBIO & DBIx::Class Authors

COPYRIGHT AND LICENSE

Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.