This commit is contained in:
41666 2024-06-13 22:33:29 -04:00
commit c5cc245e25
29 changed files with 926 additions and 0 deletions

48
store/player.go Normal file
View file

@ -0,0 +1,48 @@
package store
import (
"context"
"database/sql"
"log"
"time"
)
type PlayerStore struct {
DB *sql.DB
}
func NewPlayerStore(db *sql.DB) *PlayerStore {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
ps := &PlayerStore{
DB: db,
}
ps.RunMigration(ctx, false)
return ps
}
func (ps *PlayerStore) RunMigration(ctx context.Context, force bool) {
if !force {
// check if migrated first...
}
log.Println("(Re)-creating players table")
ps.DB.ExecContext(ctx, `
DROP TABLE IF EXISTS players;
CREATE TABLE players (
character_id TEXT NOT NULL PRIMARY KEY,
last_updated TIMESTAMPTZ NOT NULL,
world_id INT NOT NULL,
faction_id INT NOT NULL,
zone_id INT NOT NULL,
class_name TEXT NOT NULL
);
`)
log.Println("Done, players table is initialized.")
}