feat: add sql-schema-transform cloud function#7
Open
pyramation wants to merge 22 commits into
Open
Conversation
functions testing harness
Dev/testing strategy using a matrix
Adds a new Knative cloud function that transforms schema names in SQL using
AST-based parsing with plpgsql-parser. The function accepts SQL and a schema
mapping, then returns the transformed SQL with schema names replaced.
The transformation logic handles:
- Schema-qualified identifiers in RangeVar nodes (schema.table in SELECT/FROM)
- Schema names in CreateSchemaStmt, DropStmt, GrantStmt nodes
- DDL statements with embedded relations: CreateStmt (CREATE TABLE), IndexStmt,
AlterTableStmt, TruncateStmt, CreateTrigStmt, RuleStmt, CreatePolicyStmt
- Schema-qualified function names in FuncCall nodes
- Schema-qualified type names in TypeName nodes
- Schema names in VariableSetStmt (SET search_path)
- Schema names inside PL/pgSQL function bodies (hydrated AST)
API:
POST / with JSON body: {sql, schema_mapping}
Returns: {transformed_sql, schemas_found, schemas_transformed}
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
⚙️ Control Options:
|
ce265a7 to
dd2c7e9
Compare
Contributor
|
Heads-up: repository history was rewritten on 2026-05-12 to scrub leaked secrets (Postgres/pgAdmin default passwords, an AWS access key ID, generated This PR shows "DIRTY" / merge-conflict status because git fetch --all --prune
git checkout <this-branch>
git reset --hard origin/<this-branch> # your local branch tip moved too — pick up the rewritten version
git rebase origin/main # rebase onto rewritten main
# resolve conflicts (usually trivial — mostly secret-placeholder + the 4 deleted interweb-*.yaml files)
git push --force-with-leaseOr merge instead of rebase if the branch is shared with others: git merge origin/main
git pushNotes:
|
|
Devin is archived and cannot be woken up. Please unarchive Devin if you want to continue using it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new Knative cloud function that transforms schema names in SQL using AST-based parsing with
plpgsql-parser. The function accepts SQL and a schema mapping, then returns the transformed SQL with schema names replaced according to the mapping.The transformation handles:
API:
Review & Testing Checklist for Human
transform-schemas-ast.tsin constructive-db. Other DDL statements may need handlers (e.g., ViewStmt, CreateSeqStmt, CommentStmt)Recommended test plan:
Notes
anytypes for AST nodes (consistent with plpgsql-parser patterns but reduces type safety)Requested by: @pyramation
Link to Devin run: https://app.devin.ai/sessions/2eed6a2d4f0142349bb3bdd50334b23f