-- CreateTable
CREATE TABLE "workspace"."reminders" (
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "workspace_id" UUID NOT NULL,
    "user_id" UUID NOT NULL,
    "text" TEXT NOT NULL,
    "remind_at" TIMESTAMPTZ NOT NULL,
    "status" VARCHAR(20) NOT NULL DEFAULT 'pending',
    "channel_id" UUID,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "completed_at" TIMESTAMPTZ
);

-- CreateIndex
CREATE INDEX "idx_reminders_user" ON "workspace"."reminders"("user_id", "status");

-- CreateIndex
CREATE INDEX "idx_reminders_pending" ON "workspace"."reminders"("remind_at");

-- AddForeignKey
ALTER TABLE "workspace"."reminders" ADD CONSTRAINT "reminders_workspace_id_fkey" FOREIGN KEY ("workspace_id") REFERENCES "workspace"."workspaces"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "workspace"."reminders" ADD CONSTRAINT "reminders_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "auth"."users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "workspace"."reminders" ADD CONSTRAINT "reminders_channel_id_fkey" FOREIGN KEY ("channel_id") REFERENCES "messaging"."channels"("id") ON DELETE SET NULL ON UPDATE CASCADE;