-- Customer settings migration (run once on the Dabil database).
-- Adds the columns used by the customer Security & Privacy / Two-Factor /
-- Close Account screens. Safe to run on MySQL 8+ (uses IF NOT EXISTS).

ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `twofa_enabled` TINYINT(1) NOT NULL DEFAULT 0;
ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `backup_codes` TEXT NULL;
ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `closure_requested` TINYINT(1) NOT NULL DEFAULT 0;
ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `closure_requested_at` TIMESTAMP NULL DEFAULT NULL;

-- Authenticator app (TOTP) enrollment
ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `totp_secret` VARCHAR(64) NULL;
ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `totp_enabled` TINYINT(1) NOT NULL DEFAULT 0;

-- If your MySQL version doesn't support "ADD COLUMN IF NOT EXISTS",
-- run these individually and ignore "duplicate column" errors:
--   ALTER TABLE `users` ADD COLUMN `twofa_enabled` TINYINT(1) NOT NULL DEFAULT 0;
--   ALTER TABLE `users` ADD COLUMN `backup_codes` TEXT NULL;
--   ALTER TABLE `users` ADD COLUMN `closure_requested` TINYINT(1) NOT NULL DEFAULT 0;
--   ALTER TABLE `users` ADD COLUMN `closure_requested_at` TIMESTAMP NULL DEFAULT NULL;
--   ALTER TABLE `users` ADD COLUMN `totp_secret` VARCHAR(64) NULL;
--   ALTER TABLE `users` ADD COLUMN `totp_enabled` TINYINT(1) NOT NULL DEFAULT 0;
