From 80f810287989cd80595977605812af42f40e5254 Mon Sep 17 00:00:00 2001 From: Mouad BANI Date: Thu, 25 Dec 2025 14:20:26 +0100 Subject: [PATCH 1/3] feat: db migration for new repositories table --- .../U1766661879__createRepositoriesTable.sql | 0 .../V1766661879__createRepositoriesTable.sql | 27 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 backend/src/database/migrations/U1766661879__createRepositoriesTable.sql create mode 100644 backend/src/database/migrations/V1766661879__createRepositoriesTable.sql diff --git a/backend/src/database/migrations/U1766661879__createRepositoriesTable.sql b/backend/src/database/migrations/U1766661879__createRepositoriesTable.sql new file mode 100644 index 0000000000..e69de29bb2 diff --git a/backend/src/database/migrations/V1766661879__createRepositoriesTable.sql b/backend/src/database/migrations/V1766661879__createRepositoriesTable.sql new file mode 100644 index 0000000000..30d6375272 --- /dev/null +++ b/backend/src/database/migrations/V1766661879__createRepositoriesTable.sql @@ -0,0 +1,27 @@ +CREATE TABLE public.repositories( + id UUID PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(), + "url" VARCHAR(1024) NOT NULL UNIQUE, + "segmentId" UUID NOT NULL REFERENCES "segments"(id) ON DELETE CASCADE, + "gitIntegrationId" UUID NOT NULL REFERENCES public."integrations" (id) ON DELETE CASCADE, + "sourceIntegrationId" UUID NOT NULL REFERENCES public."integrations" (id) ON DELETE CASCADE, + "insightsProjectId" UUID REFERENCES "insightsProjects"(id) ON DELETE CASCADE, + "archived" BOOLEAN NOT NULL DEFAULT FALSE, + "forkedFrom" VARCHAR(1024) DEFAULT NULL, + "excluded" BOOLEAN NOT NULL DEFAULT FALSE, + "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), + "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), + "deletedAt" TIMESTAMP WITH TIME ZONE, + "lastArchivedCheckAt" TIMESTAMP WITH TIME ZONE +); + +CREATE INDEX ix_repositories_segmentId + ON repositories ("segmentId") + WHERE "deletedAt" IS NULL; + +CREATE INDEX ix_repositories_sourceIntegrationId + ON repositories ("sourceIntegrationId") + WHERE "deletedAt" IS NULL; + +CREATE INDEX ix_repositories_insightsProjectId + ON repositories ("insightsProjectId") + WHERE "deletedAt" IS NULL; From 1d4e75478346dce93ce1cbda9955c18dbf00d3a4 Mon Sep 17 00:00:00 2001 From: Mouad BANI Date: Thu, 25 Dec 2025 15:06:00 +0100 Subject: [PATCH 2/3] feat: db migration for new git.repositoryProcessing table --- ...30__createGitRepositoryProcessingTable.sql | 0 ...30__createGitRepositoryProcessingTable.sql | 29 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 backend/src/database/migrations/U1766669430__createGitRepositoryProcessingTable.sql create mode 100644 backend/src/database/migrations/V1766669430__createGitRepositoryProcessingTable.sql diff --git a/backend/src/database/migrations/U1766669430__createGitRepositoryProcessingTable.sql b/backend/src/database/migrations/U1766669430__createGitRepositoryProcessingTable.sql new file mode 100644 index 0000000000..e69de29bb2 diff --git a/backend/src/database/migrations/V1766669430__createGitRepositoryProcessingTable.sql b/backend/src/database/migrations/V1766669430__createGitRepositoryProcessingTable.sql new file mode 100644 index 0000000000..af2e052cb9 --- /dev/null +++ b/backend/src/database/migrations/V1766669430__createGitRepositoryProcessingTable.sql @@ -0,0 +1,29 @@ +CREATE TABLE git."repositoryProcessing" ( + "id" UUID PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(), + "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), + "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), + + "repositoryId" UUID NOT NULL UNIQUE REFERENCES public.repositories ("id") ON DELETE CASCADE, + "branch" VARCHAR(255) DEFAULT NULL, + "state" VARCHAR(50) NOT NULL DEFAULT 'pending', + "priority" INTEGER NOT NULL DEFAULT 1, + "lockedAt" TIMESTAMP WITH TIME ZONE DEFAULT NULL, + "lastProcessedAt" TIMESTAMP WITH TIME ZONE DEFAULT NULL, + "lastProcessedCommit" VARCHAR(64) DEFAULT NULL, + "maintainerFile" VARCHAR(255) DEFAULT NULL, + "lastMaintainerRunAt" TIMESTAMP WITH TIME ZONE DEFAULT NULL, + "stuckRequiresReOnboard" BOOLEAN NOT NULL DEFAULT FALSE, + "reOnboardingCount" INTEGER NOT NULL DEFAULT 0 +); + +CREATE INDEX "ix_git_repositoryProcessing_onboarding_acquisition" + ON git."repositoryProcessing" ("state", "lockedAt", "priority", "createdAt") + WHERE "state" = 'pending' AND "lockedAt" IS NULL; + +CREATE INDEX "ix_git_repositoryProcessing_recurrent_acquisition" + ON git."repositoryProcessing" ("state", "lockedAt", "lastProcessedAt", "priority") + WHERE "lockedAt" IS NULL; + +CREATE INDEX "ix_git_repositoryProcessing_active_onboarding_count" + ON git."repositoryProcessing" ("state") + WHERE "state" = 'processing' AND "lastProcessedCommit" IS NULL; From 74e90ad2b30b919126862eade30fcea2e4e7137d Mon Sep 17 00:00:00 2001 From: Mouad BANI Date: Thu, 25 Dec 2025 15:54:45 +0100 Subject: [PATCH 3/3] fix: mark insightsProjectId as required --- .../migrations/V1766661879__createRepositoriesTable.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/database/migrations/V1766661879__createRepositoriesTable.sql b/backend/src/database/migrations/V1766661879__createRepositoriesTable.sql index 30d6375272..f6f60e46e5 100644 --- a/backend/src/database/migrations/V1766661879__createRepositoriesTable.sql +++ b/backend/src/database/migrations/V1766661879__createRepositoriesTable.sql @@ -4,14 +4,14 @@ CREATE TABLE public.repositories( "segmentId" UUID NOT NULL REFERENCES "segments"(id) ON DELETE CASCADE, "gitIntegrationId" UUID NOT NULL REFERENCES public."integrations" (id) ON DELETE CASCADE, "sourceIntegrationId" UUID NOT NULL REFERENCES public."integrations" (id) ON DELETE CASCADE, - "insightsProjectId" UUID REFERENCES "insightsProjects"(id) ON DELETE CASCADE, + "insightsProjectId" UUID NOT NULL REFERENCES "insightsProjects"(id) ON DELETE CASCADE, "archived" BOOLEAN NOT NULL DEFAULT FALSE, "forkedFrom" VARCHAR(1024) DEFAULT NULL, "excluded" BOOLEAN NOT NULL DEFAULT FALSE, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), "deletedAt" TIMESTAMP WITH TIME ZONE, - "lastArchivedCheckAt" TIMESTAMP WITH TIME ZONE + "lastArchivedCheckAt" TIMESTAMP WITH TIME ZONE DEFAULT NULL ); CREATE INDEX ix_repositories_segmentId