db(T0): schema + migration 001 — super_oauth_id, firstname, lastname
tech-lead: overflow granted — gate migration avant Sprint B+C SuperOAuth
This commit is contained in:
12
Backend/database/migrations/001_add_oauth_profile_fields.sql
Normal file
12
Backend/database/migrations/001_add_oauth_profile_fields.sql
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
-- Migration 001 — Add OAuth + profile fields
|
||||||
|
-- Safe: ADD COLUMN NULL only, no data loss
|
||||||
|
-- Run: mysql -u <user> -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);
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
DROP TABLE IF EXISTS users;
|
DROP TABLE IF EXISTS users;
|
||||||
|
|
||||||
CREATE TABLE users (
|
CREATE TABLE users (
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
nickname VARCHAR(30) NOT NULL,
|
nickname VARCHAR(30) NOT NULL,
|
||||||
mail VARCHAR(90) NOT NULL,
|
mail VARCHAR(90) NOT NULL,
|
||||||
password VARCHAR(200) NOT NULL,
|
password VARCHAR(200) NOT NULL,
|
||||||
tetardcoin INT default 0
|
tetardcoin INT DEFAULT 0,
|
||||||
|
firstname VARCHAR(50) NULL,
|
||||||
|
lastname VARCHAR(50) NULL,
|
||||||
|
super_oauth_id VARCHAR(36) NULL UNIQUE
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -7,16 +7,32 @@ class UserManager extends AbstractManager {
|
|||||||
|
|
||||||
// The C of CRUD - Create operation
|
// The C of CRUD - Create operation
|
||||||
async create(user) {
|
async create(user) {
|
||||||
const { nickname, mail, tetardcoin, password } = user;
|
const { nickname, mail, tetardcoin, password, firstname, lastname } = user;
|
||||||
|
|
||||||
const [result] = await this.database.query(
|
const [result] = await this.database.query(
|
||||||
`INSERT INTO ${this.table} (nickname, mail, tetardcoin, password) VALUES (?, ?, ?, ?)`,
|
`INSERT INTO ${this.table} (nickname, mail, tetardcoin, password, firstname, lastname) VALUES (?, ?, ?, ?, ?, ?)`,
|
||||||
[nickname, mail, tetardcoin, password]
|
[nickname, mail, tetardcoin, password, firstname ?? null, lastname ?? null]
|
||||||
);
|
);
|
||||||
|
|
||||||
return result.insertId;
|
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
|
// The Rs of CRUD - Read operations
|
||||||
async read(id, field) {
|
async read(id, field) {
|
||||||
if (field) {
|
if (field) {
|
||||||
@@ -69,6 +85,8 @@ class UserManager extends AbstractManager {
|
|||||||
"nickname",
|
"nickname",
|
||||||
"tetardcoin",
|
"tetardcoin",
|
||||||
"password",
|
"password",
|
||||||
|
"firstname",
|
||||||
|
"lastname",
|
||||||
];
|
];
|
||||||
|
|
||||||
const fieldsToUpdate = Object.keys(updatedFields).filter((field) =>
|
const fieldsToUpdate = Object.keys(updatedFields).filter((field) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user