we're about to port the chrome-extension. everything else mostly works

This commit is contained in:
cottongin
2025-10-30 13:27:55 -04:00
parent 2db707961c
commit db2a8abe66
29 changed files with 2490 additions and 562 deletions

View File

@@ -5,9 +5,17 @@ const fs = require('fs');
const dbPath = process.env.DB_PATH || path.join(__dirname, 'data', 'jackbox.db');
const dbDir = path.dirname(dbPath);
// Ensure data directory exists
if (!fs.existsSync(dbDir)) {
fs.mkdirSync(dbDir, { recursive: true });
// Ensure data directory exists with proper permissions
try {
if (!fs.existsSync(dbDir)) {
fs.mkdirSync(dbDir, { recursive: true, mode: 0o777 });
}
// Also ensure the directory is writable
fs.accessSync(dbDir, fs.constants.W_OK);
} catch (err) {
console.error(`Error with database directory ${dbDir}:`, err.message);
console.error('Please ensure the directory exists and is writable');
process.exit(1);
}
const db = new Database(dbPath);
@@ -56,10 +64,41 @@ function initializeDatabase() {
game_id INTEGER NOT NULL,
played_at DATETIME DEFAULT CURRENT_TIMESTAMP,
manually_added INTEGER DEFAULT 0,
status TEXT DEFAULT 'played',
FOREIGN KEY (session_id) REFERENCES sessions(id) ON DELETE CASCADE,
FOREIGN KEY (game_id) REFERENCES games(id) ON DELETE CASCADE
)
`);
// Add status column if it doesn't exist (for existing databases)
try {
db.exec(`ALTER TABLE session_games ADD COLUMN status TEXT DEFAULT 'played'`);
} catch (err) {
// Column already exists, ignore error
}
// Add favor_bias column to games if it doesn't exist
try {
db.exec(`ALTER TABLE games ADD COLUMN favor_bias INTEGER DEFAULT 0`);
} catch (err) {
// Column already exists, ignore error
}
// Packs table for pack-level favoriting
db.exec(`
CREATE TABLE IF NOT EXISTS packs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL UNIQUE,
favor_bias INTEGER DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
)
`);
// Populate packs table with unique pack names from games
db.exec(`
INSERT OR IGNORE INTO packs (name)
SELECT DISTINCT pack_name FROM games
`);
// Chat logs table
db.exec(`