feat(skills): 技能管理 - 支持后台维护一级分类 (#694)
Co-authored-by: ddcat666 <26564566+ddcat666@users.noreply.github.com>
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const CurrentSchemaVersion int64 = 46
|
||||
const CurrentSchemaVersion int64 = 47
|
||||
|
||||
const baselineSchemaChecksum = "sha256:open-ai-canvas-schema-v1-20260830"
|
||||
const schemaMigrationAppliedAtIndexChecksum = "sha256:schema-migrations-applied-at-index-v2-20260830"
|
||||
@@ -147,6 +147,7 @@ var schemaMigrations = []migration{
|
||||
return tx.AutoMigrate(&model.TopupProduct{}, &model.PaymentOrder{})
|
||||
}},
|
||||
{version: 46, name: "skill_curation", checksum: "sha256:skill-curation-v46-20261005", apply: migrateSkillCuration},
|
||||
{version: 47, name: "skill_curation_roots", checksum: "sha256:skill-curation-roots-v47-20261005", apply: migrateSkillCurationRoots},
|
||||
}
|
||||
|
||||
func migratePrefixedIDSequenceReconcile(tx *gorm.DB) error {
|
||||
|
||||
15
backend/internal/database/skill_curation_roots.go
Normal file
15
backend/internal/database/skill_curation_roots.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"infinite-canvas/backend/internal/model"
|
||||
)
|
||||
|
||||
func migrateSkillCurationRoots(tx *gorm.DB) error {
|
||||
if err := tx.AutoMigrate(&model.SkillCurationRoot{}, &model.SkillCurationRootAssignment{}); err != nil {
|
||||
return err
|
||||
}
|
||||
roots := model.DefaultSkillCurationRoots()
|
||||
return tx.Clauses(clause.OnConflict{DoNothing: true}).Create(&roots).Error
|
||||
}
|
||||
53
backend/internal/database/skill_curation_roots_test.go
Normal file
53
backend/internal/database/skill_curation_roots_test.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
"infinite-canvas/backend/internal/model"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSkillCurationRootsMigration(t *testing.T) {
|
||||
db, err := gorm.Open(sqlite.Open(filepath.Join(t.TempDir(), "roots.db")), &gorm.Config{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sqlDB, _ := db.DB()
|
||||
defer sqlDB.Close()
|
||||
if err := db.Transaction(migrateSkillCuration); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
db.Create(&model.SkillCurationCategory{ID: "old", Name: "Existing", NormalizedName: "existing", RootTag: "drama", Enabled: true})
|
||||
if err := db.Transaction(migrateSkillCurationRoots); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var roots []model.SkillCurationRoot
|
||||
db.Find(&roots)
|
||||
if len(roots) != 5 {
|
||||
t.Fatalf("neutral defaults: %d", len(roots))
|
||||
}
|
||||
db.Model(&model.SkillCurationRoot{}).Where("id = ?", "drama").Updates(map[string]any{"name": "Edited", "enabled": false})
|
||||
if err := db.Transaction(migrateSkillCurationRoots); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var root model.SkillCurationRoot
|
||||
db.First(&root, "id = ?", "drama")
|
||||
if root.Name != "Edited" || root.Enabled {
|
||||
t.Fatal("migration overwrote root")
|
||||
}
|
||||
var category model.SkillCurationCategory
|
||||
db.First(&category, "id = ?", "old")
|
||||
if category.RootTag != "drama" {
|
||||
t.Fatal("migration changed U39 categories")
|
||||
}
|
||||
found := false
|
||||
for _, m := range schemaMigrations {
|
||||
if m.version == 47 {
|
||||
found = m.name == "skill_curation_roots" && m.checksum == "sha256:skill-curation-roots-v47-20261005"
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatal("migration 47 is not registered")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user