mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-08 03:50:21 +00:00
Refactor database initialization script; create tables for users, teams, clues, game settings, and hunts with sample data
This commit is contained in:
1 parent
a6ed24b2e6
commit
4f7fdc6ad2
2 files changed
+75
-1
No files matched your search
Binary file not shown.
+75
-1
@@ -1,3 +1,77 @@
|
||||
INSERT INTO users (username, password, role) VALUES ('admin', 'hashed_password', 'admin');
|
||||
-- Schema for clue_hunt.db
|
||||
|
||||
-- Drop tables if they exist
|
||||
DROP TABLE IF EXISTS clues;
|
||||
DROP TABLE IF EXISTS users;
|
||||
DROP TABLE IF EXISTS teams;
|
||||
DROP TABLE IF EXISTS game_settings;
|
||||
|
||||
-- Users table
|
||||
CREATE TABLE users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT UNIQUE NOT NULL,
|
||||
password TEXT NOT NULL,
|
||||
role TEXT NOT NULL DEFAULT 'user',
|
||||
team_id INTEGER, -- Ensure this column exists
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (team_id) REFERENCES teams(id)
|
||||
);
|
||||
|
||||
-- Teams table
|
||||
CREATE TABLE teams (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
code TEXT UNIQUE NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Clues table
|
||||
CREATE TABLE clues (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
description TEXT NOT NULL,
|
||||
team_id INTEGER NOT NULL,
|
||||
found BOOLEAN DEFAULT FALSE,
|
||||
found_at TIMESTAMP,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (team_id) REFERENCES teams(id)
|
||||
);
|
||||
|
||||
-- Game settings table
|
||||
CREATE TABLE game_settings (
|
||||
id INTEGER PRIMARY KEY,
|
||||
hunt_active BOOLEAN DEFAULT FALSE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Execute this in your database:
|
||||
CREATE TABLE IF NOT EXISTS hunts (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
active BOOLEAN DEFAULT FALSE,
|
||||
start_time DATETIME DEFAULT NULL,
|
||||
end_time DATETIME DEFAULT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Insert a default hunt row if none exists:
|
||||
INSERT INTO hunts (active)
|
||||
SELECT FALSE
|
||||
WHERE NOT EXISTS (SELECT 1 FROM hunts LIMIT 1);
|
||||
|
||||
|
||||
|
||||
-- Insert initial admin user
|
||||
INSERT INTO users (username, password, role)
|
||||
VALUES ('admin', '$2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy', 'admin');
|
||||
-- Password is 'password123' - change this in production!
|
||||
|
||||
-- Insert sample teams
|
||||
INSERT INTO teams (name, code) VALUES ('Team Alpha', 'ALPHA123');
|
||||
INSERT INTO teams (name, code) VALUES ('Team Beta', 'BETA456');
|
||||
INSERT INTO teams (name, code) VALUES ('Team Gamma', 'GAMMA789');
|
||||
|
||||
-- Insert sample clues for Team Alpha
|
||||
INSERT INTO clues (description, team_id) VALUES ('Find the red door', 1);
|
||||
INSERT INTO clues (description, team_id) VALUES ('Look under the bridge', 1);
|
||||
INSERT INTO clues (description, team_id) VALUES ('Check the library', 1);
|
||||
|
||||
Reference in new issue
Block a user