This commit is contained in:
2025-09-11 17:05:56 +02:00
parent 5b1a528748
commit 7b604df87c
3 changed files with 235 additions and 101 deletions

View File

@@ -21,56 +21,60 @@ const migrations = [
name: "init",
up: async (conn) => {
await conn.query(`
CREATE TABLE IF NOT EXISTS users (
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(255) NOT NULL
username VARCHAR(32),
input_method INT
)
`);
await conn.query(`
CREATE TABLE IF NOT EXISTS user_settings (
user INT NOT NULL,
input_method INT,
PRIMARY KEY (user),
FOREIGN KEY (user) REFERENCES users(id) ON DELETE CASCADE
)
`);
await conn.query(`
CREATE TABLE IF NOT EXISTS games (
CREATE TABLE games (
id INT PRIMARY KEY AUTO_INCREMENT,
winner INT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (winner) REFERENCES users(id) ON DELETE SET NULL
FOREGIN KEY (winner) REFERENCES users(id)
)
`);
await conn.query(`
CREATE TABLE IF NOT EXISTS game_players (
CREATE TABLE current_games (
id INT PRIMARY KEY AUTO_INCREMENT,
game INT NOT NULL,
user INT NOT NULL,
FOREIGN KEY (game) REFERENCES games(id) ON DELETE CASCADE,
FOREIGN KEY (user) REFERENCES users(id) ON DELETE CASCADE,
UNIQUE (game, user)
is_open BOOL,
is_local BOOL,
current_playing_user INT,
turn_order JSON DEFAULT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (current_playing_user) REFERENCES users(id)
)
`);
await conn.query(`
CREATE TABLE IF NOT EXISTS turns (
CREATE TABLE game_players (
id INT PRIMARY KEY AUTO_INCREMENT,
game INT NOT NULL,
user INT NOT NULL,
round_number INT NOT NULL,
game INT,
user INT,
is_creator BOOL,
FOREIGN KEY (game) REFERENCES current_games(id),
FOREIGN KEY (user) REFERENCES users(id)
)
`)
await conn.query(`
CREATE TABLE turns (
id INT PRIMARY KEY AUTO_INCREMENT,
game INT,
user INT,
round_number INT,
start_points INT,
first_throw INT,
second_throw INT,
third_throw INT,
end_points INT,
FOREIGN KEY (game) REFERENCES games(id) ON DELETE CASCADE,
FOREIGN KEY (user) REFERENCES users(id) ON DELETE CASCADE
FOREIGN KEY (game) REFERENCES current_games(id),
FOREIGN KEY (user) REFERENCES users(id)
)
`);
`)
}
}
];