fix(credential): fix service_account migration to avoid unsafe enum usage in same transaction (#3897)

This commit is contained in:
Waleed
2026-04-02 10:16:08 -07:00
committed by GitHub
parent 080a0a6123
commit a78f3f9c2e
5 changed files with 5 additions and 43 deletions
@@ -0,0 +1,2 @@
ALTER TYPE "public"."credential_type" ADD VALUE 'service_account';--> statement-breakpoint
ALTER TABLE "credential" ADD COLUMN "encrypted_service_account_key" text;
@@ -1,3 +0,0 @@
ALTER TYPE "public"."credential_type" ADD VALUE 'service_account';--> statement-breakpoint
ALTER TABLE "credential" ADD COLUMN "encrypted_service_account_key" text;--> statement-breakpoint
CREATE UNIQUE INDEX "credential_workspace_service_account_unique" ON "credential" USING btree ("workspace_id","type","provider_id","display_name") WHERE type = 'service_account';
+1 -35
View File
@@ -1,5 +1,5 @@
{
"id": "7f097b1f-1207-472e-b1bc-e237bab9528c",
"id": "1a38a6e2-09e2-4215-baa2-662f78824768",
"prevId": "1114a957-9e5b-49fe-b82d-ef3612189345",
"version": "7",
"dialect": "postgresql",
@@ -2930,40 +2930,6 @@
"concurrently": false,
"method": "btree",
"with": {}
},
"credential_workspace_service_account_unique": {
"name": "credential_workspace_service_account_unique",
"columns": [
{
"expression": "workspace_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "type",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "provider_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "display_name",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"where": "type = 'service_account'",
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
+2 -2
View File
@@ -1286,8 +1286,8 @@
{
"idx": 184,
"version": "7",
"when": 1775118314401,
"tag": "0184_stiff_captain_marvel",
"when": 1775149654511,
"tag": "0184_hard_thaddeus_ross",
"breakpoints": true
}
]
-3
View File
@@ -2350,9 +2350,6 @@ export const credential = pgTable(
workspacePersonalEnvUnique: uniqueIndex('credential_workspace_personal_env_unique')
.on(table.workspaceId, table.type, table.envKey, table.envOwnerUserId)
.where(sql`type = 'env_personal'`),
workspaceServiceAccountUnique: uniqueIndex('credential_workspace_service_account_unique')
.on(table.workspaceId, table.type, table.providerId, table.displayName)
.where(sql`type = 'service_account'`),
oauthSourceConstraint: check(
'credential_oauth_source_check',
sql`(type <> 'oauth') OR (account_id IS NOT NULL AND provider_id IS NOT NULL)`