45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package migrations
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"fmt"
|
|
|
|
"github.com/uptrace/bun"
|
|
)
|
|
|
|
func init() {
|
|
migrations.MustRegister(func(ctx context.Context, db *bun.DB) error {
|
|
return db.RunInTx(ctx, &sql.TxOptions{}, func(ctx context.Context, tx bun.Tx) error {
|
|
for oldColumn, newColumn := range getColumnsToRename20240504051104() {
|
|
_, err := tx.ExecContext(ctx, "ALTER TABLE servers RENAME COLUMN ? TO ?", bun.Safe(oldColumn), bun.Safe(newColumn))
|
|
if err != nil {
|
|
return fmt.Errorf("%s: %w", oldColumn, err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
})
|
|
}, func(ctx context.Context, db *bun.DB) error {
|
|
return db.RunInTx(ctx, &sql.TxOptions{}, func(ctx context.Context, tx bun.Tx) error {
|
|
for oldColumn, newColumn := range getColumnsToRename20240504051104() {
|
|
_, err := tx.ExecContext(ctx, "ALTER TABLE servers RENAME COLUMN ? TO ?", bun.Safe(newColumn), bun.Safe(oldColumn))
|
|
if err != nil {
|
|
return fmt.Errorf("%s: %w", newColumn, err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
})
|
|
})
|
|
}
|
|
|
|
func getColumnsToRename20240504051104() map[string]string {
|
|
return map[string]string{
|
|
"player_data_updated_at": "player_data_synced_at",
|
|
"tribe_data_updated_at": "tribe_data_synced_at",
|
|
"village_data_updated_at": "village_data_synced_at",
|
|
"ennoblement_data_updated_at": "ennoblement_data_synced_at",
|
|
}
|
|
}
|