Files

47 lines
1.8 KiB
MySQL
Raw Permalink Normal View History

-- Robot Clash schema v1. Online saves are one JSON document per player; the server changes their economy
-- fields only through game/eco.js (same rules as the client), so a document stays consistent.
CREATE TABLE users (
uid TEXT PRIMARY KEY,
name TEXT NOT NULL, -- display name
uname TEXT UNIQUE, -- login name, lower case (NULL for guests)
email TEXT UNIQUE, -- optional
pass TEXT, -- bcrypt hash (NULL for guests)
role TEXT NOT NULL DEFAULT 'player',-- player | admin
guest INTEGER NOT NULL DEFAULT 0,
created INTEGER NOT NULL,
seen INTEGER NOT NULL
);
CREATE TABLE refresh_tokens (
token TEXT PRIMARY KEY,
uid TEXT NOT NULL REFERENCES users(uid) ON DELETE CASCADE,
exp INTEGER NOT NULL
);
CREATE INDEX refresh_tokens_uid ON refresh_tokens(uid);
CREATE TABLE online_saves (
uid TEXT PRIMARY KEY REFERENCES users(uid) ON DELETE CASCADE,
data TEXT NOT NULL,
fame INTEGER NOT NULL DEFAULT 0, -- copy of data.fame for the ranking
updated INTEGER NOT NULL
);
CREATE INDEX online_saves_fame ON online_saves(fame DESC);
CREATE TABLE campaign_saves ( -- offline campaign mirrored for registered accounts (client-trusted)
uid TEXT PRIMARY KEY REFERENCES users(uid) ON DELETE CASCADE,
data TEXT NOT NULL,
updated INTEGER NOT NULL
);
CREATE TABLE matches (
id TEXT PRIMARY KEY,
seed INTEGER NOT NULL,
arena TEXT NOT NULL,
uid0 TEXT NOT NULL,
uid1 TEXT NOT NULL,
winner INTEGER, -- seat 0 / 1, -1 draw, NULL running
reason TEXT,
started INTEGER NOT NULL,
ended INTEGER
);
CREATE TABLE kv ( -- small settings, e.g. 'live' (admin live control)
key TEXT PRIMARY KEY,
value TEXT NOT NULL
);