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 <dallinbentley98@gmail.com>
This commit is contained in:
Devin AI 2025-07-21 05:59:39 +00:00
parent 45749b881b
commit 9b9330982a
2 changed files with 12 additions and 7 deletions

View File

@ -3,9 +3,9 @@ CREATE TABLE "github_integrations" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"organization_id" uuid NOT NULL, "organization_id" uuid NOT NULL,
"user_id" uuid NOT NULL, "user_id" uuid NOT NULL,
"installation_id" varchar(255), "installation_id" varchar(255) NOT NULL,
"app_id" varchar(255), "app_id" varchar(255),
"github_org_id" varchar(255), "github_org_id" varchar(255) NOT NULL,
"github_org_name" varchar(255), "github_org_name" varchar(255),
"token_vault_key" varchar(255), "token_vault_key" varchar(255),
"webhook_secret_vault_key" varchar(255), "webhook_secret_vault_key" varchar(255),
@ -21,6 +21,7 @@ CREATE TABLE "github_integrations" (
); );
--> statement-breakpoint --> 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_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_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);

View File

@ -1957,10 +1957,10 @@ export const githubIntegrations = pgTable(
organizationId: uuid('organization_id').notNull(), organizationId: uuid('organization_id').notNull(),
userId: uuid('user_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 }), 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 }), githubOrgName: varchar('github_org_name', { length: 255 }),
tokenVaultKey: varchar('token_vault_key', { length: 255 }).unique(), tokenVaultKey: varchar('token_vault_key', { length: 255 }).unique(),
@ -1991,7 +1991,7 @@ export const githubIntegrations = pgTable(
columns: [table.userId], columns: [table.userId],
foreignColumns: [users.id], foreignColumns: [users.id],
name: 'github_integrations_user_id_fkey', name: 'github_integrations_user_id_fkey',
}), }).onDelete('set null'),
unique('github_integrations_org_installation_key').on(table.organizationId, table.installationId), unique('github_integrations_org_installation_key').on(table.organizationId, table.installationId),
index('idx_github_integrations_org_id').using( index('idx_github_integrations_org_id').using(
'btree', 'btree',
@ -2001,6 +2001,10 @@ export const githubIntegrations = pgTable(
'btree', 'btree',
table.installationId.asc().nullsLast().op('text_ops') table.installationId.asc().nullsLast().op('text_ops')
), ),
index('idx_github_integrations_github_org_id').using(
'btree',
table.githubOrgId.asc().nullsLast().op('text_ops')
),
] ]
); );