mirror of
https://github.com/kristoferssolo/echoes-of-ascension.git
synced 2026-03-22 00:26:26 +00:00
feat(migrations): migrate old code
This commit is contained in:
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;
|
||||
|
||||
28
migrations/20250125123853_init.up.sql
Normal file
28
migrations/20250125123853_init.up.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
-- Add up migration script here
|
||||
-- Enable UUID support
|
||||
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
|
||||
|
||||
-- Users table with login codes
|
||||
CREATE TABLE IF NOT EXISTS "user" (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid (),
|
||||
username varchar(255) NOT NULL UNIQUE,
|
||||
code varchar(255) NOT NULL UNIQUE,
|
||||
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Scores table with detailed game stats
|
||||
CREATE TABLE IF NOT EXISTS score (
|
||||
id bigserial PRIMARY KEY,
|
||||
user_id uuid NOT NULL,
|
||||
score integer NOT NULL,
|
||||
floor_reached integer NOT NULL,
|
||||
play_time_seconds integer NOT NULL,
|
||||
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES "user" (id)
|
||||
);
|
||||
|
||||
-- Indexes for performance
|
||||
CREATE INDEX idx_user_login ON "user" (code);
|
||||
|
||||
CREATE INDEX idx_scores_user_score ON score (user_id, score DESC);
|
||||
|
||||
Reference in New Issue
Block a user