package migrate

import (
	"github.com/pingcap/log"
	"github.com/tidbcloud/chaos-svc/model"
	"gorm.io/gorm"
)

var models = []interface{}{
	&model.ChaosBackend{},
	&model.ChaosBackendOperation{},
	&model.Workflow{},
	&model.WorkflowNode{},
	&model.WorkflowLock{},
}

func initChaosDB(db *gorm.DB) error {
	log.Info("init empty database with data")
	// create the tables in a empty database
	// it is 3 time faster than migrate model individually
	// NOTE: not all models defined in `model.go` are owned by dataflow-service, so we should NOT do the migration for them.
	if err := db.AutoMigrate(models...); err != nil {
		return err
	}
	log.Info("after create database tables")
	return nil
}
