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

fix: make preimage a nullable string #139

Closed
wants to merge 1 commit into from
Closed

Conversation

rolznz
Copy link
Contributor

@rolznz rolznz commented Sep 21, 2023

Related to #138

I think the preimage should not be able to be stored as an empty string (then we cannot make add a unique constraint)

The query in GetBudgetUsage is working incorrectly because it's checking preimage IS NOT NULL which always passes.

A follow up PR needs to be added to add the unique constraint, once this has been run.

@rolznz rolznz requested review from bumi and kiwiidb September 21, 2023 13:01
@@ -85,6 +85,13 @@ func main() {
log.Fatalf("Failed migrate DB %v", err)
}

// Update payments with preimage as an empty string to use NULL instead
// TODO: remove this migration in a future release and make preimage column unique
if err := db.Table("payments").Where("preimage = ?", "").Update("preimage", nil).Error; err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

don't do migrations like this.

either we have a proper migration setup or you do DB maintenance on the DB.

Copy link
Contributor

Choose a reason for hiding this comment

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

And if we don't have proper migrations. Then we must release this as a breaking change with details in the release notes, otherwise we break the deployment of others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I vote for a proper migration setup - I don't think we can release this as a breaking change. NWC on all umbrel apps will break and it's unreasonable to ask users to manually do something to fix it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gorm on its own does not seem to support doing a manual migration here (note: the string column from non-nullable to nullable IS migrated automatically, but not the query to update the preimage from '' to NULL needs to be done manually)

It looks like https://github.com/go-gormigrate/gormigrate could be the best option here, it runs inline (as opposed to atlas and golang-migrate)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think auto-migrate is mostly a dangerous option as you always have to be careful with the data that you have already in the DB.

and I think it's better to write explicit migrations then it is also possible to support different special SQL dialects (PG, SQLite)

@rolznz
Copy link
Contributor Author

rolznz commented Sep 27, 2023

Replaced by #148

@rolznz rolznz closed this Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants