-
Notifications
You must be signed in to change notification settings - Fork 91
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
Introduce DBAction
interface and refactoring of column dropping
#709
Conversation
DBAction
interface and refactoring of column dropping
@kvch code change LGTM but I would wait on the rest of the team to see if this is the desired path! my personal view: I kind of like that operations are self-contained for the most part, with some helper functions for complex stuff like backfills. This pattern would force us to write the statements elsewhere, hiding the operation implementation a bit. Not a big deal for me, but still... |
The operations are getting less and less self-contained, because we are adding more and more complexity as go beyond the naive implementation of each migration. Also, some of the operations have overlap like Furthermore, we already have |
👍 thank you for the detailed explanation! no strong opinion on my side, to me whatever @andrew-farries and you decide works for me! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the direction of this change but I think we can go further:
For at least the Start
phase, and possibly also for Complete
and Rollback
the method could return the list of DBActions
to be executed, rather than having the methods execute the actions directly.
This would allow us to more easily re-order and squash steps in multi-operation migations, for example allowing two operations to modify the same column - this is currently unsupported as each operation independently tries to duplicate the column.
WDYT @kvch ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new DBAction interface with its dropColumnAction implementation to streamline and unify various database migration operations. The changes refactor multiple migration operations to use NewDropColumnAction for dropping columns, which improves consistency and modularity in how migration steps are executed.
- Introduces a DBAction interface and dropColumnAction for column dropping.
- Refactors several migration operations (add, drop, alter, and constraint operations) to use NewDropColumnAction.
- Enhances consistency in executing SQL column drop operations across different migration files.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
pkg/migrations/dbactions.go | New DBAction interface and dropColumnAction implementation |
pkg/migrations/op_add_column.go | Replaced direct ExecContext call with dropColumnAction usage |
pkg/migrations/op_drop_constraint.go | Refactored drop column logic to use dropColumnAction |
pkg/migrations/op_create_constraint.go | Updated drop column and backfill removal with dropColumnAction |
pkg/migrations/op_drop_column.go | Refactored drop column steps to use dropColumnAction |
pkg/migrations/op_drop_multicolumn_constraint.go | Updated multiple column drop and backfill removal with dropColumnAction |
pkg/migrations/op_alter_column.go | Replaced direct drops with dropColumnAction usage in complete and rollback steps |
I like this approach. To keep the review burden and the changeset small, I would like to transform all existing database actions to the common format in different PRs. Then in a separate PR I will implement the new interface for |
That works for me 👍 |
This PR is part of a refactoring effort. My goal is to unify all database actions pgroll is executing. Example actions include dropping columns, renaming columns, creating and dropping triggers, creating constraints, etc.
We can define a list of these actions in a migration phase and run them sequentially. The following example is a
Complete
phase of an imaginary migration:In this step I implemented column dropping as an action. In later PRs I would like to add creating and dropping triggers, functions, etc.