package migration

import (
	"gorm.io/gorm"

	"github.com/tidbcloud/tidb-management-service/nextgen-global-service/infra/repoimpl/schema"
)

// Migration 202608210001 records whether an automatic backup belongs to the
// hourly or daily backup category. Existing backups remain unknown because the
// historical schedule needed for reliable classification is not available.
var _ = AddDBMigrateRecord(
	"202608210001",
	func(db *gorm.DB) error {
		if err := db.AutoMigrate(&schema.Backup{}); err != nil {
			return err
		}
		return db.Unscoped().Model(&schema.Backup{}).
			Where("auto_backup_type IS NULL OR auto_backup_type = ''").
			Update("auto_backup_type", schema.AutoBackupTypeUnknown).Error
	},
)
