feat: user migration

This commit is contained in:
2026-04-28 19:06:42 +08:00
parent aa90b10f06
commit f9077dafcf
6 changed files with 114 additions and 4 deletions
+25
View File
@@ -0,0 +1,25 @@
package models
import "gorm.io/gorm"
func BackfillLegacyUserPermissions(db *gorm.DB) error {
if err := db.Model(&User{}).
Where("role IS NULL OR role = '' OR role = ?", UserRoleViewer).
Update("role", UserRoleOperator).Error; err != nil {
return err
}
if err := db.Model(&User{}).
Where("flavor_type IS NULL OR flavor_type = '' OR flavor_type = ?", UserFlavorAll).
Update("flavor_type", UserFlavorFlink).Error; err != nil {
return err
}
if err := db.Model(&User{}).
Where("is_active IS NULL").
Update("is_active", true).Error; err != nil {
return err
}
return nil
}