-
-
Notifications
You must be signed in to change notification settings - Fork 145
fix: invalid prisma schema with format args #2677
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
Merged
ymc9
merged 5 commits into
zenstackhq:dev
from
sanny-io:fix/invalid-prisma-schema-with-format-args
May 22, 2026
+55
−1
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
03ed7a2
fix: invalid prisma schema with id formatting args
sanny-io 5541e5d
chore: add tests
sanny-io 24952f0
fix: add missing case for `uuid`
sanny-io 4843085
chore: add negative cases
sanny-io c95e8a6
fix: re-add missing cuid case
sanny-io File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { loadSchema } from '@zenstackhq/testtools'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { PrismaSchemaGenerator } from '@zenstackhq/sdk'; | ||
|
|
||
| describe('Prisma schema generation tests', () => { | ||
| it('strips format args from id functions', async () => { | ||
| const model = await loadSchema(` | ||
| model User { | ||
| id Int @id @default(autoincrement()) | ||
|
|
||
| cuid String @default(cuid()) | ||
| cuid1 String @default(cuid(1, 'cuid1_%s')) | ||
| cuid2 String @default(cuid(2, 'cuid2_%s')) | ||
|
|
||
| uuid String @default(uuid()) | ||
| uuid4 String @default(uuid(4, 'uuid4_%s')) | ||
| uuid7 String @default(uuid(7, 'uuid7_%s')) | ||
|
|
||
| ulid String @default(ulid()) | ||
| ulid1 String @default(ulid('ulid_%s')) | ||
|
|
||
| nanoid String @default(nanoid()) | ||
| nanoid12 String @default(nanoid(12, 'nanoid12_%s')) | ||
| } | ||
| `); | ||
|
|
||
| const generator = new PrismaSchemaGenerator(model); | ||
| const prismaSchemaText = await generator.generate(); | ||
|
|
||
| expect(prismaSchemaText.includes('cuid()')).toBe(true); | ||
| expect(prismaSchemaText.includes('cuid(1)')).toBe(true); | ||
| expect(prismaSchemaText.includes('cuid(2)')).toBe(true); | ||
| expect(prismaSchemaText.includes('cuid1_%s')).toBe(false); | ||
| expect(prismaSchemaText.includes('cuid2_%s')).toBe(false); | ||
|
|
||
| expect(prismaSchemaText.includes('uuid()')).toBe(true); | ||
| expect(prismaSchemaText.includes('uuid(4)')).toBe(true); | ||
| expect(prismaSchemaText.includes('uuid(7)')).toBe(true); | ||
| expect(prismaSchemaText.includes('uuid4_%s')).toBe(false); | ||
| expect(prismaSchemaText.includes('uuid7_%s')).toBe(false); | ||
|
|
||
| expect(prismaSchemaText.match(/ulid\(\)/g)).toHaveLength(2); | ||
| expect(prismaSchemaText.includes('ulid_%s')).toBe(false); | ||
|
|
||
| expect(prismaSchemaText.includes('nanoid()')).toBe(true); | ||
| expect(prismaSchemaText.includes('nanoid(12)')).toBe(true); | ||
| expect(prismaSchemaText.includes('nanoid12_%s')).toBe(false); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.