mirror of
https://github.com/kristoferssolo/echoes-of-ascension.git
synced 2025-10-21 18:50:34 +00:00
feat(db): create initial db
This commit is contained in:
parent
663364b94c
commit
f09238d21d
3
.gitignore
vendored
3
.gitignore
vendored
@ -12,3 +12,6 @@ test-results/
|
||||
end2end/playwright-report/
|
||||
playwright/.cache/
|
||||
bruno/
|
||||
|
||||
.env
|
||||
**/*.db
|
||||
|
||||
49
justfile
49
justfile
@ -1,10 +1,14 @@
|
||||
set dotenv-load
|
||||
|
||||
export RUSTC_WRAPPER:="sccache"
|
||||
# Li st all available commands
|
||||
|
||||
# List all available commands
|
||||
default:
|
||||
@just --list
|
||||
|
||||
# Install required tools and dependencies
|
||||
setup:
|
||||
just db-setup
|
||||
rustup toolchain install nightly
|
||||
rustup default nightly
|
||||
rustup target add wasm32-unknown-unknown
|
||||
@ -15,8 +19,8 @@ setup:
|
||||
# Development Commands
|
||||
|
||||
# Start development server with hot reload
|
||||
dev: kill-server
|
||||
RUST_BACKTRACE=full cargo leptos watch | bunyan
|
||||
dev: kill-server db-setup db-migrate
|
||||
cargo leptos watch | bunyan
|
||||
|
||||
# Run cargo check on both native and wasm targets
|
||||
check:
|
||||
@ -61,16 +65,9 @@ build-wasm:
|
||||
build-server:
|
||||
cargo leptos build-only-server
|
||||
|
||||
# Database Commands (add these when you set up your database)
|
||||
db-setup:
|
||||
echo "Add your database setup commands here"
|
||||
|
||||
db-migrate:
|
||||
echo "Add your database migration commands here"
|
||||
|
||||
# Deployment Commands (customize based on your deployment strategy)
|
||||
# Deployment Commands
|
||||
deploy:
|
||||
echo "Add your deployment commands here"
|
||||
echo "Add deployment commands here"
|
||||
|
||||
# Combined commands
|
||||
check-all: fmt lint check test
|
||||
@ -84,3 +81,31 @@ kill-server:
|
||||
pkill -f "target/debug/server" || true
|
||||
pkill -f "cargo-leptos" || true
|
||||
|
||||
|
||||
# Database Commands
|
||||
|
||||
# Setup the database
|
||||
db-setup:
|
||||
sqlite3 ${DATABASE_URL#sqlite:} ".databases"
|
||||
|
||||
alias migrate:=db-migrate
|
||||
alias m:=db-migrate
|
||||
# Migrate
|
||||
db-migrate:
|
||||
sqlx migrate run
|
||||
|
||||
# Generate sqlx prepare check files
|
||||
db-prepare:
|
||||
sqlx prepare
|
||||
|
||||
# Reset database
|
||||
db-reset:
|
||||
rm -f ${DATABASE_URL#sqlite:}
|
||||
just db-setup
|
||||
just db-migrate
|
||||
|
||||
alias migrations:=db-new-migration
|
||||
# Create new migration
|
||||
db-new-migration name:
|
||||
sqlx migrate add -r {{name}}
|
||||
|
||||
|
||||
11
migrations/20250125123853_init.down.sql
Normal file
11
migrations/20250125123853_init.down.sql
Normal file
@ -0,0 +1,11 @@
|
||||
-- Add down migration script here
|
||||
-- Drop indexes first
|
||||
DROP INDEX IF EXISTS idx_scores_user_score;
|
||||
|
||||
DROP INDEX IF EXISTS idx_users_login;
|
||||
|
||||
-- Drop tables in reverse order of creation
|
||||
DROP TABLE IF EXISTS scores;
|
||||
|
||||
DROP TABLE IF EXISTS users;
|
||||
|
||||
25
migrations/20250125123853_init.up.sql
Normal file
25
migrations/20250125123853_init.up.sql
Normal file
@ -0,0 +1,25 @@
|
||||
-- Add up migration script here
|
||||
-- Users table with login codes
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id integer PRIMARY KEY AUTOINCREMENT,
|
||||
username text NOT NULL UNIQUE,
|
||||
code text NOT NULL UNIQUE,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Scores table with detailed game stats
|
||||
CREATE TABLE IF NOT EXISTS scores (
|
||||
id integer PRIMARY KEY AUTOINCREMENT,
|
||||
user_id integer NOT NULL,
|
||||
score integer NOT NULL,
|
||||
floor_reached integer NOT NULL,
|
||||
play_time_seconds integer NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users (id)
|
||||
);
|
||||
|
||||
-- Indexes for performance
|
||||
CREATE INDEX idx_users_login ON users (code);
|
||||
|
||||
CREATE INDEX idx_scores_user_score ON scores (user_id, score DESC);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user