Skip to content

fix: resolve migration issue for oidv_issuer schema modal#1610

Merged
pranalidhanavade merged 1 commit into
mainfrom
fix/migration-failed-for-create-issuer
May 4, 2026
Merged

fix: resolve migration issue for oidv_issuer schema modal#1610
pranalidhanavade merged 1 commit into
mainfrom
fix/migration-failed-for-create-issuer

Conversation

@pranalidhanavade

@pranalidhanavade pranalidhanavade commented May 4, 2026

Copy link
Copy Markdown
Contributor

What

  • fix: resolve migration issue for oidv_issuer schema modal

Summary by CodeRabbit

Refactor

  • Updated database schema to restructure organizational data management within the credential issuer system.
  • Modified relationships and constraints affecting how organizations are associated with credentials and issuers.

Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com>
@pranalidhanavade pranalidhanavade self-assigned this May 4, 2026
@coderabbitai

coderabbitai Bot commented May 4, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR reverts a previous migration and introduces a replacement migration that adds isPrimary and orgId columns to oidc_issuer, while updating Prisma schema constraints. The key change shifts oid4vc_credentials.orgId from nullable to required and updates referential integrity rules from SetNull to Restrict for credential-related organisation relations.

Changes

Database Constraint Tightening

Layer / File(s) Summary
Migration Rollback & Replacement
libs/prisma-service/prisma/migrations/20260427080006_*/migration.sql, libs/prisma-service/prisma/migrations/20260504110536_*/migration.sql
Previous migration (20260427080006) is removed; new migration (20260504110536) adds oidc_issuer.isPrimary (BOOLEAN NOT NULL DEFAULT false) and oidc_issuer.orgId (UUID) with foreign-key constraint to organisation(id) using ON DELETE SET NULL and ON UPDATE CASCADE.
Schema Model Updates
libs/prisma-service/prisma/schema.prisma
oid4vc_credentials.orgId changes from optional (String?) to required (String); oid4vc_credentials.organisation and issued_oid4vc_credentials.organisation relations change from onDelete: SetNull to onDelete: Restrict; oidc_issuer.organisation relation removes explicit onDelete directive.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • sagarkhole4
  • RinkalBhojani
  • shitrerohit

Poem

🐰 The schemas shift like morning dew,
From SetNull soft to Restrict true—
Credentials anchor, strong and tight,
isPrimary hops into sight!
A rollback dance, a fresh new start,
Where data integrity plays its part. 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title references a migration fix for 'oidv_issuer' schema, which aligns with the actual changes involving oidc_issuer table modifications and migration corrections across multiple files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/migration-failed-for-create-issuer

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

sonarqubecloud Bot commented May 4, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@libs/prisma-service/prisma/migrations/20260504110536_add_orgid_and_isprimary_in_oidc_issuer/migration.sql`:
- Around line 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.
- Around line 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.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 70300b48-0df0-4027-a7c3-434980bb7184

📥 Commits

Reviewing files that changed from the base of the PR and between 92abafa and c73ff1d.

📒 Files selected for processing (3)
  • 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
  • libs/prisma-service/prisma/schema.prisma
💤 Files with no reviewable changes (1)
  • libs/prisma-service/prisma/migrations/20260427080006_added_org_id_and_is_primary_in_oidc_issuer/migration.sql

Comment on lines +1 to +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;

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
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;

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.

@pranalidhanavade
pranalidhanavade merged commit 1601616 into main May 4, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants