2023-12-20 07:03:03 +00:00
|
|
|
package migrations
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/uptrace/bun"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
migrations.MustRegister(func(ctx context.Context, db *bun.DB) error {
|
|
|
|
_, err := db.ExecContext(ctx, `
|
2023-12-16 07:12:20 +00:00
|
|
|
create table if not exists player_snapshots
|
|
|
|
(
|
2024-01-04 10:44:36 +00:00
|
|
|
?,
|
2023-12-16 07:12:20 +00:00
|
|
|
player_id bigint not null,
|
|
|
|
num_villages bigint default 0,
|
|
|
|
points bigint default 0,
|
|
|
|
rank bigint default 0,
|
|
|
|
tribe_id bigint,
|
|
|
|
server_key varchar(100) not null
|
|
|
|
references servers,
|
|
|
|
date date not null,
|
|
|
|
created_at timestamp with time zone default CURRENT_TIMESTAMP not null,
|
|
|
|
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,
|
|
|
|
unique (player_id, server_key, date),
|
|
|
|
foreign key (player_id, server_key) references players
|
|
|
|
);
|
2024-01-04 10:44:36 +00:00
|
|
|
`, bun.Safe(autoincrementIDColumn(db)))
|
2023-12-20 07:03:03 +00:00
|
|
|
return err
|
|
|
|
}, func(ctx context.Context, db *bun.DB) error {
|
|
|
|
_, err := db.ExecContext(ctx, "drop table if exists player_snapshots cascade;")
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
}
|