From c414cf2d079af0a7a64395430f8d8e313984917d Mon Sep 17 00:00:00 2001 From: Tetardtek Date: Sun, 15 Mar 2026 18:11:42 +0100 Subject: [PATCH] =?UTF-8?q?db(T0):=20schema=20+=20migration=20001=20?= =?UTF-8?q?=E2=80=94=20super=5Foauth=5Fid,=20firstname,=20lastname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tech-lead: overflow granted — gate migration avant Sprint B+C SuperOAuth --- .../001_add_oauth_profile_fields.sql | 12 ++++++++++ Backend/database/schema.sql | 13 ++++++---- Backend/src/models/UserManager.js | 24 ++++++++++++++++--- 3 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 Backend/database/migrations/001_add_oauth_profile_fields.sql diff --git a/Backend/database/migrations/001_add_oauth_profile_fields.sql b/Backend/database/migrations/001_add_oauth_profile_fields.sql new file mode 100644 index 0000000..882b602 --- /dev/null +++ b/Backend/database/migrations/001_add_oauth_profile_fields.sql @@ -0,0 +1,12 @@ +-- Migration 001 — Add OAuth + profile fields +-- Safe: ADD COLUMN NULL only, no data loss +-- Run: mysql -u -p clickerz < migrations/001_add_oauth_profile_fields.sql + +ALTER TABLE users + ADD COLUMN IF NOT EXISTS firstname VARCHAR(50) NULL, + ADD COLUMN IF NOT EXISTS lastname VARCHAR(50) NULL, + ADD COLUMN IF NOT EXISTS super_oauth_id VARCHAR(36) NULL; + +-- Unique index separately (idempotent) +CREATE UNIQUE INDEX IF NOT EXISTS uq_users_super_oauth_id + ON users (super_oauth_id); diff --git a/Backend/database/schema.sql b/Backend/database/schema.sql index d6a9cdb..8c4793d 100755 --- a/Backend/database/schema.sql +++ b/Backend/database/schema.sql @@ -1,9 +1,12 @@ DROP TABLE IF EXISTS users; CREATE TABLE users ( -id INT AUTO_INCREMENT PRIMARY KEY, -nickname VARCHAR(30) NOT NULL, -mail VARCHAR(90) NOT NULL, -password VARCHAR(200) NOT NULL, -tetardcoin INT default 0 + id INT AUTO_INCREMENT PRIMARY KEY, + nickname VARCHAR(30) NOT NULL, + mail VARCHAR(90) NOT NULL, + password VARCHAR(200) NOT NULL, + tetardcoin INT DEFAULT 0, + firstname VARCHAR(50) NULL, + lastname VARCHAR(50) NULL, + super_oauth_id VARCHAR(36) NULL UNIQUE ); diff --git a/Backend/src/models/UserManager.js b/Backend/src/models/UserManager.js index 84eb62a..11970a5 100755 --- a/Backend/src/models/UserManager.js +++ b/Backend/src/models/UserManager.js @@ -7,16 +7,32 @@ class UserManager extends AbstractManager { // The C of CRUD - Create operation async create(user) { - const { nickname, mail, tetardcoin, password } = user; + const { nickname, mail, tetardcoin, password, firstname, lastname } = user; const [result] = await this.database.query( - `INSERT INTO ${this.table} (nickname, mail, tetardcoin, password) VALUES (?, ?, ?, ?)`, - [nickname, mail, tetardcoin, password] + `INSERT INTO ${this.table} (nickname, mail, tetardcoin, password, firstname, lastname) VALUES (?, ?, ?, ?, ?, ?)`, + [nickname, mail, tetardcoin, password, firstname ?? null, lastname ?? null] ); return result.insertId; } + async getBySuperOAuthId(superOAuthId) { + const [rows] = await this.database.query( + `SELECT * FROM ${this.table} WHERE super_oauth_id = ?`, + [superOAuthId] + ); + return rows[0] ?? null; + } + + async linkSuperOAuth(id, superOAuthId) { + const [result] = await this.database.query( + `UPDATE ${this.table} SET super_oauth_id = ? WHERE id = ?`, + [superOAuthId, id] + ); + return result.affectedRows; + } + // The Rs of CRUD - Read operations async read(id, field) { if (field) { @@ -69,6 +85,8 @@ class UserManager extends AbstractManager { "nickname", "tetardcoin", "password", + "firstname", + "lastname", ]; const fieldsToUpdate = Object.keys(updatedFields).filter((field) =>