Skip to content
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

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

Merged
merged 7 commits into from
Mar 27, 2024

Conversation

andrew-farries
Copy link
Collaborator

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.

Copy link
Member

@exekias exekias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! 🚀

pkg/migrations/migrations.go Outdated Show resolved Hide resolved
@andrew-farries andrew-farries merged commit cc8c2d3 into main Mar 27, 2024
44 checks passed
@andrew-farries andrew-farries deleted the transform-sql-option branch March 27, 2024 09:19
andrew-farries added a commit that referenced this pull request Mar 27, 2024
Use the SQL transformer to transform the `up` and `down` fields of a raw
SQL migration.

Builds on #329 which added a
`SQLTransformer` option to rewrite user-supplied SQL.
andrew-farries added a commit that referenced this pull request Mar 28, 2024
…operations (#333)

Revert #315 as there is no longer a demonstrated need for this option.

The `WithSQLTransformer` option was added (#329) and can be used to
transform raw SQL operations in #330, removing the need for the
`WithRawSQLURL` option.
andrew-farries added a commit that referenced this pull request Mar 28, 2024
Use the SQL transformer added in #329 to rewrite or reject column
`DEFAULT` values.

Column `DEFAULT` values are user-supplied SQL expressions that may need
to be restricted or rewritten in some environments.
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.

2 participants