script_service.go
1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
}
}