Problème identifié : - La contrainte UNIQUE sur la colonne openId n'existait pas dans la base de données - Tous les utilisateurs partageaient le même openId - Chaque connexion créait un nouvel utilisateur au lieu de mettre à jour l'existant - 344 utilisateurs en double ont été créés Solution appliquée : - Nettoyé 343 utilisateurs en double (gardé le plus récent pour chaque openId) - Ajouté la contrainte UNIQUE sur la colonne openId via ALTER TABLE - Maintenant onDuplicateKeyUpdate fonctionne correctement Résultat : - Plus aucun utilisateur en double ne sera créé - À chaque connexion, l'utilisateur existant est mis à jour - Table users propre avec seulement les utilisateurs uniques
29 lines
2.0 KiB
JSON
29 lines
2.0 KiB
JSON
{
|
|
"query": "SHOW CREATE TABLE users",
|
|
"command": "mysql --batch --raw --column-names --default-character-set=utf8mb4 --host gateway02.us-east-1.prod.aws.tidbcloud.com --port 4000 --user 4CrrYuB5tme73Qo.root --database 7PAT67UmWoxv8vwp8Bbcv6 --execute SHOW CREATE TABLE users",
|
|
"rows": [
|
|
{
|
|
"Table": "users",
|
|
"Create Table": "CREATE TABLE `users` ("
|
|
}
|
|
],
|
|
"messages": [
|
|
" `id` int(11) NOT NULL AUTO_INCREMENT,",
|
|
" `name` text DEFAULT NULL,",
|
|
" `email` varchar(320) DEFAULT NULL,",
|
|
" `role` enum('user','admin') NOT NULL DEFAULT 'user',",
|
|
" `createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,",
|
|
" `updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,",
|
|
" `lastSignedIn` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,",
|
|
" `isActive` tinyint(1) NOT NULL DEFAULT '1',",
|
|
" `password` varchar(255) DEFAULT NULL,",
|
|
" `emailVerified` tinyint(1) NOT NULL DEFAULT '0',",
|
|
" `openId` varchar(64) NOT NULL,",
|
|
" `loginMethod` varchar(64) DEFAULT NULL,",
|
|
" PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */",
|
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=2880001"
|
|
],
|
|
"stdout": "Table\tCreate Table\nusers\tCREATE TABLE `users` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `name` text DEFAULT NULL,\n `email` varchar(320) DEFAULT NULL,\n `role` enum('user','admin') NOT NULL DEFAULT 'user',\n `createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n `updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n `lastSignedIn` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n `isActive` tinyint(1) NOT NULL DEFAULT '1',\n `password` varchar(255) DEFAULT NULL,\n `emailVerified` tinyint(1) NOT NULL DEFAULT '0',\n `openId` varchar(64) NOT NULL,\n `loginMethod` varchar(64) DEFAULT NULL,\n PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=2880001\n",
|
|
"stderr": "",
|
|
"execution_time_ms": 49
|
|
} |