added data migration

and old GameSystem field to misc table to be able to handle all tables in the same procedure.
This commit is contained in:
2026-01-29 08:04:38 +01:00
parent c2de8a5d7d
commit dc5b3c3944
2 changed files with 33 additions and 6 deletions
+32 -6
View File
@@ -201,16 +201,42 @@ func MigrateDataIfNeeded(db ...*gorm.DB) error {
} else { } else {
targetDB = database.DB targetDB = database.DB
} }
tables := []string{
"gsm_lit_sources",
"gsm_believes",
"gsm_equipments",
"gsm_weapons",
"gsm_containers",
"gsm_transportations",
"gsm_skills",
"gsm_weaponskills",
"gsm_spells",
"char_chars",
"gsm_character_classes",
"gsm_misc",
"learning_skill_categories",
"learning_skill_difficulties",
"learning_spell_level_le_costs",
"learning_spell_schools",
}
sql := ` sql := `
UPDATE gsm_believes UPDATE TABLE
SET game_system_id = 1 SET game_system_id = 1
WHERE game_system_id IS NULL or game_system_id = 0; WHERE game_system_id IS NULL or game_system_id = 0;
` `
logger.Debug("Führe SQL-Update aus: %s", strings.ReplaceAll(sql, "\n", " ")) logger.Debug("Führe SQL-Update aus: %s", strings.ReplaceAll(sql, "\n", " "))
result := targetDB.Exec(sql) errors := []error{}
if result.Error != nil { for _, currentTable := range tables {
logger.Error("Fehler beim SQL-Update der Spell Learning Categories: %s", result.Error.Error()) //currentTable := tables[tables]
return fmt.Errorf("failed to update spell learning categories: %w", result.Error) execSQL := strings.ReplaceAll(sql, "TABLE", currentTable)
result := targetDB.Exec(execSQL)
if result.Error != nil {
logger.Error("Fehler beim SQL-Update der Tabelle %s: %s", currentTable, result.Error.Error())
errors = append(errors, fmt.Errorf("failed to update table %s: %w", currentTable, result.Error))
}
} }
return nil if len(errors) == 0 {
return nil
}
return fmt.Errorf("The following Errors occured when migrating data: %v", errors)
} }
+1
View File
@@ -137,6 +137,7 @@ type Believe struct {
// MiscLookup represents miscellaneous lookup values like gender, race, origin, etc. // MiscLookup represents miscellaneous lookup values like gender, race, origin, etc.
type MiscLookup struct { type MiscLookup struct {
ID uint `gorm:"primaryKey" json:"id"` ID uint `gorm:"primaryKey" json:"id"`
GameSystem string `gorm:"column:game_system;index;default:midgard" json:"game_system"`
GameSystemId uint `json:"game_system_id,omitempty"` GameSystemId uint `json:"game_system_id,omitempty"`
Key string `gorm:"column:key;type:varchar(50);index;not null" json:"key"` Key string `gorm:"column:key;type:varchar(50);index;not null" json:"key"`
Value string `gorm:"type:varchar(255);not null" json:"value"` Value string `gorm:"type:varchar(255);not null" json:"value"`