-- phpMyAdmin-compatible extras for FlieMart production hardening
-- Run once if Prisma db push is not available on the server.
-- Safe to re-run (IF NOT EXISTS).
--
-- For a full schema: on a staging machine run `npx prisma db push`, then
-- phpMyAdmin → Export the database → Import on production.
-- This file only adds tables introduced for abuse protection / webhooks.

CREATE TABLE IF NOT EXISTS `RateLimitBucket` (
  `id` VARCHAR(191) NOT NULL,
  `count` INT NOT NULL DEFAULT 0,
  `resetAt` DATETIME(3) NOT NULL,
  PRIMARY KEY (`id`),
  INDEX `RateLimitBucket_resetAt_idx` (`resetAt`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `StripeWebhookEvent` (
  `id` VARCHAR(255) NOT NULL,
  `type` VARCHAR(191) NOT NULL,
  `processedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
  PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Quick live-check (read-only): after import, run:
-- SELECT 1 AS ok;
-- SHOW TABLES;
