bump db & fix imports
Signed-off-by: Ben Hall <ben@benh.codes>
This commit is contained in:
parent
068f36a5e4
commit
34027ad95a
@ -922,7 +922,7 @@ func ImportHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
ticketsToCreate := make([]database2.Ticket, len(data.Tickets))
|
ticketsToCreate := make([]database2.Ticket, len(data.Tickets))
|
||||||
ticketIdMap = make(map[int]int)
|
ticketIdMapTwo := make(map[int]int)
|
||||||
|
|
||||||
// Import tickets
|
// Import tickets
|
||||||
for i, ticket := range data.Tickets {
|
for i, ticket := range data.Tickets {
|
||||||
@ -949,7 +949,7 @@ func ImportHandler(ctx *gin.Context) {
|
|||||||
NotesThreadId: ticket.NotesThreadId,
|
NotesThreadId: ticket.NotesThreadId,
|
||||||
}
|
}
|
||||||
|
|
||||||
ticketIdMap[ticket.Id] = ticket.Id + ticketCount
|
ticketIdMapTwo[ticket.Id] = ticket.Id + ticketCount
|
||||||
} else {
|
} else {
|
||||||
skippedItems = append(skippedItems, fmt.Sprintf("Ticket (ID: %d)", ticket.Id))
|
skippedItems = append(skippedItems, fmt.Sprintf("Ticket (ID: %d)", ticket.Id))
|
||||||
}
|
}
|
||||||
@ -964,7 +964,7 @@ func ImportHandler(ctx *gin.Context) {
|
|||||||
|
|
||||||
// Update the mapping
|
// Update the mapping
|
||||||
log.Logger.Info("Importing mapping for tickets", zap.Uint64("guild", guildId))
|
log.Logger.Info("Importing mapping for tickets", zap.Uint64("guild", guildId))
|
||||||
for area, m := range map[string]map[int]int{"ticket": ticketIdMap} {
|
for area, m := range map[string]map[int]int{"ticket": ticketIdMapTwo} {
|
||||||
for sourceId, targetId := range m {
|
for sourceId, targetId := range m {
|
||||||
if err := dbclient.Client2.ImportMappingTable.Set(queryCtx, guildId, area, sourceId, targetId); err != nil {
|
if err := dbclient.Client2.ImportMappingTable.Set(queryCtx, guildId, area, sourceId, targetId); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
@ -976,7 +976,7 @@ func ImportHandler(ctx *gin.Context) {
|
|||||||
ticketsExtrasGroup, _ := errgroup.WithContext(queryCtx)
|
ticketsExtrasGroup, _ := errgroup.WithContext(queryCtx)
|
||||||
|
|
||||||
ticketsExtrasGroup.Go(func() (err error) {
|
ticketsExtrasGroup.Go(func() (err error) {
|
||||||
log.Logger.Info("Importing ticket messages", zap.Uint64("guild", guildId))
|
log.Logger.Info("Importing ticket members", zap.Uint64("guild", guildId))
|
||||||
newMembersMap := make(map[int][]uint64)
|
newMembersMap := make(map[int][]uint64)
|
||||||
for ticketId, members := range data.TicketAdditionalMembers {
|
for ticketId, members := range data.TicketAdditionalMembers {
|
||||||
if _, ok := ticketIdMap[ticketId]; !ok {
|
if _, ok := ticketIdMap[ticketId]; !ok {
|
||||||
@ -998,35 +998,24 @@ func ImportHandler(ctx *gin.Context) {
|
|||||||
// Import ticket last messages
|
// Import ticket last messages
|
||||||
ticketsExtrasGroup.Go(func() (err error) {
|
ticketsExtrasGroup.Go(func() (err error) {
|
||||||
log.Logger.Info("Importing ticket last messages", zap.Uint64("guild", guildId))
|
log.Logger.Info("Importing ticket last messages", zap.Uint64("guild", guildId))
|
||||||
failedLastMessages := 0
|
msgs := map[int]database2.TicketLastMessage{}
|
||||||
for _, msg := range data.TicketLastMessages {
|
for _, msg := range data.TicketLastMessages {
|
||||||
if _, ok := ticketIdMap[msg.TicketId]; !ok {
|
if _, ok := ticketIdMap[msg.TicketId]; !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
lastMessageId := uint64(0)
|
|
||||||
if msg.Data.LastMessageId != nil {
|
|
||||||
lastMessageId = *msg.Data.LastMessageId
|
|
||||||
}
|
|
||||||
|
|
||||||
userId := uint64(0)
|
msgs[ticketIdMap[msg.TicketId]] = database2.TicketLastMessage{
|
||||||
if msg.Data.UserId != nil {
|
LastMessageId: msg.Data.LastMessageId,
|
||||||
userId = *msg.Data.UserId
|
LastMessageTime: msg.Data.LastMessageTime,
|
||||||
}
|
UserId: msg.Data.UserId,
|
||||||
|
UserIsStaff: msg.Data.UserIsStaff,
|
||||||
userIsStaff := false
|
|
||||||
if msg.Data.UserIsStaff != nil {
|
|
||||||
userIsStaff = *msg.Data.UserIsStaff
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := dbclient.Client.TicketLastMessage.Set(queryCtx, guildId, ticketIdMap[msg.TicketId], lastMessageId, userId, userIsStaff); err != nil {
|
|
||||||
failedLastMessages++
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if failedLastMessages == 0 {
|
if err := dbclient.Client2.TicketLastMessage.ImportBulk(queryCtx, guildId, msgs); err != nil {
|
||||||
successfulItems = append(successfulItems, "Ticket Last Messages")
|
failedItems = append(failedItems, "Ticket Last Messages")
|
||||||
} else {
|
} else {
|
||||||
failedItems = append(failedItems, fmt.Sprintf("Ticket Last Messages (x%d)", failedLastMessages))
|
successfulItems = append(successfulItems, "Ticket Last Messages")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
@ -1054,10 +1043,10 @@ func ImportHandler(ctx *gin.Context) {
|
|||||||
log.Logger.Info("Importing ticket ratings", zap.Uint64("guild", guildId))
|
log.Logger.Info("Importing ticket ratings", zap.Uint64("guild", guildId))
|
||||||
newRatingsMap := make(map[int]uint8)
|
newRatingsMap := make(map[int]uint8)
|
||||||
for ticketId, rating := range data.ServiceRatings {
|
for ticketId, rating := range data.ServiceRatings {
|
||||||
if _, ok := ticketIdMap[ticketId]; !ok {
|
if _, ok := ticketIdMapTwo[ticketId]; !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
newRatingsMap[ticketIdMap[ticketId]] = uint8(rating.Data)
|
newRatingsMap[ticketIdMapTwo[ticketId]] = uint8(rating.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client2.ServiceRatings.ImportBulk(queryCtx, guildId, newRatingsMap); err != nil {
|
if err := dbclient.Client2.ServiceRatings.ImportBulk(queryCtx, guildId, newRatingsMap); err != nil {
|
||||||
@ -1073,10 +1062,10 @@ func ImportHandler(ctx *gin.Context) {
|
|||||||
log.Logger.Info("Importing ticket participants", zap.Uint64("guild", guildId))
|
log.Logger.Info("Importing ticket participants", zap.Uint64("guild", guildId))
|
||||||
newParticipantsMap := make(map[int][]uint64)
|
newParticipantsMap := make(map[int][]uint64)
|
||||||
for ticketId, participants := range data.Participants {
|
for ticketId, participants := range data.Participants {
|
||||||
if _, ok := ticketIdMap[ticketId]; !ok {
|
if _, ok := ticketIdMapTwo[ticketId]; !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
newParticipantsMap[ticketIdMap[ticketId]] = participants
|
newParticipantsMap[ticketIdMapTwo[ticketId]] = participants
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client2.Participants.ImportBulk(queryCtx, guildId, newParticipantsMap); err != nil {
|
if err := dbclient.Client2.Participants.ImportBulk(queryCtx, guildId, newParticipantsMap); err != nil {
|
||||||
@ -1092,10 +1081,10 @@ func ImportHandler(ctx *gin.Context) {
|
|||||||
failedFirstResponseTimes := 0
|
failedFirstResponseTimes := 0
|
||||||
log.Logger.Info("Importing first response times", zap.Uint64("guild", guildId))
|
log.Logger.Info("Importing first response times", zap.Uint64("guild", guildId))
|
||||||
for _, frt := range data.FirstResponseTimes {
|
for _, frt := range data.FirstResponseTimes {
|
||||||
if _, ok := ticketIdMap[frt.TicketId]; !ok {
|
if _, ok := ticketIdMapTwo[frt.TicketId]; !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := dbclient.Client.FirstResponseTime.Set(queryCtx, guildId, frt.UserId, ticketIdMap[frt.TicketId], frt.ResponseTime); err != nil {
|
if err := dbclient.Client.FirstResponseTime.Set(queryCtx, guildId, frt.UserId, ticketIdMapTwo[frt.TicketId], frt.ResponseTime); err != nil {
|
||||||
failedFirstResponseTimes++
|
failedFirstResponseTimes++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1112,14 +1101,14 @@ func ImportHandler(ctx *gin.Context) {
|
|||||||
log.Logger.Info("Importing ticket survey responses", zap.Uint64("guild", guildId))
|
log.Logger.Info("Importing ticket survey responses", zap.Uint64("guild", guildId))
|
||||||
failedSurveyResponses := 0
|
failedSurveyResponses := 0
|
||||||
for _, response := range data.ExitSurveyResponses {
|
for _, response := range data.ExitSurveyResponses {
|
||||||
if _, ok := ticketIdMap[response.TicketId]; !ok {
|
if _, ok := ticketIdMapTwo[response.TicketId]; !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
resps := map[int]string{
|
resps := map[int]string{
|
||||||
*response.Data.QuestionId: *response.Data.Response,
|
*response.Data.QuestionId: *response.Data.Response,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client.ExitSurveyResponses.AddResponses(queryCtx, guildId, ticketIdMap[response.TicketId], formIdMap[*response.Data.FormId], resps); err != nil {
|
if err := dbclient.Client.ExitSurveyResponses.AddResponses(queryCtx, guildId, ticketIdMapTwo[response.TicketId], formIdMap[*response.Data.FormId], resps); err != nil {
|
||||||
failedSurveyResponses++
|
failedSurveyResponses++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1137,10 +1126,10 @@ func ImportHandler(ctx *gin.Context) {
|
|||||||
log.Logger.Info("Importing close reasons", zap.Uint64("guild", guildId))
|
log.Logger.Info("Importing close reasons", zap.Uint64("guild", guildId))
|
||||||
failedCloseReasons := 0
|
failedCloseReasons := 0
|
||||||
for _, reason := range data.CloseReasons {
|
for _, reason := range data.CloseReasons {
|
||||||
if _, ok := ticketIdMap[reason.TicketId]; !ok {
|
if _, ok := ticketIdMapTwo[reason.TicketId]; !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := dbclient.Client.CloseReason.Set(queryCtx, guildId, ticketIdMap[reason.TicketId], reason.Data); err != nil {
|
if err := dbclient.Client.CloseReason.Set(queryCtx, guildId, ticketIdMapTwo[reason.TicketId], reason.Data); err != nil {
|
||||||
failedCloseReasons++
|
failedCloseReasons++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1158,10 +1147,10 @@ func ImportHandler(ctx *gin.Context) {
|
|||||||
failedAutocloseExcluded := 0
|
failedAutocloseExcluded := 0
|
||||||
log.Logger.Info("Importing autoclose excluded tickets", zap.Uint64("guild", guildId))
|
log.Logger.Info("Importing autoclose excluded tickets", zap.Uint64("guild", guildId))
|
||||||
for _, ticketId := range data.AutocloseExcluded {
|
for _, ticketId := range data.AutocloseExcluded {
|
||||||
if _, ok := ticketIdMap[ticketId]; !ok {
|
if _, ok := ticketIdMapTwo[ticketId]; !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := dbclient.Client.AutoCloseExclude.Exclude(queryCtx, guildId, ticketIdMap[ticketId]); err != nil {
|
if err := dbclient.Client.AutoCloseExclude.Exclude(queryCtx, guildId, ticketIdMapTwo[ticketId]); err != nil {
|
||||||
failedAutocloseExcluded++
|
failedAutocloseExcluded++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1179,10 +1168,10 @@ func ImportHandler(ctx *gin.Context) {
|
|||||||
log.Logger.Info("Importing archive messages", zap.Uint64("guild", guildId))
|
log.Logger.Info("Importing archive messages", zap.Uint64("guild", guildId))
|
||||||
failedArchiveMessages := 0
|
failedArchiveMessages := 0
|
||||||
for _, message := range data.ArchiveMessages {
|
for _, message := range data.ArchiveMessages {
|
||||||
if _, ok := ticketIdMap[message.TicketId]; !ok {
|
if _, ok := ticketIdMapTwo[message.TicketId]; !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := dbclient.Client.ArchiveMessages.Set(queryCtx, guildId, ticketIdMap[message.TicketId], message.Data.ChannelId, message.Data.MessageId); err != nil {
|
if err := dbclient.Client.ArchiveMessages.Set(queryCtx, guildId, ticketIdMapTwo[message.TicketId], message.Data.ChannelId, message.Data.MessageId); err != nil {
|
||||||
failedArchiveMessages++
|
failedArchiveMessages++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -7,7 +7,7 @@ go 1.22.6
|
|||||||
require (
|
require (
|
||||||
github.com/BurntSushi/toml v1.2.1
|
github.com/BurntSushi/toml v1.2.1
|
||||||
github.com/TicketsBot-cloud/archiverclient v0.0.0-20250206203822-d4f91573ad70
|
github.com/TicketsBot-cloud/archiverclient v0.0.0-20250206203822-d4f91573ad70
|
||||||
github.com/TicketsBot-cloud/database v0.0.0-20250209183433-92dad7c593f6
|
github.com/TicketsBot-cloud/database v0.0.0-20250215204312-d433be0833c9
|
||||||
github.com/TicketsBot/common v0.0.0-20241117150316-ff54c97b45c1
|
github.com/TicketsBot/common v0.0.0-20241117150316-ff54c97b45c1
|
||||||
github.com/TicketsBot/database v0.0.0-20250205194156-c8239ae6eb4e
|
github.com/TicketsBot/database v0.0.0-20250205194156-c8239ae6eb4e
|
||||||
github.com/TicketsBot/logarchiver v0.0.0-20241012220745-5f3ba17a5138
|
github.com/TicketsBot/logarchiver v0.0.0-20241012220745-5f3ba17a5138
|
||||||
|
4
go.sum
4
go.sum
@ -45,8 +45,8 @@ github.com/TicketsBot-cloud/archiverclient v0.0.0-20250206203822-d4f91573ad70 h1
|
|||||||
github.com/TicketsBot-cloud/archiverclient v0.0.0-20250206203822-d4f91573ad70/go.mod h1:BtS3JYHIuRStuUm909E7IDAwg7aAuiS5CNfIH5Y+Ayw=
|
github.com/TicketsBot-cloud/archiverclient v0.0.0-20250206203822-d4f91573ad70/go.mod h1:BtS3JYHIuRStuUm909E7IDAwg7aAuiS5CNfIH5Y+Ayw=
|
||||||
github.com/TicketsBot-cloud/common v0.0.0-20250208140430-b5da1dd487b3 h1:2rpwH5o8negd0BCqWG8xv9r0jh/fYK3P/V3WJ+yFDKs=
|
github.com/TicketsBot-cloud/common v0.0.0-20250208140430-b5da1dd487b3 h1:2rpwH5o8negd0BCqWG8xv9r0jh/fYK3P/V3WJ+yFDKs=
|
||||||
github.com/TicketsBot-cloud/common v0.0.0-20250208140430-b5da1dd487b3/go.mod h1:gn88nKOiWkAgFhhTyuuo+sPFAQEVdTK+P/VXAxOBKNw=
|
github.com/TicketsBot-cloud/common v0.0.0-20250208140430-b5da1dd487b3/go.mod h1:gn88nKOiWkAgFhhTyuuo+sPFAQEVdTK+P/VXAxOBKNw=
|
||||||
github.com/TicketsBot-cloud/database v0.0.0-20250209183433-92dad7c593f6 h1:sllM5xdcCSDk5h26fjNEGCE4rT3NsJjriD82pjutJ/I=
|
github.com/TicketsBot-cloud/database v0.0.0-20250215204312-d433be0833c9 h1:ByFdW+kTUS2AorJbGiHap1tkQWNBcCbmDjHvTMe8vK8=
|
||||||
github.com/TicketsBot-cloud/database v0.0.0-20250209183433-92dad7c593f6/go.mod h1:LPDEn9e5wccH7rq/pUlVcL3UhyLnnwdM2dhj0tp/ljo=
|
github.com/TicketsBot-cloud/database v0.0.0-20250215204312-d433be0833c9/go.mod h1:LPDEn9e5wccH7rq/pUlVcL3UhyLnnwdM2dhj0tp/ljo=
|
||||||
github.com/TicketsBot/analytics-client v0.0.0-20240724103359-30f5dac821e6 h1:JigBTrKv/wRkCnz0G9m/EsqmG5DU6pFWBtrXNhcvK3E=
|
github.com/TicketsBot/analytics-client v0.0.0-20240724103359-30f5dac821e6 h1:JigBTrKv/wRkCnz0G9m/EsqmG5DU6pFWBtrXNhcvK3E=
|
||||||
github.com/TicketsBot/analytics-client v0.0.0-20240724103359-30f5dac821e6/go.mod h1:9Z9qP/yovb6DUe1KlzgN2wicc+8ey6MMoxfynFbMyRg=
|
github.com/TicketsBot/analytics-client v0.0.0-20240724103359-30f5dac821e6/go.mod h1:9Z9qP/yovb6DUe1KlzgN2wicc+8ey6MMoxfynFbMyRg=
|
||||||
github.com/TicketsBot/archiverclient v0.0.0-20241012221057-16a920bfb454 h1:u77mqvmLdljjircnvgikSWNOSyc2uSLLybPOQP8moK8=
|
github.com/TicketsBot/archiverclient v0.0.0-20241012221057-16a920bfb454 h1:u77mqvmLdljjircnvgikSWNOSyc2uSLLybPOQP8moK8=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user