core/internal/migrations/20231220052547_create_index...

31 lines
835 B
Go

package migrations
import (
"context"
"github.com/uptrace/bun"
"github.com/uptrace/bun/dialect"
)
//nolint:lll
func init() {
// this index is for Postgres only
migrations.MustRegister(func(ctx context.Context, db *bun.DB) error {
if db.Dialect().Name() != dialect.PG {
return nil
}
_, err := db.ExecContext(
ctx,
`create unique index concurrently if not exists tribe_changes_hash_key
on tribe_changes (hash_record_extended(
ROW (player_id, new_tribe_id, old_tribe_id, server_key, date_trunc('hours'::text, (created_at AT TIME ZONE 'UTC'::text))),
0::bigint));`,
)
return err
}, func(ctx context.Context, db *bun.DB) error {
_, err := db.NewDropIndex().IfExists().Index("tribe_changes_hash_key").Concurrently().Exec(ctx)
return err
})
}