-
Notifications
You must be signed in to change notification settings - Fork 82
fix: add missing orgId column to issued_oid4vc_credentials table #1615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,11 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "oidc_issuer" ADD COLUMN "isPrimary" BOOLEAN NOT NULL DEFAULT false, | ||
| ADD COLUMN "orgId" UUID; | ||
| ALTER TABLE "oidc_issuer" ADD COLUMN IF NOT EXISTS "isPrimary" BOOLEAN NOT NULL DEFAULT false; | ||
| ALTER TABLE "oidc_issuer" ADD COLUMN IF NOT EXISTS "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; | ||
| DO $$ | ||
| BEGIN | ||
| IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'oidc_issuer_orgId_fkey') THEN | ||
| ALTER TABLE "oidc_issuer" ADD CONSTRAINT "oidc_issuer_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE SET NULL ON UPDATE CASCADE; | ||
| END IF; | ||
| END $$; | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,18 @@ | ||||||
| -- AlterTable | ||||||
| ALTER TABLE "issued_oid4vc_credentials" ADD COLUMN IF NOT EXISTS "orgId" UUID; | ||||||
|
|
||||||
| -- AddForeignKey | ||||||
| DO $$ | ||||||
| BEGIN | ||||||
| IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'issued_oid4vc_credentials_orgId_fkey') THEN | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Both guards search by name only: SELECT 1 FROM pg_constraint WHERE conname = '...'
SELECT 1 FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = '...'In a database with multiple schemas, if an identically-named constraint or index exists in any schema (e.g., a 🔧 Proposed fix — scope checks to the target schema- IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'issued_oid4vc_credentials_orgId_fkey') THEN
+ IF NOT EXISTS (
+ SELECT 1 FROM pg_constraint con
+ JOIN pg_class cls ON cls.oid = con.conrelid
+ JOIN pg_namespace nsp ON nsp.oid = cls.relnamespace
+ WHERE con.conname = 'issued_oid4vc_credentials_orgId_fkey'
+ AND nsp.nspname = current_schema()
+ ) THEN- IF NOT EXISTS (SELECT 1 FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = 'issued_oid4vc_credentials_orgId_issuanceSessionId_idx') THEN
+ IF NOT EXISTS (SELECT 1 FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = 'issued_oid4vc_credentials_orgId_issuanceSessionId_idx' AND n.nspname = current_schema()) THENAlso applies to: 15-15 🤖 Prompt for AI Agents |
||||||
| ALTER TABLE "issued_oid4vc_credentials" ADD CONSTRAINT "issued_oid4vc_credentials_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If org deletion should remain blocked while credentials exist, this is intentional; otherwise: 🔧 Proposed fix — change to `ON DELETE SET NULL`- ALTER TABLE "issued_oid4vc_credentials" ADD CONSTRAINT "issued_oid4vc_credentials_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
+ ALTER TABLE "issued_oid4vc_credentials" ADD CONSTRAINT "issued_oid4vc_credentials_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "organisation"("id") ON DELETE SET NULL ON UPDATE CASCADE;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| END IF; | ||||||
| END $$; | ||||||
|
|
||||||
| -- CreateIndex | ||||||
| DO $$ | ||||||
| BEGIN | ||||||
| IF NOT EXISTS (SELECT 1 FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = 'issued_oid4vc_credentials_orgId_issuanceSessionId_idx') THEN | ||||||
| CREATE INDEX "issued_oid4vc_credentials_orgId_issuanceSessionId_idx" ON "issued_oid4vc_credentials"("orgId", "issuanceSessionId"); | ||||||
| END IF; | ||||||
| END $$; | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
pg_constraintschema-filter gap as the companion migration.SELECT 1 FROM pg_constraint WHERE conname = 'oidc_issuer_orgId_fkey'does not filter by schema. An identically-named constraint in any other schema will cause the guard to skip creating the FK in the intended schema. Apply the same schema-scoped fix suggested in the companion file.🤖 Prompt for AI Agents