-- CreateTable CREATE TABLE "coupons" ( "id" TEXT NOT NULL PRIMARY KEY, "code" TEXT NOT NULL, "title" TEXT NOT NULL, "description" TEXT, "stock" INTEGER NOT NULL DEFAULT 0, "maxPerUser" INTEGER NOT NULL DEFAULT 1, "expiresAt" DATETIME, "active" BOOLEAN NOT NULL DEFAULT true, "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ); -- CreateTable CREATE TABLE "coupon_redemptions" ( "id" TEXT NOT NULL PRIMARY KEY, "couponId" TEXT NOT NULL, "userId" TEXT NOT NULL, "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT "coupon_redemptions_couponId_fkey" FOREIGN KEY ("couponId") REFERENCES "coupons" ("id") ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT "coupon_redemptions_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users" ("userId") ON DELETE CASCADE ON UPDATE CASCADE ); -- CreateTable CREATE TABLE "partners" ( "id" TEXT NOT NULL PRIMARY KEY, "name" TEXT NOT NULL, "category" TEXT NOT NULL, "latitude" REAL NOT NULL, "longitude" REAL NOT NULL, "address" TEXT, "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, "updatedAt" DATETIME NOT NULL ); -- CreateIndex CREATE UNIQUE INDEX "coupons_code_key" ON "coupons"("code"); -- CreateIndex CREATE INDEX "coupons_active_expiresAt_idx" ON "coupons"("active", "expiresAt"); -- CreateIndex CREATE INDEX "coupon_redemptions_userId_createdAt_idx" ON "coupon_redemptions"("userId", "createdAt"); -- CreateIndex CREATE UNIQUE INDEX "coupon_redemptions_couponId_userId_key" ON "coupon_redemptions"("couponId", "userId"); -- CreateIndex CREATE INDEX "partners_category_idx" ON "partners"("category");