feat: new rest endpoint - /versions/{code}/servers/{key}/tribes/{id}/tribe-changes
All checks were successful
continuous-integration/drone/pr Build is passing
All checks were successful
continuous-integration/drone/pr Build is passing
This commit is contained in:
parent
3833d4b186
commit
602c94b0c8
|
@ -0,0 +1,58 @@
|
|||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/bundb/internal/model"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Migrations.MustRegister(func(ctx context.Context, db *bun.DB) error {
|
||||
indexes := []struct {
|
||||
idx string
|
||||
columns []string
|
||||
}{
|
||||
{
|
||||
idx: "tribe_changes_server_key_new_tribe_id_idx",
|
||||
columns: []string{"server_key", "new_tribe_id"},
|
||||
},
|
||||
{
|
||||
idx: "tribe_changes_server_key_old_tribe_id_idx",
|
||||
columns: []string{"server_key", "old_tribe_id"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, idx := range indexes {
|
||||
if _, err := db.NewCreateIndex().
|
||||
Model(&model.TribeChange{}).
|
||||
Index(idx.idx).
|
||||
IfNotExists().
|
||||
Column(idx.columns...).
|
||||
Concurrently().
|
||||
Exec(ctx); err != nil {
|
||||
return fmt.Errorf("couldn't create the '%s' index: %w", idx.idx, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}, func(ctx context.Context, db *bun.DB) error {
|
||||
indexes := []string{
|
||||
"tribe_changes_server_key_new_tribe_id_idx",
|
||||
"tribe_changes_server_key_old_tribe_id_idx",
|
||||
}
|
||||
|
||||
for _, idx := range indexes {
|
||||
if _, err := db.NewDropIndex().
|
||||
Model(&model.TribeChange{}).
|
||||
Index(idx).
|
||||
IfExists().
|
||||
Concurrently().
|
||||
Exec(ctx); err != nil {
|
||||
return fmt.Errorf("couldn't drop the '%s' index: %w", idx, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
|
@ -127,8 +127,8 @@ func (l listTribeChangesParamsApplier) applyFilters(q *bun.SelectQuery) *bun.Sel
|
|||
|
||||
if len(l.params.TribeIDs) > 0 {
|
||||
q = q.WhereGroup(" AND ", func(q *bun.SelectQuery) *bun.SelectQuery {
|
||||
return q.WhereOr("tc.new_tribe_id = ?", bun.In(l.params.TribeIDs)).
|
||||
WhereOr("tc.old_tribe_id = ?", bun.In(l.params.TribeIDs))
|
||||
return q.WhereOr("tc.new_tribe_id IN (?)", bun.In(l.params.TribeIDs)).
|
||||
WhereOr("tc.old_tribe_id IN (?)", bun.In(l.params.TribeIDs))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue
Block a user