Skip to content

chore(popx): code simplification and refactoring#816

Merged
aeneasr merged 3 commits into
masterfrom
fix/popx/migrator-status
Nov 4, 2024
Merged

chore(popx): code simplification and refactoring#816
aeneasr merged 3 commits into
masterfrom
fix/popx/migrator-status

Conversation

@zepatrik

@zepatrik zepatrik commented Oct 7, 2024

Copy link
Copy Markdown
Member

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.

Comment thread popx/migrator.go
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
Copy Markdown
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.

Comment thread popx/migrator.go
if m.Connection.Dialect.Name() == "cockroach" {
outer := fn
fn = func() error {
return crdb.Execute(outer)

Copy link
Copy Markdown
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
Copy Markdown
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).

Comment thread popx/migrator_test.go
//go:embed stub/migrations/transactional/*.sql
var transactionalMigrations embed.FS

func TestMigratorUpgrading(t *testing.T) {

Copy link
Copy Markdown
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
@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