38 lines
1.3 KiB
Go
38 lines
1.3 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 server_snapshots
|
|
(
|
|
?ID_COL,
|
|
server_key varchar(100) not null
|
|
references servers,
|
|
date date not null,
|
|
created_at timestamp with time zone default CURRENT_TIMESTAMP not null,
|
|
num_players bigint default 0,
|
|
num_active_players bigint default 0,
|
|
num_inactive_players bigint default 0,
|
|
num_tribes bigint default 0,
|
|
num_active_tribes bigint default 0,
|
|
num_inactive_tribes bigint default 0,
|
|
num_villages bigint default 0,
|
|
num_player_villages bigint default 0,
|
|
num_barbarian_villages bigint default 0,
|
|
num_bonus_villages bigint default 0,
|
|
unique (server_key, date)
|
|
);
|
|
`)
|
|
return err
|
|
}, func(ctx context.Context, db *bun.DB) error {
|
|
_, err := db.ExecContext(ctx, "drop table if exists server_snapshots cascade;")
|
|
return err
|
|
})
|
|
}
|