script_service.go 1.4 KB
package domainService

import (
	"fmt"
	pG "github.com/linmadan/egglib-go/transaction/pg"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log"
)

func Script() {
	ScriptRenameQuerySetPinName()
}

func ScriptRenameQuerySetPinName() {
	defer func() {
		if p := recover(); p != nil {
			log.Logger.Error(fmt.Sprintf("%v", p))
		}
	}()
	var err error
	transactionContext := pG.NewPGTransactionContext(pg.DB)
	if err != nil {
		return
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return
	}
	defer func() {
		transactionContext.RollbackTransaction()
	}()
	querySetRepository, _ := repository.NewQuerySetRepository(transactionContext)
	_, querySets, _ := querySetRepository.Find(map[string]interface{}{})
	for i := range querySets {
		pinName := pinFull(querySets[i].Name)
		log.Logger.Info(fmt.Sprintf("%v %v -> %v", querySets[i].QuerySetId, querySets[i].Name, querySets[i]))
		querySets[i].PinName = pinName
		_, err := querySetRepository.Save(querySets[i])
		if err != nil {
			log.Logger.Error(err.Error(), map[string]interface{}{"qs": querySets[i]})
		}
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return
	}
}