Skip to content

feat(transform): name rebinding in SchemaRouter (repoint references at a different object) - #322

Merged
pyramation merged 1 commit into
mainfrom
feat/name-rebinding
Jul 30, 2026
Merged

feat(transform): name rebinding in SchemaRouter (repoint references at a different object)#322
pyramation merged 1 commit into
mainfrom
feat/name-rebinding

Conversation

@pyramation

Copy link
Copy Markdown
Collaborator

Summary

SchemaRouter object routes can now rebind — repoint a reference at a different object, not just a different schema. Routing preserves identity (same function, new address); rebinding is the substitution primitive: satisfy a reference's contract with another implementation.

An object route target is now string | ObjectRoute, where the shorthand string keeps today's meaning exactly:

interface ObjectRoute {
  schema?: string | null;  // null = de-qualify (rely on search_path)
  name?: string;           // rebind to a different object name
}

new SchemaRouter({
  accounts: {
    functions: { current_actor: { schema: null, name: 'current_user_id' } },
    relations: { members: { schema: 'app', name: 'users' } }
  }
});
// accounts.current_actor()              -> current_user_id()
// REFERENCES accounts.members(id)       -> REFERENCES app.users(id)
  • New resolveObject(schema, name, ns): ObjectRoute | undefined is the full-fidelity resolver; resolve() now delegates to it and keeps its exact schema-only semantics (a null/name-only target reads as "unchanged" there), so every existing caller behaves identically.
  • A rebind naming no schema inherits the route's schema-level default; schema: null de-qualifies, matching the ExtensionRouter to: null convention.
  • transformNameList / transformRelation apply { schema, name } targets, covering call sites in expressions, defaults, policies, FK target tables (RangeVar), DROP/COMMENT object lists, and references inside LANGUAGE sql and PL/pgSQL bodies (via the existing AST body walk).
  • New introspection: hasNameRebinds() (rebinds are inexpressible by the string-level passes, so callers must take the AST path) and nameRebinds() for reporting/verification by consumers.

Tests: 9 new cases (unit resolution + call-site/FK/policy/sql-body/de-qualify/sibling-isolation through transformSqlStatement); full @pgsql/transform suite green (8 suites / 228 tests).

Link to Devin session: https://app.devin.ai/sessions/025fb88043964fdbb335ac5e39df2478
Requested by: @pyramation

@pyramation pyramation self-assigned this Jul 30, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@pyramation
pyramation merged commit 76f1d79 into main Jul 30, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant