forked from baron/baron-sso
테넌트 목록 조회 cursor기반으로 재구성. 사용자 metadata 미사용 필드 제거
This commit is contained in:
34
backend/internal/bootstrap/user_metadata_sanitize.go
Normal file
34
backend/internal/bootstrap/user_metadata_sanitize.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const sanitizeLegacyUserMetadataSQL = `
|
||||
update users
|
||||
set metadata = metadata - 'hanmacFamily' - 'userType',
|
||||
updated_at = now()
|
||||
where metadata ? 'hanmacFamily'
|
||||
or metadata ? 'userType'
|
||||
`
|
||||
|
||||
// SanitizeLegacyUserMetadata removes legacy UI classification flags from Baron user metadata.
|
||||
func SanitizeLegacyUserMetadata(db *gorm.DB) error {
|
||||
if db == nil {
|
||||
return fmt.Errorf("database is not configured")
|
||||
}
|
||||
if !db.Migrator().HasTable("users") {
|
||||
slog.Info("[Bootstrap] Legacy user metadata sanitize skipped because users table does not exist")
|
||||
return nil
|
||||
}
|
||||
|
||||
result := db.Exec(sanitizeLegacyUserMetadataSQL)
|
||||
if result.Error != nil {
|
||||
return fmt.Errorf("sanitize legacy user metadata: %w", result.Error)
|
||||
}
|
||||
slog.Info("[Bootstrap] Legacy user metadata sanitized", "rowsAffected", result.RowsAffected)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user