-- Conserver la première lecture de chaque article avant d'imposer l'unicité.
DELETE duplicate_read
FROM `article_reads` AS duplicate_read
INNER JOIN `article_reads` AS retained_read
  ON duplicate_read.`userId` = retained_read.`userId`
  AND duplicate_read.`articleType` = retained_read.`articleType`
  AND duplicate_read.`articleId` = retained_read.`articleId`
  AND duplicate_read.`id` > retained_read.`id`;
--> statement-breakpoint
ALTER TABLE `article_reads` ADD CONSTRAINT `article_reads_user_type_article_unique` UNIQUE(`userId`,`articleType`,`articleId`);
