diff --git a/backend/database/config.go b/backend/database/config.go index 33c5b02..973479d 100644 --- a/backend/database/config.go +++ b/backend/database/config.go @@ -38,6 +38,13 @@ var ( func ConnectDatabase() *gorm.DB { SetupTestDB() + /* + db, err := gorm.Open(sqlite.Open(PreparedTestDB), &gorm.Config{}) + if err != nil { + log.Fatal("Failed to connect to database:", err) + } + DB = db + */ return DB } func ConnectDatabaseOrig() *gorm.DB { diff --git a/backend/maintenance/handlers.go b/backend/maintenance/handlers.go index 0aa82a1..ce1251f 100644 --- a/backend/maintenance/handlers.go +++ b/backend/maintenance/handlers.go @@ -45,6 +45,40 @@ func migrateAllStructures(db *gorm.DB) error { return nil } +func migrateDataIfNeeded(db *gorm.DB) error { + // Kopiere categorie nach learning_category für Spells, wenn learning_category leer ist + err := migrateSpellLearningCategories(db) + if err != nil { + return fmt.Errorf("failed to migrate spell learning categories: %w", err) + } + + return nil +} + +// migrateSpellLearningCategories kopiert categorie-Werte in learning_category wenn diese leer sind +func migrateSpellLearningCategories(db *gorm.DB) error { + // SQL-Statement um categorie nach learning_category zu kopieren, wo learning_category leer oder NULL ist + sql := ` + UPDATE gsm_spells + SET learning_category = category + WHERE (learning_category IS NULL OR learning_category = '') + AND category IS NOT NULL + AND category != '' + ` + + result := db.Exec(sql) + if result.Error != nil { + return fmt.Errorf("failed to update spell learning categories: %w", result.Error) + } + + // Log der Anzahl der aktualisierten Datensätze + if result.RowsAffected > 0 { + fmt.Printf("Updated %d spell records with learning_category from categorie\n", result.RowsAffected) + } + + return nil +} + func MakeTestdataFromLive(c *gin.Context) { liveDB := database.ConnectDatabase() if liveDB == nil { @@ -361,6 +395,12 @@ func SetupCheck(c *gin.Context) { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } + + err = migrateDataIfNeeded(db) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to migrate data: " + err.Error()}) + return + } c.JSON(http.StatusOK, gin.H{"message": "Setup Check OK"}) } diff --git a/backend/models/model_gsmaster.go b/backend/models/model_gsmaster.go index 625d3f7..b761378 100644 --- a/backend/models/model_gsmaster.go +++ b/backend/models/model_gsmaster.go @@ -63,24 +63,25 @@ type WeaponSkill struct { } type Spell struct { - ID uint `gorm:"primaryKey" json:"id"` - GameSystem string `gorm:"column:game_system;index;default:midgard" json:"game_system"` - Name string `gorm:"type:varchar(255);index" json:"name"` - Beschreibung string `json:"beschreibung"` - Quelle string `json:"quelle"` // Deprecated: Für Rückwärtskompatibilität - SourceID uint `gorm:"index" json:"source_id,omitempty"` // Verweis auf strukturierte Quelle - PageNumber int `json:"page_number,omitempty"` // Seitenzahl im Quellenbuch - Bonus int `json:"bonus"` - Stufe int `json:"level"` - AP string `gorm:"default:1" json:"ap"` - Art string `gorm:"default:Gestenzauber" json:"art"` - Zauberdauer string `gorm:"default:10 sec" json:"zauberdauer"` - Reichweite string `json:"reichweite"` // in m - Wirkungsziel string `json:"wirkungsziel"` - Wirkungsbereich string `json:"wirkungsbereich"` - Wirkungsdauer string `json:"wirkungsdauer"` - Ursprung string `json:"ursprung"` - Category string `gorm:"default:normal" json:"category"` // spell_school + ID uint `gorm:"primaryKey" json:"id"` + GameSystem string `gorm:"column:game_system;index;default:midgard" json:"game_system"` + Name string `gorm:"type:varchar(255);index" json:"name"` + Beschreibung string `json:"beschreibung"` + Quelle string `json:"quelle"` // Deprecated: Für Rückwärtskompatibilität + SourceID uint `gorm:"index" json:"source_id,omitempty"` // Verweis auf strukturierte Quelle + PageNumber int `json:"page_number,omitempty"` // Seitenzahl im Quellenbuch + Bonus int `json:"bonus"` + Stufe int `json:"level"` + AP string `gorm:"default:1" json:"ap"` + Art string `gorm:"default:Gestenzauber" json:"art"` + Zauberdauer string `gorm:"default:10 sec" json:"zauberdauer"` + Reichweite string `json:"reichweite"` // in m + Wirkungsziel string `json:"wirkungsziel"` + Wirkungsbereich string `json:"wirkungsbereich"` + Wirkungsdauer string `json:"wirkungsdauer"` + Ursprung string `json:"ursprung"` + Category string `gorm:"default:normal" json:"category"` // spell_school + LearningCategory string `gorm:"type:varchar(25);index" json:"learning_category"` } type Equipment struct { diff --git a/backend/models/model_learning_costs.go b/backend/models/model_learning_costs.go index c6583de..7f2c163 100644 --- a/backend/models/model_learning_costs.go +++ b/backend/models/model_learning_costs.go @@ -373,13 +373,13 @@ func GetSpellLearningInfoNewSystem(spellName string, classCode string) (*SpellLe s.id as spell_id, s.name as spell_name, s.stufe as spell_level, - s.category as school_name, + s.learning_category as school_name, cssec.character_class as class_code, cssec.character_class as class_name, cssec.ep_per_le, COALESCE(sllc.le_required, 0) as le_required FROM gsm_spells s - JOIN learning_class_spell_school_ep_costs cssec ON s.category = cssec.spell_school + JOIN learning_class_spell_school_ep_costs cssec ON s.learning_category = cssec.spell_school LEFT JOIN learning_spell_level_le_costs sllc ON s.stufe = sllc.level WHERE s.name = ? AND cssec.character_class = ? `, spellName, classCode).Scan(&result).Error diff --git a/frontend/CHARACTER_CREATION_DOCS.md b/frontend/CHARACTER_CREATION_DOCS.md new file mode 100644 index 0000000..e69de29 diff --git a/frontend/index.html b/frontend/index.html index 85113b8..df51194 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -5,7 +5,7 @@ -