feat(git): mehrere Repositories je Projekt
Ein Vorhaben besteht oft aus Frontend und Backend - zwei Repositories, aber eine Karte. Die Git-Felder wandern deshalb vom Projekt in eine eigene Tabelle, der Snapshot haengt jetzt am Repository. Das erste Repository ist das fuehrende. Wo nur eines dargestellt werden kann - Karte, Kanban -, ist es dieses. Ein Abgleichsfehler an *irgendeinem* erscheint aber trotzdem auf der Karte, sonst bliebe er unbemerkt. Der Merkstand fuer Benachrichtigungen liegt nun am Repository. Am Projekt verdeckte ein rotes Frontend die rote Pipeline des Backends. Stillstand bleibt dagegen eine Aussage ueber das Vorhaben und bemisst sich am juengsten Commit ueber alle Repos: an einem Projekt wird gearbeitet, sobald an einem seiner Teile gearbeitet wird. Der Zeitgeber zaehlt und begrenzt jetzt Repositories statt Projekte. Sonst zoege ein Projekt mit fuenf Repos fuenfmal so viele Anfragen nach sich, wie sein Platz im Kontingent hergibt. "Alle abgleichen" laeuft nacheinander - ein Schwung gleichzeitiger Anfragen an denselben Anbieter ist genau das, worauf Rate-Limits reagieren. Die Issue-Nummer allein reicht als Dublettenschutz nicht mehr: Frontend und Backend haben beide ein Issue 5, und das sind zwei Aufgaben. Die Herkunft gehoert deshalb mit in die Eindeutigkeit. In Postgres nachgewiesen: dieselbe Nummer in zwei Repos geht durch, zweimal im selben Repo nicht, mehrere Aufgaben ohne Herkunft bleiben erlaubt. Die Projekt-API nimmt die Git-Felder weiterhin an und setzt damit das fuehrende Repository - so kommt man mit einem Aufruf zu Projekt und Repo, und der Import muss von der neuen Tabelle nichts wissen. Die Exportdatei zaehlt auf 2 hoch und traegt eine Liste. Version 1 bleibt lesbar: dort stand genau ein Repository flach am Projekt. Die Datenmigration ist von Hand geschrieben - migrate diff kennt nur den Zielzustand und haette die Spalten samt Snapshots ersatzlos geloescht. Gegen eine Kopie mit echten Daten geprueft: Verknuepfung, Verbindung, Fehlerzaehler und Snapshot kommen vollstaendig mit, Projekte ohne Repo bekommen keine leere Zeile. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
-- Mehrere Repositories je Projekt.
|
||||
--
|
||||
-- Die Git-Felder wandern vom Projekt in eine eigene Tabelle. Bestehende
|
||||
-- Projekte bekommen daraus genau ein Repository, damit nichts verlorengeht;
|
||||
-- der Snapshot haengt danach am Repository statt am Projekt.
|
||||
--
|
||||
-- Von Hand geschrieben: prisma migrate diff wuerde die Spalten am Projekt
|
||||
-- ersatzlos loeschen und die Snapshots gleich mit.
|
||||
|
||||
-- ── 1. Neue Tabelle ─────────────────────────────────────────
|
||||
CREATE TABLE "Repository" (
|
||||
"id" TEXT NOT NULL,
|
||||
"projectId" TEXT NOT NULL,
|
||||
"label" TEXT,
|
||||
"repoUrl" TEXT,
|
||||
"repoOwner" TEXT,
|
||||
"repoName" TEXT,
|
||||
"defaultBranch" TEXT,
|
||||
"connectionId" TEXT,
|
||||
"position" INTEGER NOT NULL DEFAULT 0,
|
||||
"lastSyncedAt" TIMESTAMP(3),
|
||||
"syncError" TEXT,
|
||||
"autoSync" BOOLEAN NOT NULL DEFAULT true,
|
||||
"syncFailureCount" INTEGER NOT NULL DEFAULT 0,
|
||||
"notifiedSyncError" TEXT,
|
||||
"notifiedCiState" TEXT,
|
||||
"notifiedRelease" TEXT,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "Repository_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE INDEX "Repository_projectId_position_idx" ON "Repository"("projectId", "position");
|
||||
CREATE INDEX "Repository_connectionId_idx" ON "Repository"("connectionId");
|
||||
|
||||
ALTER TABLE "Repository" ADD CONSTRAINT "Repository_projectId_fkey"
|
||||
FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
ALTER TABLE "Repository" ADD CONSTRAINT "Repository_connectionId_fkey"
|
||||
FOREIGN KEY ("connectionId") REFERENCES "GitConnection"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- ── 2. Bestand uebernehmen ──────────────────────────────────
|
||||
-- Nur Projekte, an denen wirklich etwas haengt. Ein Projekt, das bloss eine
|
||||
-- Verbindung ausgewaehlt hatte, ohne je ein Repo zu nennen, braucht keine
|
||||
-- leere Zeile.
|
||||
INSERT INTO "Repository" (
|
||||
"id", "projectId", "repoUrl", "repoOwner", "repoName", "defaultBranch",
|
||||
"connectionId", "position", "lastSyncedAt", "syncError", "autoSync",
|
||||
"syncFailureCount", "notifiedSyncError", "notifiedCiState", "notifiedRelease",
|
||||
"createdAt", "updatedAt"
|
||||
)
|
||||
SELECT
|
||||
gen_random_uuid()::text, "id", "repoUrl", "repoOwner", "repoName", "defaultBranch",
|
||||
"connectionId", 0, "lastSyncedAt", "syncError", "autoSync",
|
||||
"syncFailureCount", "notifiedSyncError", "notifiedCiState", "notifiedRelease",
|
||||
"createdAt", CURRENT_TIMESTAMP
|
||||
FROM "Project"
|
||||
WHERE "repoUrl" IS NOT NULL
|
||||
OR ("repoOwner" IS NOT NULL AND "repoName" IS NOT NULL);
|
||||
|
||||
-- ── 3. Snapshots umhaengen ──────────────────────────────────
|
||||
ALTER TABLE "RepoSnapshot" ADD COLUMN "repositoryId" TEXT;
|
||||
|
||||
UPDATE "RepoSnapshot" AS s
|
||||
SET "repositoryId" = r."id"
|
||||
FROM "Repository" AS r
|
||||
WHERE r."projectId" = s."projectId";
|
||||
|
||||
-- Ein Snapshot ohne zugehoeriges Repository kann nur entstanden sein, wenn
|
||||
-- jemand die Repo-Angaben nachtraeglich geleert hat. Er ist ohnehin nicht
|
||||
-- mehr zuzuordnen und beim naechsten Abgleich neu geholt.
|
||||
DELETE FROM "RepoSnapshot" WHERE "repositoryId" IS NULL;
|
||||
|
||||
ALTER TABLE "RepoSnapshot" ALTER COLUMN "repositoryId" SET NOT NULL;
|
||||
ALTER TABLE "RepoSnapshot" DROP CONSTRAINT "RepoSnapshot_projectId_fkey";
|
||||
DROP INDEX "RepoSnapshot_projectId_key";
|
||||
ALTER TABLE "RepoSnapshot" DROP COLUMN "projectId";
|
||||
|
||||
CREATE UNIQUE INDEX "RepoSnapshot_repositoryId_key" ON "RepoSnapshot"("repositoryId");
|
||||
ALTER TABLE "RepoSnapshot" ADD CONSTRAINT "RepoSnapshot_repositoryId_fkey"
|
||||
FOREIGN KEY ("repositoryId") REFERENCES "Repository"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- ── 4. Herkunft uebernommener Aufgaben ──────────────────────
|
||||
-- Bisher war die Issue-Nummer je Projekt eindeutig. Mit mehreren Repos
|
||||
-- reicht das nicht mehr: Frontend und Backend haben beide ein Issue 5.
|
||||
ALTER TABLE "Task" ADD COLUMN "sourceRepositoryId" TEXT;
|
||||
|
||||
UPDATE "Task" AS t
|
||||
SET "sourceRepositoryId" = r."id"
|
||||
FROM "Repository" AS r
|
||||
WHERE r."projectId" = t."projectId" AND t."sourceIssue" IS NOT NULL;
|
||||
|
||||
DROP INDEX "Task_projectId_sourceIssue_key";
|
||||
CREATE UNIQUE INDEX "Task_projectId_sourceRepositoryId_sourceIssue_key"
|
||||
ON "Task"("projectId", "sourceRepositoryId", "sourceIssue");
|
||||
|
||||
-- ── 5. Projekt aufraeumen ───────────────────────────────────
|
||||
ALTER TABLE "Project" DROP CONSTRAINT "Project_connectionId_fkey";
|
||||
DROP INDEX "Project_connectionId_idx";
|
||||
|
||||
ALTER TABLE "Project"
|
||||
DROP COLUMN "repoUrl",
|
||||
DROP COLUMN "repoOwner",
|
||||
DROP COLUMN "repoName",
|
||||
DROP COLUMN "defaultBranch",
|
||||
DROP COLUMN "connectionId",
|
||||
DROP COLUMN "lastSyncedAt",
|
||||
DROP COLUMN "syncError",
|
||||
DROP COLUMN "autoSync",
|
||||
DROP COLUMN "syncFailureCount",
|
||||
DROP COLUMN "notifiedSyncError",
|
||||
DROP COLUMN "notifiedCiState",
|
||||
DROP COLUMN "notifiedRelease";
|
||||
Reference in New Issue
Block a user