-
Notifications
You must be signed in to change notification settings - Fork 14
enhance: align generated Klicker elements with native knowledge graphs #5383
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
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 |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| const CONTAINER_PATTERN = /^(?!.*--)[a-z0-9](?:[a-z0-9-]{1,61}[a-z0-9])$/ | ||
| const SHA256_PATTERN = /^[0-9a-f]{64}$/ | ||
| const MAX_BLOB_PREFIX_LENGTH = 700 | ||
|
|
||
| export const DEFAULT_KB_GRAPH_BUNDLE_CONTAINER = 'kg-graph-artifacts' | ||
| export const DEFAULT_KB_GRAPH_BUNDLE_PREFIX = 'graph-artifacts' | ||
|
|
||
| function containsControlCharacter(value: string) { | ||
| return Array.from(value).some((character) => character.charCodeAt(0) <= 31) | ||
|
Check warning on line 9 in packages/graphql/src/services/kbGraphBundleCoordinates.ts
|
||
| } | ||
|
|
||
| function canonicalBlobPrefix(value: string): string | null { | ||
| const normalized = value.trim().replace(/^\/+|\/+$/gu, '') | ||
|
Check warning on line 13 in packages/graphql/src/services/kbGraphBundleCoordinates.ts
|
||
| const segments = normalized.split('/') | ||
| return normalized.length > 0 && | ||
| normalized.length <= MAX_BLOB_PREFIX_LENGTH && | ||
| !normalized.includes('\\') && | ||
| !normalized.includes('?') && | ||
| !normalized.includes('#') && | ||
| !containsControlCharacter(normalized) && | ||
| segments.every((segment) => segment && segment !== '.' && segment !== '..') | ||
| ? normalized | ||
| : null | ||
| } | ||
|
|
||
| export function getKBGraphBundleCoordinates( | ||
| buildId: string, | ||
| env: NodeJS.ProcessEnv = process.env | ||
| ) { | ||
| const containerName = | ||
| env.KB_GRAPH_ARTIFACT_CONTAINER?.trim() || DEFAULT_KB_GRAPH_BUNDLE_CONTAINER | ||
| const configuredPrefix = | ||
| env.KB_GRAPH_ARTIFACT_PREFIX?.trim() || DEFAULT_KB_GRAPH_BUNDLE_PREFIX | ||
| const prefix = canonicalBlobPrefix(configuredPrefix) | ||
| if (!CONTAINER_PATTERN.test(containerName) || prefix === null) { | ||
| throw new Error('KB graph bundle storage configuration is invalid') | ||
| } | ||
| return { | ||
| containerName, | ||
| blobPrefix: `${prefix}/${buildId}/${buildId}`, | ||
| storageName: buildId, | ||
| } | ||
| } | ||
|
|
||
| export function expectedKBGraphManifestBlobName( | ||
| blobPrefix: string, | ||
| bundleSha256: string | ||
| ): string | null { | ||
| const prefix = canonicalBlobPrefix(blobPrefix) | ||
| return prefix !== null && SHA256_PATTERN.test(bundleSha256) | ||
| ? `${prefix}/${bundleSha256}/manifest.json` | ||
| : null | ||
| } | ||
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.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: uzh-bf/klicker-uzh
Length of output: 863
🏁 Script executed:
Repository: uzh-bf/klicker-uzh
Length of output: 9118
🏁 Script executed:
Repository: uzh-bf/klicker-uzh
Length of output: 8859
🌐 Web query:
Prisma 7.8.0 PostgreSQL compound unique constraint default name identifier length 63 truncation map migration drift💡 Result:
In PostgreSQL, identifiers (including index and constraint names) have a maximum length of 63 bytes (NAMEDATALEN - 1) [1]. When Prisma generates a default name for a compound unique constraint (e.g., table_field1_field2_key), and that name exceeds this limit, PostgreSQL silently truncates it [2][1]. Migration drift occurs because Prisma's internal state expects the full, non-truncated name, while the database reports the truncated version during introspection [3][4]. When
prisma migrate devruns, it detects a mismatch between the schema it expects and the truncated identifier in the database, leading it to attempt a "fix" (usually dropping and recreating the index/constraint), which results in an infinite loop of migration drift [3][4]. To resolve or prevent this drift, use themapargument within your@@uniqueattribute to explicitly set a name that is shorter than the 63-byte limit [4][5][6]. Example: model User { id Int@idlongColumnNameWithTooManyCharacters String anotherLongColumnName String @@unique([longColumnNameWithTooManyCharacters, anotherLongColumnName], map: "user_short_key") } Note that recent versions of Prisma, including 7.8.0, have improved identifier length validation to measure bytes rather than characters, which helps catch these issues earlier in the schema parsing phase, especially when using multibyte (non-ASCII) characters that consume more than one byte per character [1][7]. If you encounter drift, explicitly mapping the name is the standard and most reliable solution [4].Citations:
prisma migrate devexceeding 63 characters causing errors due to truncating prisma/orm#9415🌐 Web query:
Prisma 7.8.0 "must be 63 characters or shorter" constraint name @@unique PostgreSQL💡 Result:
In PostgreSQL, the maximum identifier length is 63 bytes [1][2]. Prisma ORM manages this limit by automatically truncating default-generated names to fit within this constraint [3]. If you are encountering issues with
@@uniqueor other constraint names, consider the following technical details: 1. Automatic Truncation and Deterministic Naming: When you do not provide an explicit name, Prisma generates a deterministic name based on the table and column names [3]. If this generated name exceeds the 63-byte limit, Prisma truncates it to ensure it remains valid for PostgreSQL [3]. 2. Wire-Name Prefix and Hashing: For indexes, Prisma often uses a "wire-name" strategy [4][5][6]. It reserves a portion of the identifier (up to 54 characters) for a prefix and appends a 9-character suffix (an underscore followed by an 8-character content hash) to ensure uniqueness [4][5][6]. Because the final identifier must not exceed 63 bytes, if your authored prefix is too long, you will trigger a validation error (specificallyCONTRACT.WIRE_NAME_PREFIX_TOO_LONG) [5]. 3. ThemapArgument: To avoid issues with automatic truncation or long identifier conflicts, you can use themapargument within your@@uniqueattribute to explicitly set the constraint's name in the database [7][3]. Example: @@unique([field1, field2], map: "my_custom_constraint_name") Usingmapforces Prisma to use the exact name provided for the database constraint, bypassing the default generation and truncation logic [3][6]. 4. Byte vs. Character Length: Note that PostgreSQL's 63-limit is measured in bytes, not characters [1][2]. If your schema uses non-ASCII characters (e.g., Cyrillic or other multibyte UTF-8 characters), a name shorter than 63 characters may still exceed the 63-byte limit and cause errors [1]. Prisma has been updated in recent versions to validate identifier lengths based on UTF-8 bytes to prevent these silent truncation issues [1]. If you are using Prisma 7.8.0, ensure that any custom names defined inmapdo not exceed 63 bytes to avoid database-level errors [1][2]. If you continue to see errors regarding "key too long," check if the combined length of your schema-defined name and any automatic suffixes conflicts with the database limit [5].Citations:
Pin the unique-constraint name in both schema files.
The migration uses
GeneratedElementDraft_buildId_sourceElementId_duplication_key, but the schema derives a 66-character name. PostgreSQL limits identifiers to 63 bytes, so Prisma may detect drift or propose a rename. Addmap: "GeneratedElementDraft_buildId_sourceElementId_duplication_key"here and inpackages/prisma/src/prisma/schema/knowledge.prisma.🤖 Prompt for AI Agents