From 43a7ad29561944f31c3e9e8da4a3e79996150b3c Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Sat, 16 Mar 2024 06:22:25 +0100 Subject: [PATCH] added another migration to convert --- server/backend/migration/20240317000000.go | 36 ++++++++++++++++++++++ server/backend/migration/migration.go | 1 + 2 files changed, 37 insertions(+) create mode 100644 server/backend/migration/20240317000000.go diff --git a/server/backend/migration/20240317000000.go b/server/backend/migration/20240317000000.go new file mode 100644 index 00000000..354275a3 --- /dev/null +++ b/server/backend/migration/20240317000000.go @@ -0,0 +1,36 @@ +package migration + +import ( + "fmt" + + "github.com/go-gormigrate/gormigrate/v2" + "gorm.io/gorm" +) + +func tablesWithWrongCOLLATE() []string { + return []string{"crontab", "devices", "dish", "files", "kino", "news", "newsSource", "notifications", "notification_types"} +} + +// migrate20240317000000 +// unified a variety of factors to not be different for no reason +func migrate20240317000000() *gormigrate.Migration { + return &gormigrate.Migration{ + ID: "20240317000000", + Migrate: func(tx *gorm.DB) error { + for _, t := range tablesWithWrongCOLLATE() { + if err := tx.Exec(fmt.Sprintf("ALTER TABLE `%s` COLLATE utf8mb4_unicode_ci", t)).Error; err != nil { + return err + } + } + return nil + }, + Rollback: func(tx *gorm.DB) error { + for _, t := range tablesWithWrongCOLLATE() { + if err := tx.Exec(fmt.Sprintf("ALTER TABLE `%s` COLLATE utf8mb4_general_ci", t)).Error; err != nil { + return err + } + } + return nil + }, + } +} diff --git a/server/backend/migration/migration.go b/server/backend/migration/migration.go index 9c544cb2..1c70b870 100644 --- a/server/backend/migration/migration.go +++ b/server/backend/migration/migration.go @@ -74,6 +74,7 @@ func manualMigrate(db *gorm.DB) error { migrate20240311000000(), migrate20240312000000(), migrate20240316000000(), + migrate20240317000000(), } return gormigrate.New(db, gormigrateOptions, migrations).Migrate() }