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/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/V1766661879__createRepositoriesTable.sql b/backend/src/database/migrations/V1766661879__createRepositoriesTable.sql new file mode 100644 index 0000000000..f6f60e46e5 --- /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 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 DEFAULT NULL +); + +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; 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;