-
Notifications
You must be signed in to change notification settings - Fork 0
Add policy-to-function dependency tracking #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This adds support for tracking dependencies between RLS policies and user-defined functions that they reference in USING/CHECK expressions. Previously, pg-schema-diff could create policies before the functions they depend on, causing migration failures when a policy's USING or CHECK expression calls a user-defined function. Changes: - Query pg_depend to extract function dependencies from policies - Add FunctionDependencies field to the Policy struct - Update dependency graph to order function creation before policies - Update dependency graph to order policy deletion before function deletion This follows the same pattern used for cross-table policy dependencies (issue #266). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary of ChangesHello @vshulev, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances pg-schema-diff by introducing robust dependency tracking for Row Level Security (RLS) policies that utilize user-defined functions. Previously, migrations could fail due to incorrect ordering, where policies were created before their required functions. The changes ensure that the schema migration process correctly identifies and orders these dependencies, guaranteeing that functions are always in place before policies that reference them are applied, and are removed only after dependent policies are gone. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request successfully implements policy-to-function dependency tracking, addressing a critical issue where RLS policies could be created before their dependent functions, leading to migration failures. The changes are comprehensive, covering SQL query modifications to extract function dependencies, updates to the Go schema representation, and crucial adjustments to the SQL generation logic to ensure correct ordering of policy and function DDL statements. The addition of new acceptance and schema tests thoroughly validates the new functionality for both add and drop scenarios, including non-public schemas. The code is well-structured, clearly commented, and directly resolves the identified problem, significantly improving the robustness of schema migrations involving RLS policies and user-defined functions.
Summary
This adds support for tracking dependencies between RLS policies and user-defined functions that they reference in USING/CHECK expressions.
Previously, pg-schema-diff could create policies before the functions they depend on, causing migration failures like:
This happened because the dependency graph didn't track policy→function relationships, so when both a function and a policy referencing it were added, the policy could be created first.
Changes
pg_dependto extract function dependencies from policies (similar to existing cross-table policy dependency tracking)FunctionDependenciesfield to thePolicystructTest plan
FunctionDependenciesextraction🤖 Generated with Claude Code