xataio / pgroll

PostgreSQL zero-downtime migrations made easy
https://www.xata.io
Apache License 2.0
2.97k stars 54 forks source link

Add a `WithSQLTransformer` option to rewrite user-defined SQL in `up` and `down` triggers #329

Closed andrew-farries closed 5 months ago

andrew-farries commented 5 months ago

Add a new WithSQLTransformer option to rewrite the user-defined SQL used to define up and down triggers.

The intention is that the transformer be used to sanitize user-input SQL.

Transformers implement the following interface:

type SQLTransformer interface {
    Transform(sql string) (string, error)
}

and are used by the createTrigger function to rewrite the up or down SQL before using it in the trigger function definition.

Later PRs will use the same transformer to rewrite the up and down values used in raw SQL migrations and column DEFAULT expressions.