-- NyakisiiCabs: schema changes since the previous package. Import once, after any older upgrade files you have not imported yet.
-- Generated by "npm run package" on 2026-12-02T09:23:46.477Z. Import in phpMyAdmin: select the database, Import, choose this file, Go.

-- AlterTable
ALTER TABLE `User` ADD COLUMN `emailVerifiedAt` DATETIME(3) NULL,
    MODIFY `phone` VARCHAR(16) NULL;

-- Sign-in moves to email, so emails must be unique. Store them trimmed and lower-case, and where
-- two accounts share one, keep it on the oldest account (the others can sign in with their own
-- email later; staff and drivers are given one in the console).
UPDATE `User` SET `email` = NULLIF(LOWER(TRIM(`email`)), '') WHERE `email` IS NOT NULL;
UPDATE `User` u
  JOIN (SELECT `email` AS e, MIN(`id`) AS keep_id FROM `User` WHERE `email` IS NOT NULL GROUP BY `email` HAVING COUNT(*) > 1) d
    ON u.`email` = d.e AND u.`id` <> d.keep_id
  SET u.`email` = NULL;

-- CreateIndex
CREATE UNIQUE INDEX `User_email_key` ON `User`(`email`);
