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

chore(popx): code simplification and refactoring #816

Merged
merged 3 commits into from
Nov 4, 2024

Conversation

zepatrik
Copy link
Member

@zepatrik zepatrik commented Oct 7, 2024

While debugging the migrator, I stumbled upon a couple of improvements that could be made.
I also removed the pkgerx package, as we don't use that now for years.

if len(legacyVersion) > 14 {
legacyVersion = legacyVersion[:14]
}
err := c.RawQuery(fmt.Sprintf("SELECT version FROM %s WHERE version IN (?, ?)", mtn), mi.Version, legacyVersion).All(&appliedMigrations)
Copy link
Member Author

Choose a reason for hiding this comment

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

We've now combined two queries into one, which should half the number of queries and (depending on the database) can significantly improve the performance of the migrate job.

if m.Connection.Dialect.Name() == "cockroach" {
outer := fn
fn = func() error {
return crdb.Execute(outer)
Copy link
Member Author

Choose a reason for hiding this comment

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

From the documentation of crdb.Execute:

It is used to add retry handling to the execution of a single statement. If a multi-statement transaction is being run, use ExecuteTx instead.

But as the transaction is started within, we don't need to retry anything at this point.

Copy link
Member

Choose a reason for hiding this comment

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

With my recent auto-commit changes, we should add retry to migrations that run without transactions (aka go migrations and auto commit transactions).

)

//go:embed stub/migrations/transactional/*.sql
var transactionalMigrations embed.FS

func TestMigratorUpgrading(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This test was mostly skipped anyway, and I removed the "legacy" migrator with this PR, so no need to test compatibility anymore.

@aeneasr aeneasr force-pushed the fix/popx/migrator-status branch from a10280b to 13b5cd0 Compare October 31, 2024 14:22
@aeneasr aeneasr merged commit 52dce5e into master Nov 4, 2024
9 checks passed
@aeneasr aeneasr deleted the fix/popx/migrator-status branch November 4, 2024 15:28
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