From f208c72830db27a8e82649a344e58ebcb7c4ceaf Mon Sep 17 00:00:00 2001 From: mudabbir-ahmad Date: Mon, 24 Mar 2025 09:03:42 +0000 Subject: [PATCH] db init update + final clue page update --- app/(main)/clue/[clueId]/page.js | 4 +- clue_hunt.db | Bin 290816 -> 290816 bytes init-schema.sql | 53 +++++++++++++--------- initialise-databse.sql | 75 ------------------------------- 4 files changed, 33 insertions(+), 99 deletions(-) delete mode 100644 initialise-databse.sql diff --git a/app/(main)/clue/[clueId]/page.js b/app/(main)/clue/[clueId]/page.js index 88f37b0..1a9ecef 100644 --- a/app/(main)/clue/[clueId]/page.js +++ b/app/(main)/clue/[clueId]/page.js @@ -948,7 +948,7 @@ export default function CluePage({ params }) { } .clue-title-container { - background-color: #D6BC69; + background-color: #d6bc69; border: 2px solid black; border-bottom: none; border-top-left-radius: 10px; @@ -966,7 +966,7 @@ export default function CluePage({ params }) { } .clue-scroll { - background-color: #D6BC69; + background-color: #d6bc69; border: 2px solid black; border-top: none; border-bottom-left-radius: 10px; diff --git a/clue_hunt.db b/clue_hunt.db index e03209160dc35647a26903d60cb44fa9e273b8c5..6b5c23be74cd0a8984ac2f000ee55c658567c426 100644 GIT binary patch delta 279 zcmZp8AlUFgaDp^r*+dy<#Ulzs=7#UcZg2WByRlyY*>ls*D zU{PdjIIj|{h}p!-aC&_{izqvgVQDz80;bi_LeJ2^6jQ6Ah2gw%xFQohBNJ?jfQ~4G VE5hLjL!cu{!HTxu$z@St0su93NofE8 delta 72 zcmZp8AlUFgaDp^r!9*En#)6Fr&i0I@%}eatm)J7`F%u9oZ(m~1lAyrC&3lAlI^O{% avCW1G%Xpa$=ao*k4`mVEekYejg$V$jS{M2N diff --git a/init-schema.sql b/init-schema.sql index 1bd394b..63fbf07 100644 --- a/init-schema.sql +++ b/init-schema.sql @@ -1,19 +1,21 @@ -- Schema for clue_hunt.db --- Drop tables if they exist +-- Drop tables if they exist (in reverse order of dependencies) DROP TABLE IF EXISTS team_clues; +DROP TABLE IF EXISTS progress; DROP TABLE IF EXISTS clues; DROP TABLE IF EXISTS users; DROP TABLE IF EXISTS teams; -DROP TABLE IF EXISTS game_settings; DROP TABLE IF EXISTS hunts; +DROP TABLE IF EXISTS game_settings; -- Create teams table CREATE TABLE teams ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, code TEXT NOT NULL UNIQUE, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -- Create users table @@ -21,8 +23,9 @@ CREATE TABLE users ( id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT NOT NULL UNIQUE, password TEXT NOT NULL, - role TEXT DEFAULT 'user', + role TEXT DEFAULT 'user' NOT NULL, team_id INTEGER, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE SET NULL ); @@ -31,8 +34,11 @@ CREATE TABLE clues ( id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL, description TEXT NOT NULL, - location TEXT NOT NULL, - qr_code TEXT NOT NULL, + location TEXT, + qr_code TEXT DEFAULT '', + found BOOLEAN DEFAULT FALSE, + skipped BOOLEAN DEFAULT FALSE, + found_at TIMESTAMP, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); @@ -46,6 +52,16 @@ CREATE TABLE team_clues ( FOREIGN KEY (clue_id) REFERENCES clues(id) ON DELETE CASCADE ); +-- Create progress table +CREATE TABLE 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) +); + -- Create hunts table CREATE TABLE hunts ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -55,21 +71,14 @@ CREATE TABLE hunts ( created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); --- Insert a default hunt row +-- Create 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 +); + +-- Insert a default hunt row (only structural setup, no custom values) INSERT INTO hunts (active) SELECT 0 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 -INSERT INTO clues (title, description, location, qr_code) VALUES ('Clue 1', 'Find the red door', 'Location 1', 'QR1'); -INSERT INTO clues (title, description, location, qr_code) VALUES ('Clue 2', 'Look under the bridge', 'Location 2', 'QR2'); -INSERT INTO clues (title, description, location, qr_code) VALUES ('Clue 3', 'Check the library', 'Location 3', 'QR3'); - diff --git a/initialise-databse.sql b/initialise-databse.sql deleted file mode 100644 index 1bd394b..0000000 --- a/initialise-databse.sql +++ /dev/null @@ -1,75 +0,0 @@ --- Schema for clue_hunt.db - --- Drop tables if they exist -DROP TABLE IF EXISTS team_clues; -DROP TABLE IF EXISTS clues; -DROP TABLE IF EXISTS users; -DROP TABLE IF EXISTS teams; -DROP TABLE IF EXISTS game_settings; -DROP TABLE IF EXISTS hunts; - --- Create teams table -CREATE TABLE teams ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - name TEXT NOT NULL, - code TEXT NOT NULL UNIQUE, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP -); - --- Create users table -CREATE TABLE users ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - username TEXT NOT NULL UNIQUE, - password TEXT NOT NULL, - role TEXT DEFAULT 'user', - team_id INTEGER, - FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE SET NULL -); - --- Create clues table -CREATE TABLE clues ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - title TEXT NOT NULL, - description TEXT NOT NULL, - location TEXT NOT NULL, - qr_code TEXT NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP -); - --- Create team_clues table (for tracking which teams have found which clues) -CREATE TABLE team_clues ( - team_id INTEGER NOT NULL, - clue_id INTEGER NOT NULL, - found_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (team_id, clue_id), - FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE CASCADE, - FOREIGN KEY (clue_id) REFERENCES clues(id) ON DELETE CASCADE -); - --- Create hunts table -CREATE TABLE hunts ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - active BOOLEAN DEFAULT 0, - start_time DATETIME DEFAULT NULL, - end_time DATETIME DEFAULT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP -); - --- Insert a default hunt row -INSERT INTO hunts (active) SELECT 0 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 -INSERT INTO clues (title, description, location, qr_code) VALUES ('Clue 1', 'Find the red door', 'Location 1', 'QR1'); -INSERT INTO clues (title, description, location, qr_code) VALUES ('Clue 2', 'Look under the bridge', 'Location 2', 'QR2'); -INSERT INTO clues (title, description, location, qr_code) VALUES ('Clue 3', 'Check the library', 'Location 3', 'QR3'); -