package migrate

import (
	ccmod "github.com/tidbcloud/devops/models/cloudconfig"

	"gorm.io/gorm"
)

// migration for cloudconfig_configuration_change_to_template tables to add template_type
var _ = AddMigrateRecord(
	"202511181400",
	func(db *gorm.DB) error {
		err := db.AutoMigrate(&ccmod.ConfigurationChangeToTemplate{})
		if err != nil {
			return err
		}

		// update existing records with default template_type 'custom'.
		err = db.Exec("UPDATE cloudconfig_configuration_change_to_template SET template_type = 'custom' WHERE template_type = ''").Error
		if err != nil {
			return err
		}

		return nil
	},
)
