-
Notifications
You must be signed in to change notification settings - Fork 29
Description
This patch fixes several bugs in pgschema's dependency handling:
Issues Fixed
-
FK-heavy tables could be reordered alphabetically during cycles: When Kahn's algorithm encountered a cycle, it would fall back to alphabetical ordering, causing child tables to be created before parent tables. The fix breaks cycles deterministically based on source order and defers FK constraints until their referenced tables exist.
-
Schema-qualified identifiers in strings weren't normalized: When the desired schema was applied to a temporary schema, any schema-qualified identifiers inside strings (defaults, policy expressions, trigger bodies, etc.) were left untouched. The diff then emitted SQL that referenced the temp schema name instead of the real schema. The fix normalizes every textual field in the IR so the target schema name is restored everywhere.
-
Function replacements always emitted DROP followed by CREATE: If other objects referenced the function, the drop would fail before the replacement could run. The fix treats replacements as
CREATE OR REPLACEoperations only, and normalizes argument identities by stripping schema prefixes sopublic.member_statusandmember_statusaren't treated as different signatures. -
Updated diff fixtures/tests: Added coverage for deferred FK constraints, policy ordering, and normalized functions.
Patch
I've attached a patch file with the complete fix. The patch is also available in this branch: main...p-c-h-b:pgschema:fix/function-drops
Would you like me to open a PR, or would you prefer to review the patch first?