-
Notifications
You must be signed in to change notification settings - Fork 5
Prismalint Showcase #29
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
Conversation
WalkthroughA new Prisma schema file and a Prisma linter configuration file have been added. The schema defines four models with various fields, relationships, and database mappings. The linter configuration enforces naming conventions, field ordering, and index requirements for Prisma models and fields. Changes
Poem
Impact AnalysisIntroduction of new Prisma schema and client generation configuration📢 Medium 🔗 Impacts API 🔄 Impacts behavior A new Prisma schema is introduced, defining four database models and configuring Prisma Client generation for JavaScript. This enables users to interact with new database tables and fields, and to generate a Prisma Client for application development. The schema establishes model structures, field mappings, and relationships, directly impacting how developers define, query, and manage data in the application. Test Prisma Client generation and validate that all defined models and relations are accessible and function as expected. Verify CRUD operations for each model, check field mappings, and ensure that ignored fields and relations behave correctly. Confirm that the database schema matches the intended design. 🔍 Related Files
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support 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
CodeRabbit Configuration File (
|
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)
3-8
: Consider consolidatingcompoundWords
exceptions across rules
"S3"
is exempted for field names but not for model names, while"GraphQL"
is exempted for model names but not for field names. Unless you have a strong reason for this asymmetry, keep the allow-list identical across the two snake-case rules to avoid surprising false positives.
28-34
:forAllRelations
already implies every field – redundant filterWhen
forAllRelations
istrue
, the engine will run the rule for every relation field regardless of its name. KeepingforNames: ["tenantId"]
is therefore redundant (and mildly confusing). Either dropforAllRelations
or dropforNames
to make the intent crystal-clear.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.prismalintrc.json
(1 hunks)example.py
(1 hunks)
🧰 Additional context used
🪛 Ruff (0.12.2)
example.py
1-1: SyntaxError: Simple statements must be separated by newlines or semicolons
1-1: SyntaxError: Simple statements must be separated by newlines or semicolons
2-2: SyntaxError: Expected an expression or a '}'
3-3: SyntaxError: Expected ',', found name
3-3: SyntaxError: Expected ',', found '='
6-6: SyntaxError: Simple statements must be separated by newlines or semicolons
6-6: SyntaxError: Simple statements must be separated by newlines or semicolons
7-7: SyntaxError: Expected an expression or a '}'
8-8: SyntaxError: Expected ',', found name
8-8: SyntaxError: Expected ',', found '='
11-11: SyntaxError: Simple statements must be separated by newlines or semicolons
11-11: SyntaxError: Simple statements must be separated by newlines or semicolons
12-12: SyntaxError: Expected ',', found name
13-13: SyntaxError: Expected ',', found name
13-13: SyntaxError: Expected ',', found name
14-14: SyntaxError: Expected ',', found name
14-14: SyntaxError: Expected ',', found name
15-15: SyntaxError: Expected ',', found name
15-15: SyntaxError: Expected ',', found name
16-16: SyntaxError: Expected ',', found name
16-16: SyntaxError: Expected ',', found name
16-16: SyntaxError: Expected ',', found ':'
16-16: SyntaxError: Expected ',', found ':'
17-17: SyntaxError: Expected an expression
17-17: SyntaxError: Expected ',', found ':'
20-20: SyntaxError: Simple statements must be separated by newlines or semicolons
20-20: SyntaxError: Simple statements must be separated by newlines or semicolons
21-21: SyntaxError: Expected ',', found name
22-22: SyntaxError: Expected ',', found name
22-22: SyntaxError: Expected ',', found name
23-23: SyntaxError: Expected an expression
23-23: SyntaxError: Expected ',', found ':'
26-26: SyntaxError: Simple statements must be separated by newlines or semicolons
26-26: SyntaxError: Simple statements must be separated by newlines or semicolons
27-27: SyntaxError: Expected ',', found name
28-28: SyntaxError: Expected an expression
28-28: SyntaxError: Expected ',', found ':'
31-31: SyntaxError: Simple statements must be separated by newlines or semicolons
31-31: SyntaxError: Simple statements must be separated by newlines or semicolons
32-32: SyntaxError: Expected ',', found name
33-33: SyntaxError: Expected ',', found name
33-33: SyntaxError: Expected ',', found name
33-33: SyntaxError: Expected ',', found ':'
34-34: SyntaxError: Expected ',', found name
35-35: SyntaxError: Expected an identifier
example.py
Outdated
generator client { | ||
provider = "prisma-client-js" | ||
output = "../generated/prisma/client" | ||
} |
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.
Wrong file extension – Prisma schema should use .prisma
The file is a Prisma schema but is saved with a .py
extension.
Tools (formatter, IDE plugins, CI linters) will fail to recognise it and the Ruff errors shown in the pipeline stem from this mismatch.
Rename the file to example.prisma
(or any *.prisma
) so that Prisma-aware tooling kicks in.
🧰 Tools
🪛 Ruff (0.12.2)
1-1: SyntaxError: Simple statements must be separated by newlines or semicolons
1-1: SyntaxError: Simple statements must be separated by newlines or semicolons
2-2: SyntaxError: Expected an expression or a '}'
3-3: SyntaxError: Expected ',', found name
3-3: SyntaxError: Expected ',', found '='
🤖 Prompt for AI Agents
In example.py lines 1 to 4, the file contains a Prisma schema but has a .py
extension, causing tooling and linters to fail. Rename the file from example.py
to example.prisma to ensure Prisma-aware tools and formatters recognize and
process it correctly.
example.py
Outdated
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
looks like a placeholder
The trailing Foo
suggests this model is temporary or experimental.
If it is intentional, document its purpose; if not, drop or rename it before the linter forces a rename anyway (singular, meaningful name + snake-case mapping).
🧰 Tools
🪛 Ruff (0.12.2)
26-26: SyntaxError: Simple statements must be separated by newlines or semicolons
26-26: SyntaxError: Simple statements must be separated by newlines or semicolons
27-27: SyntaxError: Expected ',', found name
28-28: SyntaxError: Expected an expression
28-28: SyntaxError: Expected ',', found ':'
🤖 Prompt for AI Agents
In example.py around lines 26 to 29, the model name `UserRoleFoo` appears to be
a placeholder due to the trailing `Foo`. Rename the model to a meaningful,
singular name that reflects its purpose, and update the @@map attribute to use a
snake_case table name matching the new model name. If the model is intentional
but temporary, add a comment explaining its purpose to avoid confusion.
example.py
Outdated
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
userId
mapping is not snake_case
userId String @map(name: "userid")
fails the field-name-mapping-snake-case
rule.
Rename the column to user_id
(or add "userid"
to the compoundWords
allow-list) to stay compliant:
-userId String @map(name: "userid")
+userId String @map(name: "user_id")
📝 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.
model UserRole { | |
id String @id | |
userId String @map(name: "userid") | |
// No mapping. | |
} | |
model UserRole { | |
id String @id | |
userId String @map(name: "user_id") | |
// No mapping. | |
} |
🧰 Tools
🪛 Ruff (0.12.2)
31-31: SyntaxError: Simple statements must be separated by newlines or semicolons
31-31: SyntaxError: Simple statements must be separated by newlines or semicolons
32-32: SyntaxError: Expected ',', found name
33-33: SyntaxError: Expected ',', found name
33-33: SyntaxError: Expected ',', found name
33-33: SyntaxError: Expected ',', found ':'
34-34: SyntaxError: Expected ',', found name
35-35: SyntaxError: Expected an identifier
🤖 Prompt for AI Agents
In example.py around lines 31 to 35, the userId field mapping uses "userid"
which is not in snake_case and violates the field-name-mapping-snake-case rule.
To fix this, rename the mapped column from "userid" to "user_id" to comply with
snake_case naming conventions, or alternatively add "userid" to the
compoundWords allow-list if that naming must be preserved.
example.py
Outdated
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.
Multiple lint violations in Users
model
- Model name
Users
is plural – violatesmodel-name-grammatical-number: singular
. tenantId
is not the first field – violatesfield-order
.tenantId
lacks an@index
– violatesrequire-field-index
.removeMe
is required and@ignore
d – violatesforbid-required-ignored-field
.
A minimal compliant refactor would look like:
-model Users {
+model User {
+ tenantId String @index
id String @id
emailAddress String
- tenantId String
- removeMe String @ignore
+ removeMe String? @ignore // optional or delete field
tenant Tenant @relation(fields: [tenantId], references: [id])
@@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.
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 @index | |
id String @id | |
emailAddress String | |
removeMe String? @ignore // optional or delete field | |
tenant Tenant @relation(fields: [tenantId], references: [id]) | |
@@map(name: "users") | |
} |
🧰 Tools
🪛 Ruff (0.12.2)
11-11: SyntaxError: Simple statements must be separated by newlines or semicolons
11-11: SyntaxError: Simple statements must be separated by newlines or semicolons
12-12: SyntaxError: Expected ',', found name
13-13: SyntaxError: Expected ',', found name
13-13: SyntaxError: Expected ',', found name
14-14: SyntaxError: Expected ',', found name
14-14: SyntaxError: Expected ',', found name
15-15: SyntaxError: Expected ',', found name
15-15: SyntaxError: Expected ',', found name
16-16: SyntaxError: Expected ',', found name
16-16: SyntaxError: Expected ',', found name
16-16: SyntaxError: Expected ',', found ':'
16-16: SyntaxError: Expected ',', found ':'
17-17: SyntaxError: Expected an expression
17-17: SyntaxError: Expected ',', found ':'
🤖 Prompt for AI Agents
In example.py around lines 11 to 18, the Users model has multiple lint issues:
the model name should be singular, tenantId must be the first field, tenantId
needs an @index attribute, and removeMe cannot be both required and ignored.
Rename the model to User, move tenantId to be the first field, add @index to
tenantId, and either remove the removeMe field or make it optional if it must be
ignored.
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: 3
🧹 Nitpick comments (2)
example.prisma (2)
20-24
: Minor: add defaults & uniqueness onTenant
Consider
@default(uuid())
forid
and@unique
onname
to prevent duplicates.-model Tenant { - id String @id - name String - @@map(name: "tenant") -} +model Tenant { + id String @id @default(uuid()) + name String @unique + + @@map(name: "tenant") +}
26-29
: Demo modelUserRoleFoo
breaks naming rulesThe mixed-case model mapped to
unexpected_snake_case
looks intentional for a lint showcase, but in production code this would be rejected by the configured rules. Either delete it or rename to a compliant model name.
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.
🛠️ Refactor suggestion
Database URL must come from environment variable
Hard-coding a placeholder string will break migrations & deployments. Prisma recommends env("DATABASE_URL")
to pick up per-environment credentials.
-datasource db {
- provider = "postgresql"
- url = "fake-url"
-}
+datasource db {
+ provider = "postgresql"
+ 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.
datasource db { | |
provider = "postgresql" | |
url = "fake-url" | |
} | |
datasource db { | |
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 a
placeholder string, which will cause issues with migrations and deployments.
Replace the hard-coded URL with an environment variable reference by using
env("DATABASE_URL") to ensure the database URL is dynamically loaded from the
environment configuration.
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
model violates several lint & modelling best-practices
• Model name is plural – linter rule expects singular.
• id
lacks a default; every insert must supply it manually.
• emailAddress
probably needs @unique
.
• tenantId
should be indexed for FK look-ups.
• removeMe
is both required and @ignore
, which the linter flags; simply remove it.
-model Users {
- id String @id
- emailAddress String
- tenantId String
- removeMe String @ignore
- tenant Tenant @relation(fields: [tenantId], references: [id])
- @@map(name: "users")
-}
+model User {
+ id String @id @default(uuid())
+ emailAddress String @unique
+ tenantId String
+ tenant Tenant @relation(fields: [tenantId], references: [id])
+
+ @@map(name: "users")
+ @@index([tenantId])
+}
Note: Renaming the model is a breaking change; plan a migration accordingly.
🤖 Prompt for AI Agents
In example.prisma around lines 11 to 18, the Users model should be renamed to
singular form to follow naming conventions, add a default value to the id field
(e.g., use @default(uuid()) for automatic ID generation), add @unique to
emailAddress to enforce uniqueness, add an index to tenantId for efficient
foreign key lookups, and remove the removeMe field entirely since it is both
required and ignored, which is invalid. Plan a migration to handle the model
renaming as it is a breaking change.
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
missing relation & table mapping
userId
is scalar-only; without a relation you lose referential integrity. Also, table name is implicit – add @@map
for consistency.
model UserRole {
id String @id
- userId String @map(name: "userid")
- // No mapping.
+ userId String @map(name: "userid")
+ user User @relation(fields: [userId], references: [id])
+
+ @@map(name: "user_role")
+ @@index([userId])
}
🤖 Prompt for AI Agents
In example.prisma around lines 31 to 35, the UserRole model's userId field lacks
a relation definition, which means referential integrity is not enforced. Add a
relation attribute to userId linking it to the User model's id field. Also, add
an @@map attribute at the model level to explicitly specify the database table
name for consistency and clarity.
Summary by CodeRabbit