Skip to content

Commit

Permalink
added another migration to convert
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Mar 16, 2024
1 parent c164f14 commit 43a7ad2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions server/backend/migration/20240317000000.go
Original file line number Diff line number Diff line change
@@ -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
},
}
}
1 change: 1 addition & 0 deletions server/backend/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func manualMigrate(db *gorm.DB) error {
migrate20240311000000(),
migrate20240312000000(),
migrate20240316000000(),
migrate20240317000000(),
}
return gormigrate.New(db, gormigrateOptions, migrations).Migrate()
}
Expand Down

0 comments on commit 43a7ad2

Please sign in to comment.