Files
projectbrain-Public/backend/prisma/migrations/20260826050000_portfolio_control_plane/migration.sql
T

31 lines
1.4 KiB
SQL

-- Durable Gitea portfolio discovery and onboarding state.
CREATE TYPE "PortfolioRepositoryStatus" AS ENUM ('discovered', 'onboarded', 'excluded', 'unavailable');
CREATE TABLE "PortfolioRepository" (
"id" TEXT NOT NULL,
"owner" TEXT NOT NULL,
"repository" TEXT NOT NULL,
"projectId" TEXT,
"description" TEXT,
"defaultBranch" TEXT NOT NULL,
"htmlUrl" TEXT,
"private" BOOLEAN NOT NULL DEFAULT true,
"archived" BOOLEAN NOT NULL DEFAULT false,
"canPush" BOOLEAN NOT NULL DEFAULT false,
"status" "PortfolioRepositoryStatus" NOT NULL DEFAULT 'discovered',
"exclusionReason" TEXT,
"firstSeenAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"lastSeenAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"onboardedAt" TIMESTAMP(3),
"excludedAt" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "PortfolioRepository_pkey" PRIMARY KEY ("id")
);
CREATE UNIQUE INDEX "PortfolioRepository_owner_repository_key" ON "PortfolioRepository"("owner", "repository");
CREATE INDEX "PortfolioRepository_status_lastSeenAt_idx" ON "PortfolioRepository"("status", "lastSeenAt");
CREATE INDEX "PortfolioRepository_projectId_idx" ON "PortfolioRepository"("projectId");
ALTER TABLE "PortfolioRepository" ADD CONSTRAINT "PortfolioRepository_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE SET NULL ON UPDATE CASCADE;