Skip to content

Commit 3274a60

Browse files
committed
fix: some boolean fields are NULL
This fixes a bug where boolean fields are NULL for columns that are created when rows already exist. For these rows, the column is NULL, which gorm doesn't handle well since we can only query for true of false. This commit introduces a migration that updates those fields to the default value, which is always false for booleans. It's unclear if this is intended or an upstream bug in gorm, therefore I filed go-gorm/gorm#5968.
1 parent 4af23d6 commit 3274a60

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pkg/models/database.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,22 @@ func Migrate(db *gorm.DB) error {
1313
return fmt.Errorf("error during DB migration: %w", err)
1414
}
1515

16+
/*
17+
* Workaround for https://github.com/go-gorm/gorm/issues/5968
18+
*/
19+
// Account
20+
db.Unscoped().Model(&Account{}).Select("OnBudget").Where("accounts.on_budget IS NULL").Update("OnBudget", false)
21+
db.Unscoped().Model(&Account{}).Select("External").Where("accounts.external IS NULL").Update("External", false)
22+
db.Unscoped().Model(&Account{}).Select("Hidden").Where("accounts.hidden IS NULL").Update("Hidden", false)
23+
24+
// Category
25+
db.Unscoped().Model(&Category{}).Select("Hidden").Where("categories.hidden IS NULL").Update("Hidden", false)
26+
27+
// Envelope
28+
db.Unscoped().Model(&Envelope{}).Select("Hidden").Where("envelopes.hidden IS NULL").Update("Hidden", false)
29+
30+
// Transaction
31+
db.Unscoped().Model(&Transaction{}).Select("Reconciled").Where("transactions.reconciled IS NULL").Update("Reconciled", false)
32+
1633
return nil
1734
}

0 commit comments

Comments
 (0)