- Notifications
You must be signed in to change notification settings - Fork3
Preview/prismalint#39
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 ourterms of service andprivacy 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?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
coderabbitaibot commentedJul 15, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
WalkthroughA new Prisma schema file and a Prisma linter configuration file are introduced. The schema defines four models with specific fields, relations, and database mappings, while the linter configuration enforces naming, ordering, and indexing conventions for Prisma models and fields. No existing code entities are modified. Changes
Poem
Impact AnalysisIntroduction of strict Prisma schema linting rules📢 Medium 🔄 Impacts behavior A new Test schema files with both compliant and non-compliant patterns to verify that linting errors are triggered as expected. Validate that exceptions (e.g., "S3" and "GraphQL") are handled correctly and that the developer experience remains smooth. 🔍 Related Files
Addition of new Prisma schema models and database mappings📢 Medium 🔄 Impacts behavior A new Prisma schema introduces four models ( Generate the Prisma client and test CRUD operations for each model. Verify that relations, field mappings, and ignored fields behave as expected, and that the generated client interacts correctly with the underlying database. 🔍 Related Files
🪧 TipsChatThere are 3 ways to chat withCodeRabbit:
SupportNeed help? Create a ticket on oursupport page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 4
🧹 Nitpick comments (2)
.prismalintrc.json (2)
28-34
:Consider extending the index rule to cover composite tenant scopes
require-field-index
currently safeguards one-columntenantId
look-ups.
If your multi-tenant tables frequently use composite PKs/UKs that also includetenantId
, add"coverComposite": true
(supported since prismalint 0.8) so the rule also flags@@id([id, tenantId])
without a matching secondary index.
35-36
:Missing terminal newlinePosix tools expect a trailing newline; most editors warn when it’s absent.
Add one to avoid diff churn.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.prismalintrc.json
(1 hunks)example.prisma
(1 hunks)
🔇 Additional comments (2)
.prismalintrc.json (1)
3-8
:Confirm rule key spelling matches prismalint’s specIf the project is using
@prisma/lint-pkg
v0.6+ the option key iscompoundWords
, but earlier releases expectcompoundWord
. A typo silently disables the whitelist. Double-check the linter version so"compoundWords"
is actually respected.example.prisma (1)
26-29
:Model name mapping suggests accidental snake_case in DB
UserRoleFoo
maps tounexpected_snake_case
, which is already snake_case.
If the intention is to diverge from the default mapping to satisfy an existing table, that’s fine.
If not, you can delete@@map
and let Prisma generateuser_role_foo
.
id String @id | ||
emailAddress String | ||
tenantId String | ||
removeMe String @ignore |
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.
Ignored field is required
removeMe
isString
(required by default). Either mark it optional (String?
) or drop it; otherwise it blocks deployments despite@ignore
.
🤖 Prompt for AI Agents
In example.prisma at line 15, the field `removeMe` is marked with `@ignore` butis defined as a required `String`, which causes deployment issues. To fix this,either make the field optional by changing its type to `String?` or remove thefield entirely from the model to avoid blocking deployments.
datasource db { | ||
provider = "postgresql" | ||
url = "fake-url" | ||
} |
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.
Datasource URL should come from env var
Hard-coding"fake-url"
prevents local overrides and breaksprisma generate
in CI/CD.
Typical pattern:
- url = "fake-url"+ url = env("DATABASE_URL")
📝 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.
datasourcedb { | |
provider = "postgresql" | |
url ="fake-url" | |
} | |
datasourcedb { | |
provider = "postgresql" | |
url =env("DATABASE_URL") | |
} |
🤖 Prompt for AI Agents
In example.prisma around lines 6 to 9, the datasource URL is hard-coded as"fake-url", which prevents local environment overrides and causes issues inCI/CD pipelines. Replace the hard-coded URL with an environment variablereference using the syntax env("DATABASE_URL") to allow dynamic configurationbased on the deployment environment.
model UserRole { | ||
id String @id | ||
userId String @map(name: "userid") | ||
// No mapping. | ||
} |
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.
🛠️ Refactor suggestion
UserRole
lacks relation toUser
userId
is declared but no@relation
or@@index([userId])
is present.
Withrequire-field-index
set toforAllRelations: true
this will fail linting once a relation is added. Recommend:
model UserRole { id String @id- userId String @map(name: "userid")+ userId String @map(name: "userid")+ user User @relation(fields: [userId], references: [id])++ @@index([userId]) }
📝 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.
modelUserRole { | |
id String@id | |
userId String@map(name:"userid") | |
// No mapping. | |
} | |
modelUserRole { | |
id String@id | |
userId String@map(name:"userid") | |
user User@relation(fields:[userId],references:[id]) | |
@@index([userId]) | |
} |
🤖 Prompt for AI Agents
In example.prisma around lines 31 to 35, the UserRole model defines a userIdfield without a relation or index. To fix this, add a proper @relation attributelinking userId to the User model's id field and include an @@index on userId tosatisfy the require-field-index linting rule. This ensures the relation isexplicit and indexed for performance and linting compliance.
model Users { | ||
id String @id | ||
emailAddress String | ||
tenantId String | ||
removeMe String @ignore | ||
tenant Tenant @relation(fields: [tenantId], references: [id]) | ||
@@map(name: "users") | ||
} |
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.
🛠️ Refactor suggestion
Users
violates four freshly-added lint rules
- Model name is plural (
Users
) butmodel-name-grammatical-number
demands singular. - Required
removeMe
field is marked@ignore
, violatingforbid-required-ignored-field
. tenantId
must be the first field perfield-order
.tenantId
lacks the mandatory@@index([tenantId])
.
A minimal conforming refactor:
-model Users {- id String @id- emailAddress String- tenantId String- removeMe String @ignore- tenant Tenant @relation(fields: [tenantId], references: [id])- @@map(name: "users")-}+model User {+ tenantId String+ id String @id+ emailAddress String+ // removeMe removed – ignored required fields not allowed+ tenant Tenant @relation(fields: [tenantId], references: [id])++ @@index([tenantId])+ @@map(name: "users")+}
📝 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.
modelUsers { | |
id String@id | |
emailAddress String | |
tenantId String | |
removeMe String@ignore | |
tenant Tenant@relation(fields:[tenantId],references:[id]) | |
@@map(name:"users") | |
} | |
modelUser { | |
tenantId String | |
id String@id | |
emailAddress String | |
// removeMe removed – ignored required fields not allowed | |
tenant Tenant@relation(fields:[tenantId],references:[id]) | |
@@index([tenantId]) | |
@@map(name:"users") | |
} |
🤖 Prompt for AI Agents
In example.prisma around lines 11 to 18, fix the Users model by renaming it tosingular form (User), remove the required field 'removeMe' or make it optionalinstead of using @ignore, reorder fields so that 'tenantId' is the first field,and add an @@index([tenantId]) attribute to index the tenantId field as requiredby the lint rules.
@coderabbitai full review |
✅ Actions performedFull review triggered. |
@coderabbitai full review |
✅ Actions performedFull review triggered. |
@coderabbitai full review |
✅ Actions performedFull review triggered. |
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.
Actionable comments posted: 1
♻️ Duplicate comments (3)
example.prisma (3)
11-18
:Users
model violates four enabled lint rules
Duplicate of an existing bot comment – still unresolved.
- Model name should be singular.
tenantId
must be the first field.- Required +
@ignore
fieldremoveMe
is forbidden.- Missing
@@index([tenantId])
.Minimal compliant refactor:
-model Users {- id String @id- emailAddress String- tenantId String- removeMe String @ignore- tenant Tenant @relation(fields: [tenantId], references: [id])- @@map(name: "users")-}+model User {+ tenantId String+ id String @id+ emailAddress String @map(name: "email_address")+ tenant Tenant @relation(fields: [tenantId], references: [id])++ @@index([tenantId])+ @@map(name: "users")+}
31-35
:Add relation, index, and snake-case mapping forUserRole
Earlier bot hint still applies.model UserRole { id String @id- userId String @map(name: "userid")- // No mapping.+ userId String @map(name: "user_id")+ user User @relation(fields: [userId], references: [id])++ @@index([userId])+ @@map(name: "user_role") }
6-9
:Datasource URL must be externalisedHard-coding
"fake-url"
breaks local overrides and CI/CD secrets injection. Switch to an env var to stay 12-factor compliant.datasource db { provider = "postgresql"- url = "fake-url"+ url = env("DATABASE_URL") }
🧹 Nitpick comments (1)
.prismalintrc.json (1)
1-35
:Consider documenting the rationale behind rule exceptions
compoundWords
arrays (["S3"]
,["GraphQL"]
) are self-explanatory to us today, but future contributors won’t know why just those tokens are exempt from snake-case. Because JSON doesn’t allow comments, add a short section inCONTRIBUTING.md
(or aPRISMA_LINT_RULES.md
) that explains each exception and how to request new ones.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
.coderabbit.yaml
is excluded by none and included by none
📒 Files selected for processing (2)
.prismalintrc.json
(1 hunks)example.prisma
(1 hunks)
🧰 Additional context used
🪛 PrismaLint (0.10.2)
example.prisma
31-31: Model name must be mapped to snake case. (model-name-mapping-snake-case)
33-33: Field name must be mapped to "user_id". (field-name-mapping-snake-case)
26-26: Model name must be mapped to "user_role_foo". (model-name-mapping-snake-case)
11-11: Fields are not in the expected order: "tenantId", "...". (field-order)
11-11: Expected singular model name. (model-name-grammatical-number)
13-13: Field name must be mapped to snake case. (field-name-mapping-snake-case)
15-15: Field name must be mapped to snake case. (field-name-mapping-snake-case)
15-15: Do not ignore a required field without a default value. (forbid-required-ignored-field)
14-14: Field name must be mapped to snake case. (field-name-mapping-snake-case)
14-14: Field "tenantId" must have an index. (require-field-index)
model UserRoleFoo { | ||
id String @id | ||
@@map(name: "unexpected_snake_case") | ||
} |
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.
🛠️ Refactor suggestion
UserRoleFoo
mapping should follow snake-case convention
Rulemodel-name-mapping-snake-case
expects the map name to beuser_role_foo
.
model UserRoleFoo { id String @id- @@map(name: "unexpected_snake_case")+ @@map(name: "user_role_foo") }
📝 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.
modelUserRoleFoo { | |
id String@id | |
@@map(name:"unexpected_snake_case") | |
} | |
modelUserRoleFoo { | |
id String@id | |
@@map(name:"user_role_foo") | |
} |
🧰 Tools
🪛 PrismaLint (0.10.2)
26-26: Model name must be mapped to "user_role_foo". (model-name-mapping-snake-case)
🤖 Prompt for AI Agents
In example.prisma around lines 26 to 29, the model UserRoleFoo has a @@mapattribute with the name "unexpected_snake_case" which does not follow therequired snake-case convention. Update the @@map name to "user_role_foo" tocomply with the model-name-mapping-snake-case rule.
Uh oh!
There was an error while loading.Please reload this page.
Summary by CodeRabbit