-- CreateTable
CREATE TABLE "MantisIssue" (
    "id" SERIAL NOT NULL,
    "title" TEXT NOT NULL,
    "description" TEXT,
    "reporter_id" TEXT NOT NULL,
    "status" TEXT NOT NULL,
    "priority" TEXT NOT NULL,
    "severity" TEXT NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "MantisComment" (
    "id" SERIAL NOT NULL,
    "mantis_issue_id" INTEGER NOT NULL,
    "sender_id" TEXT NOT NULL,
    "comment" TEXT NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "MantisAttachment" (
    "id" SERIAL NOT NULL,
    "comment_id" INTEGER NOT NULL,
    "filename" TEXT NOT NULL,
    "url" TEXT NOT NULL,
    "mime_type" TEXT,
    "size" INTEGER,
    "uploaded_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- AddForeignKey
ALTER TABLE "MantisIssue" ADD CONSTRAINT "MantisIssue_reporter_id_fkey" FOREIGN KEY ("reporter_id") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MantisComment" ADD CONSTRAINT "MantisComment_mantis_issue_id_fkey" FOREIGN KEY ("mantis_issue_id") REFERENCES "MantisIssue"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MantisComment" ADD CONSTRAINT "MantisComment_sender_id_fkey" FOREIGN KEY ("sender_id") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MantisAttachment" ADD CONSTRAINT "MantisAttachment_comment_id_fkey" FOREIGN KEY ("comment_id") REFERENCES "MantisComment"("id") ON DELETE CASCADE ON UPDATE CASCADE;
