migration.sql•4.64 kB
-- CreateEnum
CREATE TYPE "WorkflowStatus" AS ENUM ('IN_PROGRESS', 'COMPLETED', 'FAILED');
-- CreateEnum
CREATE TYPE "TaskStatus" AS ENUM ('IN_PROGRESS', 'SUCCESS', 'PARTIAL_SUCCESS', 'FAILED');
-- CreateEnum
CREATE TYPE "DecisionCategory" AS ENUM ('ARCHITECTURE', 'LIBRARY_CHOICE', 'TRADE_OFF', 'WORKAROUND', 'OTHER');
-- CreateEnum
CREATE TYPE "IssueType" AS ENUM ('DOC_GAP', 'BUG', 'DEPENDENCY_CONFLICT', 'UNCLEAR_REQUIREMENT', 'OTHER');
-- CreateEnum
CREATE TYPE "TestsStatus" AS ENUM ('PASSED', 'FAILED', 'NOT_RUN');
-- CreateTable
CREATE TABLE "Workflow" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT,
"plan" JSONB,
"status" "WorkflowStatus" NOT NULL DEFAULT 'IN_PROGRESS',
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Workflow_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Task" (
"id" TEXT NOT NULL,
"workflowId" TEXT NOT NULL,
"parentTaskId" TEXT,
"name" TEXT NOT NULL,
"goal" TEXT NOT NULL,
"status" "TaskStatus" NOT NULL DEFAULT 'IN_PROGRESS',
"areas" TEXT[],
"snapshotId" TEXT,
"snapshotType" TEXT,
"snapshotData" JSONB,
"startedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"completedAt" TIMESTAMP(3),
"durationMs" INTEGER,
"summary" TEXT,
"achievements" TEXT[],
"limitations" TEXT[],
"manualReviewNeeded" BOOLEAN NOT NULL DEFAULT false,
"manualReviewReason" TEXT,
"nextSteps" TEXT[],
"packagesAdded" TEXT[],
"packagesRemoved" TEXT[],
"commandsExecuted" TEXT[],
"testsStatus" "TestsStatus",
"filesAdded" TEXT[],
"filesModified" TEXT[],
"filesDeleted" TEXT[],
"scopeMatch" BOOLEAN,
"unexpectedFiles" TEXT[],
"warnings" TEXT[],
CONSTRAINT "Task_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Decision" (
"id" TEXT NOT NULL,
"taskId" TEXT NOT NULL,
"category" "DecisionCategory" NOT NULL,
"question" TEXT NOT NULL,
"optionsConsidered" TEXT[],
"chosen" TEXT NOT NULL,
"reasoning" TEXT NOT NULL,
"tradeOffs" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "Decision_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Issue" (
"id" TEXT NOT NULL,
"taskId" TEXT NOT NULL,
"type" "IssueType" NOT NULL,
"description" TEXT NOT NULL,
"resolution" TEXT NOT NULL,
"requiresHumanReview" BOOLEAN NOT NULL DEFAULT false,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "Issue_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Milestone" (
"id" TEXT NOT NULL,
"taskId" TEXT NOT NULL,
"message" TEXT NOT NULL,
"progress" INTEGER,
"metadata" JSONB,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "Milestone_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "Workflow_status_idx" ON "Workflow"("status");
-- CreateIndex
CREATE INDEX "Workflow_createdAt_idx" ON "Workflow"("createdAt");
-- CreateIndex
CREATE INDEX "Task_workflowId_idx" ON "Task"("workflowId");
-- CreateIndex
CREATE INDEX "Task_parentTaskId_idx" ON "Task"("parentTaskId");
-- CreateIndex
CREATE INDEX "Task_status_idx" ON "Task"("status");
-- CreateIndex
CREATE INDEX "Task_startedAt_idx" ON "Task"("startedAt");
-- CreateIndex
CREATE INDEX "Decision_taskId_idx" ON "Decision"("taskId");
-- CreateIndex
CREATE INDEX "Decision_createdAt_idx" ON "Decision"("createdAt");
-- CreateIndex
CREATE INDEX "Issue_taskId_idx" ON "Issue"("taskId");
-- CreateIndex
CREATE INDEX "Issue_createdAt_idx" ON "Issue"("createdAt");
-- CreateIndex
CREATE INDEX "Milestone_taskId_idx" ON "Milestone"("taskId");
-- CreateIndex
CREATE INDEX "Milestone_createdAt_idx" ON "Milestone"("createdAt");
-- AddForeignKey
ALTER TABLE "Task" ADD CONSTRAINT "Task_workflowId_fkey" FOREIGN KEY ("workflowId") REFERENCES "Workflow"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Task" ADD CONSTRAINT "Task_parentTaskId_fkey" FOREIGN KEY ("parentTaskId") REFERENCES "Task"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Decision" ADD CONSTRAINT "Decision_taskId_fkey" FOREIGN KEY ("taskId") REFERENCES "Task"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Issue" ADD CONSTRAINT "Issue_taskId_fkey" FOREIGN KEY ("taskId") REFERENCES "Task"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Milestone" ADD CONSTRAINT "Milestone_taskId_fkey" FOREIGN KEY ("taskId") REFERENCES "Task"("id") ON DELETE CASCADE ON UPDATE CASCADE;