Skip to content

Preview/prismalint #36

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

Closed
wants to merge 2 commits into from
Closed

Preview/prismalint #36

wants to merge 2 commits into from

Conversation

alexcoderabbitai
Copy link

@alexcoderabbitai alexcoderabbitai commented Jul 15, 2025

Summary by CodeRabbit

  • New Features
    • Introduced a Prisma schema with models for users, tenants, and user roles, including field mappings and relations.
    • Added a configuration file to enforce consistent naming, ordering, and indexing conventions in Prisma schema files.

Copy link

coderabbitai bot commented Jul 15, 2025

Walkthrough

A new Prisma schema file and a Prisma linting configuration file have been introduced. The schema defines four models with explicit mappings and relations, while the linting configuration enforces naming, ordering, and indexing conventions for Prisma models and fields.

Changes

File(s) Change Summary
.prismalintrc.json Added configuration file specifying linting rules for Prisma schemas, enforcing naming and structure.
example.prisma Added schema file with datasource, generator, and four models: Users, Tenant, UserRoleFoo, UserRole.

Poem

In the garden of code, a schema now grows,
With linting rules guiding how every name flows.
Models and fields in snake_case align,
"tenantId" leads, with indexes by design.
Prisma’s new order, as neat as can be—
A rabbit’s delight in consistency! 🐇

Impact Analysis

Introduction of Prisma schema linting rules for naming and structure consistency

ℹ️ Low 🔄 Impacts behavior

A new linting configuration enforces naming conventions, field ordering, and structural rules for Prisma schema files. Developers will now receive errors or warnings if their Prisma models or fields do not comply with these standards, promoting consistency but potentially requiring schema changes to pass linting.

Test Prisma schema files with both compliant and non-compliant naming and structure to verify that linting errors and warnings are triggered as expected. Validate that developer workflows are not unduly disrupted.

🔍 Related Files
  • .prismalintrc.json

Addition of initial Prisma schema with example models and mappings

ℹ️ Low 🔄 Impacts behavior

A new Prisma schema file defines several example models, relations, and mappings to database tables and columns. This enables developers to generate a Prisma client and interact with a sample PostgreSQL database structure.

Generate the Prisma client and test basic CRUD operations for each model. Verify that relations, ignored fields, and custom mappings behave as expected in the generated client and database.

🔍 Related Files
  • example.prisma

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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 (1)

1-36: Consider pinning the prismalint version

The rule set is fairly new and still evolving. Pinning the CLI version in package.json (or a devDependencies block) will ensure future minor releases don’t break your CI unexpectedly.

example.prisma (1)

26-30: UserRoleFoo mapping looks inconsistent

The model name is singular (✅) but the mapped table name is unexpected_snake_case, which does not reflect the model’s semantics.
Consider renaming the model to something meaningful or adjusting the @@map to match the business domain.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef04b8d and 561dc6c.

📒 Files selected for processing (2)
  • .prismalintrc.json (1 hunks)
  • example.prisma (1 hunks)
🔇 Additional comments (2)
.prismalintrc.json (1)

9-14: Use correct spread token for field-order

prismalint’s schema defines the rest operator as "$rest", not "...". Using "..." will be ignored and your field ordering won’t be enforced. Please verify in your installed prismalint package (for example, search for "$rest" in its schema) and then update your config:

"field-order": [
  "error",
  {
-   "order": ["tenantId", "..."]
+   "order": ["tenantId", "$rest"]
  }
],
example.prisma (1)

20-24: No issues detected with Tenant

Naming, mapping and minimal field set look good.

Comment on lines +28 to +34
"require-field-index": [
"error",
{
"forAllRelations": true,
"forNames": ["tenantId"]
}
]
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Option name forNames looks suspicious

Up-stream docs use forFieldNames; the short form forNames is not mentioned.
If this key is wrong, the entire require-field-index rule will be ignored and the schema violations you are trying to catch (e.g. missing @@index([tenantId])) will slip through.

-        "forNames": ["tenantId"]
+        "forFieldNames": ["tenantId"]
📝 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.

Suggested change
"require-field-index": [
"error",
{
"forAllRelations": true,
"forNames": ["tenantId"]
}
]
"require-field-index": [
"error",
{
"forAllRelations": true,
"forFieldNames": ["tenantId"]
}
]
🤖 Prompt for AI Agents
In the .prismalintrc.json file between lines 28 and 34, the option name
"forNames" used in the "require-field-index" rule is incorrect and should be
changed to "forFieldNames" to match the upstream documentation. Update the key
from "forNames" to "forFieldNames" to ensure the rule is properly recognized and
enforced, preventing schema violations from being missed.

Comment on lines +6 to +9
datasource db {
provider = "postgresql"
url = "fake-url"
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Hard-coding the connection string makes local & CI setup brittle

Replace the literal "fake-url" with an env("DATABASE_URL") reference so developers and CI can supply their own credentials without touching the schema.

-  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.

Suggested change
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
"fake-url", which makes local and CI setups brittle. Replace the literal string
with env("DATABASE_URL") to load the connection string from an environment
variable, allowing developers and CI pipelines to supply their own database
credentials without modifying the schema file.

Comment on lines +31 to +35
model UserRole {
id String @id
userId String @map(name: "userid")
// No mapping.
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

UserRole lacks a relation and required index

userId is clearly intended to reference User, yet no @relation is declared and no index is present.
This will also violate the require-field-index rule (forAllRelations: true).

 model UserRole {
   id         String @id
-  userId     String @map(name: "userid")
-  // No mapping.
+  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.

Suggested change
model UserRole {
id String @id
userId String @map(name: "userid")
// No mapping.
}
model UserRole {
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's userId field lacks
a @relation attribute linking it to the User model and does not have an index,
which is required for foreign key fields. Add a proper @relation directive to
userId referencing the User model and create an index on userId to comply with
the require-field-index rule and establish the relationship correctly.

Comment on lines +11 to +18
model Users {
id String @id
emailAddress String
tenantId String
removeMe String @ignore
tenant Tenant @relation(fields: [tenantId], references: [id])
@@map(name: "users")
}
Copy link

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 multiple lint rules

  1. Model name is plural ⇒ fails model-name-grammatical-number.
  2. tenantId is not the first field ⇒ fails field-order.
  3. tenantId is missing an index ⇒ fails require-field-index.
  4. Required field removeMe is ignored ⇒ fails forbid-required-ignored-field.
-model Users {
+model User {
   id           String @id
-  emailAddress String
-  tenantId     String
-  removeMe     String @ignore
+  tenantId     String
+  emailAddress String
+  // removeMe was required but ignored. Either make it optional or drop it entirely.
+  // removeMe String? @ignore
+
+  @@index([tenantId])

Renaming the model will require cascading changes in your codebase & migrations, but it brings the schema in line with the configured rules.

📝 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.

Suggested change
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
tenantId String
emailAddress String
// removeMe was required but ignored. Either make it optional or drop it entirely.
// removeMe String? @ignore
@@index([tenantId])
tenant Tenant @relation(fields: [tenantId], references: [id])
@@map(name: "users")
}
🤖 Prompt for AI Agents
In example.prisma around lines 11 to 18, the Users model violates lint rules:
rename the model to singular form (User), move tenantId to be the first field,
add an index on tenantId, and either remove the required field removeMe or make
it optional if it must be ignored. These changes align the schema with lint
rules but will require updates in your codebase and migrations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants