core/internal/bun/migrations/20231220051107_create_playe...

52 lines
2.0 KiB
Go

package migrations
import (
"context"
"github.com/uptrace/bun"
)
func init() {
migrations.MustRegister(func(ctx context.Context, db *bun.DB) error {
_, err := db.ExecContext(ctx, `
create table if not exists players
(
id bigint not null,
server_key varchar(100) not null
references servers,
name varchar(150) not null,
num_villages bigint default 0,
points bigint default 0,
rank bigint default 0,
tribe_id bigint,
created_at timestamp with time zone default CURRENT_TIMESTAMP not null,
deleted_at timestamp with time zone,
rank_att bigint default 0,
score_att bigint default 0,
rank_def bigint default 0,
score_def bigint default 0,
rank_sup bigint default 0,
score_sup bigint default 0,
rank_total bigint default 0,
score_total bigint default 0,
profile_url varchar(150),
best_rank bigint default 999999,
best_rank_at timestamp with time zone default CURRENT_TIMESTAMP not null,
most_points bigint default 0,
most_points_at timestamp with time zone default CURRENT_TIMESTAMP not null,
most_villages bigint default 0,
most_villages_at timestamp with time zone default CURRENT_TIMESTAMP not null,
last_activity_at timestamp with time zone default CURRENT_TIMESTAMP not null,
primary key (id, server_key)
);
create index if not exists players_server_key_idx
on players (server_key);
`)
return err
}, func(ctx context.Context, db *bun.DB) error {
_, err := db.ExecContext(ctx, "drop table if exists players cascade;")
return err
})
}