From 9b9330982a9e9f3b7a0ee46e77529b389a8e01d8 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 21 Jul 2025 05:59:39 +0000 Subject: [PATCH] fix: address PR review comments for GitHub integrations - Make installationId and githubOrgId NOT NULL (required GitHub API fields) - Change user foreign key to ON DELETE SET NULL to prevent blocking user deletion - Add index on github_org_id for better query performance - Maintain unique constraint on organization_id + installation_id pair Addresses greptile-apps review comments on PR #574 Co-Authored-By: Dallin Bentley --- packages/database/drizzle/0084_github_integrations.sql | 9 +++++---- packages/database/src/schema.ts | 10 +++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/database/drizzle/0084_github_integrations.sql b/packages/database/drizzle/0084_github_integrations.sql index 7c64acc62..c6bb19edd 100644 --- a/packages/database/drizzle/0084_github_integrations.sql +++ b/packages/database/drizzle/0084_github_integrations.sql @@ -3,9 +3,9 @@ CREATE TABLE "github_integrations" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "organization_id" uuid NOT NULL, "user_id" uuid NOT NULL, - "installation_id" varchar(255), + "installation_id" varchar(255) NOT NULL, "app_id" varchar(255), - "github_org_id" varchar(255), + "github_org_id" varchar(255) NOT NULL, "github_org_name" varchar(255), "token_vault_key" varchar(255), "webhook_secret_vault_key" varchar(255), @@ -21,6 +21,7 @@ CREATE TABLE "github_integrations" ( ); --> statement-breakpoint ALTER TABLE "github_integrations" ADD CONSTRAINT "github_integrations_organization_id_fkey" FOREIGN KEY ("organization_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint -ALTER TABLE "github_integrations" ADD CONSTRAINT "github_integrations_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "github_integrations" ADD CONSTRAINT "github_integrations_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint CREATE INDEX "idx_github_integrations_org_id" ON "github_integrations" USING btree ("organization_id" uuid_ops);--> statement-breakpoint -CREATE INDEX "idx_github_integrations_installation_id" ON "github_integrations" USING btree ("installation_id" text_ops); +CREATE INDEX "idx_github_integrations_installation_id" ON "github_integrations" USING btree ("installation_id" text_ops);--> statement-breakpoint +CREATE INDEX "idx_github_integrations_github_org_id" ON "github_integrations" USING btree ("github_org_id" text_ops); diff --git a/packages/database/src/schema.ts b/packages/database/src/schema.ts index 0e3dbdd55..67af583ec 100644 --- a/packages/database/src/schema.ts +++ b/packages/database/src/schema.ts @@ -1957,10 +1957,10 @@ export const githubIntegrations = pgTable( organizationId: uuid('organization_id').notNull(), userId: uuid('user_id').notNull(), - installationId: varchar('installation_id', { length: 255 }), + installationId: varchar('installation_id', { length: 255 }).notNull(), appId: varchar('app_id', { length: 255 }), - githubOrgId: varchar('github_org_id', { length: 255 }), + githubOrgId: varchar('github_org_id', { length: 255 }).notNull(), githubOrgName: varchar('github_org_name', { length: 255 }), tokenVaultKey: varchar('token_vault_key', { length: 255 }).unique(), @@ -1991,7 +1991,7 @@ export const githubIntegrations = pgTable( columns: [table.userId], foreignColumns: [users.id], name: 'github_integrations_user_id_fkey', - }), + }).onDelete('set null'), unique('github_integrations_org_installation_key').on(table.organizationId, table.installationId), index('idx_github_integrations_org_id').using( 'btree', @@ -2001,6 +2001,10 @@ export const githubIntegrations = pgTable( 'btree', table.installationId.asc().nullsLast().op('text_ops') ), + index('idx_github_integrations_github_org_id').using( + 'btree', + table.githubOrgId.asc().nullsLast().op('text_ops') + ), ] );