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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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.

)

//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.

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