Skip to content

Move TriggerConfig to backfill package #923

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

Merged
merged 1 commit into from
Jun 20, 2025
Merged

Conversation

kvch
Copy link
Contributor

@kvch kvch commented Jun 19, 2025

This PR is the first step towards moving creating triggers right before the backfill process starts.

In the long run, operations will only pass a trigger configuration to the backfill.Backfill struct, and it will
take care of loading the proper triggers for each table.

@github-actions github-actions bot temporarily deployed to Docs Preview June 19, 2025 16:43 Inactive
@kvch kvch changed the title Move TriggerConfig to backfill package Move TriggerConfig to backfill package Jun 19, 2025
@kvch kvch force-pushed the move-triggers-to-backfill-pkg branch from d784d1b to 41e72a7 Compare June 19, 2025 16:49
@github-actions github-actions bot temporarily deployed to Docs Preview June 19, 2025 16:49 Inactive
Copy link

Merging this branch will decrease overall coverage

Impacted Packages Coverage Δ 🤖
github.com/xataio/pgroll/pkg/backfill 0.00% (ø)
github.com/xataio/pgroll/pkg/migrations 74.60% (-0.03%) 👎

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/xataio/pgroll/pkg/backfill/trigger.go 0.00% (ø) 2 (+2) 0 2 (+2)
github.com/xataio/pgroll/pkg/migrations/op_add_column.go 80.99% (ø) 142 115 27
github.com/xataio/pgroll/pkg/migrations/op_alter_column.go 83.74% (ø) 123 103 20
github.com/xataio/pgroll/pkg/migrations/op_create_constraint.go 77.97% (ø) 118 92 26
github.com/xataio/pgroll/pkg/migrations/op_drop_column.go 76.74% (ø) 43 33 10
github.com/xataio/pgroll/pkg/migrations/op_drop_constraint.go 80.00% (ø) 65 52 13
github.com/xataio/pgroll/pkg/migrations/op_drop_multicolumn_constraint.go 82.50% (ø) 80 66 14
github.com/xataio/pgroll/pkg/migrations/trigger.go 80.77% (-1.37%) 26 (-2) 21 (-2) 5 👎

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/xataio/pgroll/pkg/migrations/op_add_column_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_change_type_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_common_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_drop_column_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_set_check_test.go
  • github.com/xataio/pgroll/pkg/migrations/trigger_test.go

Copy link
Collaborator

@andrew-farries andrew-farries left a comment

Choose a reason for hiding this comment

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

Changes look fiine 👍

Can you explain a bit more the motivation behind this:

first step towards moving creating triggers right before the backfill process starts

is this so that we can consolidate trigger creation and only create one per table?

I thought we might have a migration orchestrator component with a signature roughly like:

type Something interface {
  Process(actions ...DbAction) []DbAction
}

which would take care of simplifying and combining multiple create trigger actions on the same table, as well as any other changes to the list of actions required before the actions get executed. Is this roughly where you think this refactoring is heading?

@kvch
Copy link
Contributor Author

kvch commented Jun 20, 2025

is this so that we can consolidate trigger creation and only create one per table?

Yes. My goal is to create one up and down triggers per table. I would like to move the responsibility of creating and dropping triggers. Furthermore, I would like to move the management of _pgroll_needs_backfill column, too.

which would take care of simplifying and combining multiple create trigger actions on the same table, as well as any other changes to the list of actions required before the actions get executed. Is this roughly where you think this refactoring is heading?

Yes and no. This refactoring is adjacent to the migrations.DBAction refactoring. In this work I am moving trigger creation and temporary column (_pgroll_needs_backfill) out of the operations. My first idea was to return the list of DBActions from all operations as started here: #902 But over the weekend I started to play around with creating a dependency graph and running a topological sort on it. To simplify the graph, I would like to eliminate all unnecessary steps from each migration phases (Start, Complete and Rollback).

@kvch kvch merged commit b6c7a94 into main Jun 20, 2025
30 checks passed
@kvch kvch deleted the move-triggers-to-backfill-pkg branch June 20, 2025 09:00
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