mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
redo of entire app
This commit is contained in:
1 parent
7dee4879a7
commit
093dd7ea9e
45 files changed
+686
-5659
No files matched your search
@@ -0,0 +1,61 @@
|
||||
import sqlite3 from 'sqlite3';
|
||||
import { open } from 'sqlite';
|
||||
import bcrypt from 'bcryptjs';
|
||||
|
||||
async function initDb() {
|
||||
const db = await open({
|
||||
filename: './clue_hunt.db',
|
||||
driver: sqlite3.Database,
|
||||
});
|
||||
|
||||
// Create tables
|
||||
await db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT NOT NULL UNIQUE,
|
||||
password TEXT NOT NULL,
|
||||
role TEXT NOT NULL DEFAULT 'user'
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS teams (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
code TEXT NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS clues (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
description TEXT NOT NULL,
|
||||
found BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
skipped BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
team_id INTEGER,
|
||||
FOREIGN KEY (team_id) REFERENCES teams(id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS progress (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
team_id INTEGER,
|
||||
clue_id INTEGER,
|
||||
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (team_id) REFERENCES teams(id),
|
||||
FOREIGN KEY (clue_id) REFERENCES clues(id)
|
||||
);
|
||||
`);
|
||||
|
||||
// Seed initial data
|
||||
const hashedPassword = bcrypt.hashSync('admin', 10);
|
||||
await db.run(
|
||||
'INSERT OR IGNORE INTO users (username, password, role) VALUES (?, ?, ?)',
|
||||
['admin', hashedPassword, 'admin']
|
||||
);
|
||||
|
||||
await db.run(
|
||||
'INSERT OR IGNORE INTO teams (name, code) VALUES (?, ?)',
|
||||
['Team Alpha', 'ALPHA123']
|
||||
);
|
||||
|
||||
console.log('Database initialized successfully.');
|
||||
await db.close();
|
||||
}
|
||||
|
||||
initDb().catch((err) => console.error('Error initializing database:', err));
|
||||
Reference in new issue
Block a user