-- BackupLog: persistierte Historie aller Backup-/Restore-Vorgänge mit
-- Status + Volltext-Log. UI zeigt in zwei Listen (je CREATE und RESTORE).
--
-- IF NOT EXISTS damit Re-Deploys auf bestehende DBs nicht crashen, falls
-- jemand vorher manuell `prisma db push` gefahren hat.

CREATE TABLE IF NOT EXISTS `BackupLog` (
  `id` INTEGER NOT NULL AUTO_INCREMENT,
  `operation` ENUM('CREATE', 'RESTORE') NOT NULL,
  `backupName` VARCHAR(191) NULL,
  `success` BOOLEAN NOT NULL,
  `durationMs` INTEGER NOT NULL DEFAULT 0,
  `summary` TEXT NOT NULL,
  `fullLog` LONGTEXT NOT NULL,
  `userId` INTEGER NULL,
  `userEmail` VARCHAR(191) NULL,
  `ipAddress` VARCHAR(191) NULL,
  `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

  INDEX `BackupLog_operation_createdAt_idx`(`operation`, `createdAt`),
  INDEX `BackupLog_createdAt_idx`(`createdAt`),
  PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
