Skip to content

Conversation

@afitzek
Copy link
Contributor

@afitzek afitzek commented Jan 29, 2026

Summary

This PR addresses a database limitation where the subject_id column in the dynamic_credential_entry table was restricted to varchar(16), which is insufficient for certain dynamic credential resolvers that generate longer subject identifiers.

Changes Made

  • Migration: Created ExpandSubjectIDColumnLength1769690595000 migration that:
  • Changes subject_id column type from varchar(16) to TEXT (unbounded)
  • Recreates the table for both PostgreSQL and SQLite (required because subject_id is part of the composite primary key)
  • Preserves all existing data using the copyTable utility (batch copying in chunks of 10 rows)
  • Maintains all constraints (primary key, foreign keys, indexes)
  • Postgres does not support the short syntax for LIMIT and OFFSET (this was changed in the copyTable migration helper)

Why Table Recreation?

The subject_id column is part of a composite primary key (credential_id, subject_id, resolver_id). Both PostgreSQL and SQLite have restrictions on altering columns that are part of primary key constraints:

  • PostgreSQL: Cannot alter column type when it's part of a primary key without dropping the constraint first
  • SQLite: Cannot drop columns that are part of a primary key

The cleanest and safest approach is to recreate the table with the new schema, which the migration does using n8n's built-in copyTable utility that handles data preservation, foreign keys, and indexes.

Related Linear tickets, Github issues, and Community forum posts

closes https://linear.app/n8n/issue/IAM-204/increase-varchar-limit-for-subjectid-column-in-postgrest-for-dynamic

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@codecov
Copy link

codecov bot commented Jan 29, 2026

Codecov Report

❌ Patch coverage is 38.46154% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ommon/1769690595000-ExpandSubjectIDColumnLength.ts 30.00% 7 Missing ⚠️
...ckages/@n8n/db/src/migrations/migration-helpers.ts 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Jan 29, 2026
@blacksmith-sh

This comment has been minimized.

@afitzek afitzek force-pushed the iam-204-increase-varchar-limit-for-subjectid-column-in-postgrest-for branch from 4d165ec to ca589d8 Compare January 29, 2026 14:47
@afitzek afitzek marked this pull request as ready for review January 29, 2026 15:08
@afitzek afitzek requested a review from a team as a code owner January 29, 2026 15:08
@afitzek afitzek requested review from a team, BGZStephen, cstuncsik, guillaumejacquart and phyllis-noester and removed request for a team January 29, 2026 15:08
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 5 files

@tomi
Copy link
Collaborator

tomi commented Jan 29, 2026

I am a little concerned about having an unconstrainted column that is part of a PK. Does it make sense to be in the PK? Could we apply at least some limit to it?

@afitzek
Copy link
Contributor Author

afitzek commented Jan 29, 2026

I am a little concerned about having an unconstrainted column that is part of a PK. Does it make sense to be in the PK? Could we apply at least some limit to it?

@tomi Ah yes, this is a good point thanks. I'll change the type to some long VARCHAR. I'll do some research on what limit makes sense here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants