Fix notification metadata handling and add migration for null values
This commit is contained in:
parent
da41061163
commit
cdcde095dd
2 changed files with 60 additions and 7 deletions
|
@ -0,0 +1,43 @@
|
|||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"donetick.com/core/logging"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type MigrateFixNotificationMetadataExperimentModal20241212 struct{}
|
||||
|
||||
func (m MigrateFixNotificationMetadataExperimentModal20241212) ID() string {
|
||||
return "20250314_fix_notification_metadata_experiment_modal"
|
||||
}
|
||||
|
||||
func (m MigrateFixNotificationMetadataExperimentModal20241212) Description() string {
|
||||
return `Fix notification metadata for experiment modal, where notification metadata is a null string 'null' to empty json {}`
|
||||
}
|
||||
|
||||
func (m MigrateFixNotificationMetadataExperimentModal20241212) Down(ctx context.Context, db *gorm.DB) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m MigrateFixNotificationMetadataExperimentModal20241212) Up(ctx context.Context, db *gorm.DB) error {
|
||||
log := logging.FromContext(ctx)
|
||||
|
||||
// Start a transaction
|
||||
return db.Transaction(func(tx *gorm.DB) error {
|
||||
// Update all chore where notification metadata is a null stirng 'null' to empty json {}:
|
||||
|
||||
if err := tx.Table("chores").Where("notification_metadata = ?", "null").Update("notification_metadata", "{}").Error; err != nil {
|
||||
log.Errorf("Failed to update chores with null notification metadata: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Register this migration
|
||||
func init() {
|
||||
Register(MigrateFixNotificationMetadataExperimentModal20241212{})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue