First commit, phased 1 and 2 created but untested

This commit is contained in:
bepis
2026-10-20 07:40:35 +11:00
commit 7a3e408ffc
66 changed files with 5639 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
const path = require('path');
const Database = require('better-sqlite3');
const config = require('../config');
let db;
function getDb() {
if (!db) {
const dbDir = path.dirname(config.dbPath);
const fs = require('fs');
if (!fs.existsSync(dbDir)) {
fs.mkdirSync(dbDir, { recursive: true });
}
db = new Database(config.dbPath, {
wal: true,
nativeTimeout: 'session',
});
// Configure journal mode and enable foreign keys
db.pragma('journal_mode = WAL');
db.pragma('foreign_keys = ON');
}
return db;
}
module.exports = { getDb };
View File
+10
View File
@@ -0,0 +1,10 @@
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL,
password_hash TEXT NOT NULL,
created_at INTEGER NOT NULL,
last_login_at INTEGER,
is_banned INTEGER NOT NULL DEFAULT 0 CHECK (is_banned IN (0,1))
);
CREATE UNIQUE INDEX idx_users_username_nocase ON users(username COLLATE NOCASE);
+25
View File
@@ -0,0 +1,25 @@
CREATE TABLE characters (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL UNIQUE REFERENCES users(id) ON DELETE CASCADE,
name TEXT NOT NULL,
class TEXT NOT NULL CHECK (class IN ('warrior','mage','ranger')),
level INTEGER NOT NULL DEFAULT 1 CHECK (level >= 1),
xp INTEGER NOT NULL DEFAULT 0 CHECK (xp >= 0),
gold INTEGER NOT NULL DEFAULT 50 CHECK (gold >= 0),
str INTEGER NOT NULL,
agi INTEGER NOT NULL,
int INTEGER NOT NULL,
vit INTEGER NOT NULL,
unspent_points INTEGER NOT NULL DEFAULT 0 CHECK (unspent_points >= 0),
hp_current INTEGER NOT NULL CHECK (hp_current >= 0),
energy INTEGER NOT NULL CHECK (energy >= 0),
energy_updated_at INTEGER NOT NULL,
kills INTEGER NOT NULL DEFAULT 0,
deaths INTEGER NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL
);
CREATE UNIQUE INDEX idx_characters_name_nocase ON characters(name COLLATE NOCASE);
CREATE INDEX idx_characters_level ON characters(level DESC, xp DESC);
CREATE INDEX idx_characters_gold ON characters(gold DESC);
CREATE INDEX idx_characters_kills ON characters(kills DESC);
View File