From 29cb50bb34f5dfd63e3bdd414944654c74c3c372 Mon Sep 17 00:00:00 2001 From: H3ALY Date: Tue, 28 Oct 2025 14:37:05 +0000 Subject: [PATCH] Update users table and fix potential panic as fk references users before its created. --- .../migrations/0001_initial_create.up.sql | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/internal/storage/migrations/0001_initial_create.up.sql b/internal/storage/migrations/0001_initial_create.up.sql index a3d7256..1b76922 100644 --- a/internal/storage/migrations/0001_initial_create.up.sql +++ b/internal/storage/migrations/0001_initial_create.up.sql @@ -4,6 +4,17 @@ -- - utf8mb4 for full Unicode -- Booleans are TINYINT(1). Dates use DATE/DATETIME/TIMESTAMP as appropriate. +-- USERS +CREATE TABLE IF NOT EXISTS users ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + username VARCHAR(191) NOT NULL UNIQUE, + email VARCHAR(255) NOT NULL UNIQUE, + password_hash VARCHAR(255) NOT NULL, + is_admin TINYINT(1) NOT NULL DEFAULT 0, + created_at DATETIME NOT NULL DEFAULT UTC_TIMESTAMP(), + updated_at DATETIME NOT NULL DEFAULT UTC_TIMESTAMP() +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + CREATE TABLE audit_registration ( id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, user_id BIGINT UNSIGNED NOT NULL, @@ -18,14 +29,6 @@ CREATE TABLE audit_registration ( ON DELETE CASCADE ); --- USERS -CREATE TABLE IF NOT EXISTS users ( - id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - username VARCHAR(191) NOT NULL UNIQUE, - password_hash VARCHAR(255) NOT NULL, - is_admin TINYINT(1) NOT NULL DEFAULT 0 -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -- THUNDERBALL RESULTS CREATE TABLE IF NOT EXISTS results_thunderball ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,