Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- AlterTable
ALTER TABLE "oidc_issuer" ADD COLUMN "isPrimary" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN "orgId" UUID;

-- AddForeignKey
ALTER TABLE "oidc_issuer" ADD CONSTRAINT "oidc_issuer_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Comment on lines +1 to +6

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

base="$(git merge-base HEAD origin/main 2>/dev/null || true)"

if [ -n "$base" ]; then
  git diff --unified=40 "$base" -- \
    libs/prisma-service/prisma/migrations/20260427080006_added_org_id_and_is_primary_in_oidc_issuer/migration.sql \
    libs/prisma-service/prisma/migrations/20260504110536_add_orgid_and_isprimary_in_oidc_issuer/migration.sql
else
  fd '20260427080006_added_org_id_and_is_primary_in_oidc_issuer|20260504110536_add_orgid_and_isprimary_in_oidc_issuer' \
    libs/prisma-service/prisma/migrations \
    -x sh -c 'echo "=== $1 ==="; sed -n "1,160p" "$1"' sh {}
fi

Repository: credebl/platform

Length of output: 305


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find and read the migration files from the directories
echo "=== April Migration (20260427080006) ===" 
cat "libs/prisma-service/prisma/migrations/20260427080006_added_org_id_and_is_primary_in_oidc_issuer/migration.sql" 2>/dev/null || echo "File not found"

echo ""
echo "=== May Migration (20260504110536) ===" 
cat "libs/prisma-service/prisma/migrations/20260504110536_add_orgid_and_isprimary_in_oidc_issuer/migration.sql" 2>/dev/null || echo "File not found"

# Check git diff for changes to the April migration
echo ""
echo "=== Git diff for April migration (if base exists) ===" 
base="$(git merge-base HEAD origin/main 2>/dev/null || true)"
if [ -n "$base" ]; then
  git diff "$base" -- libs/prisma-service/prisma/migrations/20260427080006_added_org_id_and_is_primary_in_oidc_issuer/migration.sql || echo "No differences found"
else
  echo "Could not determine merge base"
fi

Repository: credebl/platform

Length of output: 546


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== All migration directories ===" 
ls -la libs/prisma-service/prisma/migrations/ | grep "202604\|202605"

echo ""
echo "=== Files in migration directories ===" 
find libs/prisma-service/prisma/migrations/ -name "*202604*" -o -name "*202605*" | sort

echo ""
echo "=== Git status for migration files ===" 
git status --short -- libs/prisma-service/prisma/migrations/ | head -20

echo ""
echo "=== Recent migration-related commits ===" 
git log --oneline -20 -- libs/prisma-service/prisma/migrations/ 2>/dev/null || echo "No recent commits found"

Repository: credebl/platform

Length of output: 450


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Git log for April migration (all history) ===" 
git log --full-history --oneline -- libs/prisma-service/prisma/migrations/20260427080006_added_org_id_and_is_primary_in_oidc_issuer/ 2>/dev/null | head -20

echo ""
echo "=== Git log for April migration with status ===" 
git log --full-history -p --follow -- libs/prisma-service/prisma/migrations/20260427080006_added_org_id_and_is_primary_in_oidc_issuer/ 2>/dev/null | head -100

echo ""
echo "=== Show recent migration fix commit ===" 
git show c73ff1d --stat 2>/dev/null || echo "Commit not found"

echo ""
echo "=== Files changed in that commit ===" 
git diff-tree --no-commit-id --name-only -r c73ff1d 2>/dev/null | grep -i migration || echo "No migration files in that commit"

Repository: credebl/platform

Length of output: 50372


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Check if April migration appears in git show for c73ff1d ===" 
git show c73ff1d | grep -i "20260427080006" || echo "April migration not mentioned in commit"

echo ""
echo "=== Files added/deleted/modified in migrations folder ===" 
git show --name-status c73ff1d -- libs/prisma-service/prisma/migrations/ 2>/dev/null | head -50 || echo "No migration changes found"

echo ""
echo "=== Check git log --full-history for April migration ===" 
git log --full-history --all --oneline -- 'libs/prisma-service/prisma/migrations/*20260427080006*' 2>/dev/null || echo "No history found"

echo ""
echo "=== List all commits that touched migrations ===" 
git log --oneline --all -- libs/prisma-service/prisma/migrations/ 2>/dev/null | head -10

Repository: credebl/platform

Length of output: 5304


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Show April migration in f95dcd3 ===" 
git show f95dcd3:libs/prisma-service/prisma/migrations/20260427080006_added_org_id_and_is_primary_in_oidc_issuer/migration.sql 2>/dev/null || echo "Not found in that commit"

echo ""
echo "=== Check if April migration was deleted in c73ff1d ===" 
git show c73ff1d --raw -- libs/prisma-service/prisma/migrations/ 2>/dev/null | grep "20260427080006" || echo "April migration not in c73ff1d"

echo ""
echo "=== Show May migration in c73ff1d ===" 
git show c73ff1d:libs/prisma-service/prisma/migrations/20260504110536_add_orgid_and_isprimary_in_oidc_issuer/migration.sql 2>/dev/null || echo "Not found"

echo ""
echo "=== Show commit message of c73ff1d ===" 
git show --format=fuller c73ff1d | head -20

Repository: credebl/platform

Length of output: 2172


Restore the April migration and keep it immutable.

The April migration (20260427080006) was created in commit f95dcd3 with essential schema changes to both oidc_issuer and oid4vc_credentials tables. The "fix: resolve migration issue" commit deleted it entirely and created a May migration containing only a subset of those changes. This creates two critical issues:

  1. Migration checksum drift: Any environment that already applied the April migration will fail to reconcile with the current migration history.
  2. Incomplete schema changes: The May migration omits the oid4vc_credentials and issued_oid4vc_credentials foreign key updates from the original April migration.

Restore the April migration exactly as it existed in f95dcd3 and ship only this May migration as an additive follow-up if needed.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@libs/prisma-service/prisma/migrations/20260504110536_add_orgid_and_isprimary_in_oidc_issuer/migration.sql`
around lines 1 - 6, Restore the deleted April migration 20260427080006 exactly
as it was in commit f95dcd3 so history remains immutable: re-add the original
SQL that modified both oidc_issuer and the oid4vc_credentials /
issued_oid4vc_credentials foreign keys (the exact ALTER TABLE and ADD CONSTRAINT
statements previously present) and do not modify its checksum; then keep the
current May migration (20260504110536) only as an additive follow-up that
includes exclusively the new changes (e.g., adding isPrimary and orgId on
oidc_issuer and its FK), ensuring the April migration file contents and names
match f95dcd3 precisely and the May migration only appends new ALTERs.

Comment on lines +2 to +6

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Backfill oidc_issuer.orgId from the existing orgAgentId mapping.

Line 595 in libs/prisma-service/prisma/schema.prisma already makes orgAgentId mandatory, and org_agents.orgId is the current org link. Without a data update here, every pre-existing issuer keeps orgId = NULL, so the new direct organisation relation misses historical rows.

Suggested migration patch
 -- AlterTable
 ALTER TABLE "oidc_issuer" ADD COLUMN     "isPrimary" BOOLEAN NOT NULL DEFAULT false,
 ADD COLUMN     "orgId" UUID;
 
+UPDATE "oidc_issuer" AS oi
+SET "orgId" = oa."orgId"
+FROM "org_agents" AS oa
+WHERE oa."id" = oi."orgAgentId"
+  AND oi."orgId" IS NULL;
+
 -- AddForeignKey
 ALTER TABLE "oidc_issuer" ADD CONSTRAINT "oidc_issuer_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE SET NULL ON UPDATE CASCADE;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ALTER TABLE "oidc_issuer" ADD COLUMN "isPrimary" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN "orgId" UUID;
-- AddForeignKey
ALTER TABLE "oidc_issuer" ADD CONSTRAINT "oidc_issuer_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE SET NULL ON UPDATE CASCADE;
ALTER TABLE "oidc_issuer" ADD COLUMN "isPrimary" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN "orgId" UUID;
UPDATE "oidc_issuer" AS oi
SET "orgId" = oa."orgId"
FROM "org_agents" AS oa
WHERE oa."id" = oi."orgAgentId"
AND oi."orgId" IS NULL;
-- AddForeignKey
ALTER TABLE "oidc_issuer" ADD CONSTRAINT "oidc_issuer_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE SET NULL ON UPDATE CASCADE;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@libs/prisma-service/prisma/migrations/20260504110536_add_orgid_and_isprimary_in_oidc_issuer/migration.sql`
around lines 2 - 6, The migration currently adds oidc_issuer.orgId and
immediately creates a FK, but it never backfills orgId from the existing
orgAgentId mapping so pre-existing issuers stay NULL; change the migration to
(1) add "orgId" as nullable on oidc_issuer (keep "isPrimary" as is), (2) run an
UPDATE that sets oidc_issuer.orgId = org_agents.orgId by joining
oidc_issuer.orgAgentId = org_agents.id (use the table names oidc_issuer and
org_agents and the columns orgAgentId and orgId), (3) if schema requires
non-null, ALTER COLUMN to NOT NULL afterwards, and only then add the FOREIGN KEY
constraint "oidc_issuer_orgId_fkey" referencing organisation(id) with the same
ON DELETE/ON UPDATE behavior.

11 changes: 6 additions & 5 deletions libs/prisma-service/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -600,14 +600,15 @@ model oidc_issuer {
orgId String? @db.Uuid
isPrimary Boolean @default(false)

organisation organisation? @relation(fields: [orgId], references: [id], onDelete: SetNull)
organisation organisation? @relation(fields: [orgId], references: [id])


@@index([orgAgentId])
}

model oid4vc_credentials {
id String @id @default(uuid()) @db.Uuid
orgId String? @db.Uuid
orgId String @db.Uuid
issuanceSessionId String @unique
credentialOfferId String
state String
Expand All @@ -620,8 +621,8 @@ model oid4vc_credentials {
issuedCredentials String[]
publicIssuerId String

organisation organisation? @relation(fields: [orgId], references: [id], onDelete: SetNull)
organisation organisation @relation(fields: [orgId], references: [id], onDelete: Restrict)

@@index([credentialConfigurationIds], type: Gin)
}

Expand Down Expand Up @@ -667,7 +668,7 @@ model issued_oid4vc_credentials {
updatedAt DateTime @updatedAt
statusListUri String

organisation organisation? @relation(fields: [orgId], references: [id], onDelete: SetNull)
organisation organisation? @relation(fields: [orgId], references: [id], onDelete: Restrict)

@@index([orgId, issuanceSessionId])
}
Expand Down
Loading