-- Restore todos table after out-of-band drop.
-- DB-state lost the table while schema.prisma still defined `model Todo` and
-- migration history showed no removal. This migration brings DB back in sync
-- with the schema. Generated via:
--   npx prisma migrate diff --from-config-datasource \
--     --to-schema prisma/schema.prisma --script

-- CreateTable
CREATE TABLE "todos" (
    "id" TEXT NOT NULL,
    "user_id" TEXT NOT NULL,
    "product_id" TEXT,
    "title" TEXT NOT NULL,
    "description" VARCHAR(2000),
    "done" BOOLEAN NOT NULL DEFAULT false,
    "archived" BOOLEAN NOT NULL DEFAULT false,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "todos_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE INDEX "todos_user_id_done_archived_idx" ON "todos"("user_id", "done", "archived");

-- CreateIndex
CREATE INDEX "todos_user_id_product_id_idx" ON "todos"("user_id", "product_id");

-- AddForeignKey
ALTER TABLE "todos" ADD CONSTRAINT "todos_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "todos" ADD CONSTRAINT "todos_product_id_fkey" FOREIGN KEY ("product_id") REFERENCES "products"("id") ON DELETE SET NULL ON UPDATE CASCADE;
