Skip to content

Comments

Drizzle: Enable snake casing by default#91

Closed
tomhaerter wants to merge 2 commits intoMail-0:stagingfrom
tomhaerter:drizzle-snake-case
Closed

Drizzle: Enable snake casing by default#91
tomhaerter wants to merge 2 commits intoMail-0:stagingfrom
tomhaerter:drizzle-snake-case

Conversation

@tomhaerter
Copy link
Contributor

@tomhaerter tomhaerter commented Feb 8, 2025

Quick PR to switch Drizzle ORM to snake_case by default. Here's the breakdown:

  • db/index.ts: Added { casing: "snake_case" } to the drizzle init.
  • drizzle.config.ts: Set global casing to snake_case.
  • db/schema.ts: Updated schema defs to match.

Should keep our DB columns consistent. Docs here: https://orm.drizzle.team/docs/sql-schema-declaration#camel-and-snake-casing

Summary by CodeRabbit

  • New Features

    • Introduced a standardized naming option that applies "snake_case" formatting across configurations, aiming for more uniform output.
  • Refactor

    • Streamlined schema definitions and updated formatting for improved consistency and maintainability.

@vercel
Copy link

vercel bot commented Feb 8, 2025

@tomhaerter is attempting to deploy a commit to the Projects Team on Vercel.

A member of the Team first needs to authorize it.

@tomhaerter
Copy link
Contributor Author

tomhaerter commented Feb 8, 2025

Also, to perhaps add, I introduced timestamp helpers and added timezone by default. Feel free to remove or change that as needed (totally overlooked I did that). Or let me know, and I revert that

@vercel
Copy link

vercel bot commented Feb 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
mail ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 8, 2025 7:31pm

@nizzyabi
Copy link
Collaborator

nizzyabi commented Feb 8, 2025

will this break anything @MrgSub @Praashh

@nizzyabi
Copy link
Collaborator

nizzyabi commented Feb 8, 2025

@Praashh will this break anything

@Praashh
Copy link
Contributor

Praashh commented Feb 9, 2025

@Praashh will this break anything

let's not merge this, I'll test it locally

@Praashh Praashh added the High Risk High Risk PR label Feb 9, 2025
@MrgSub
Copy link
Collaborator

MrgSub commented Feb 10, 2025

We're still early, there's nothing to "break"

@tomhaerter
Copy link
Contributor Author

@Praashh anything I can do to help to get this merged?

@MrgSub
Copy link
Collaborator

MrgSub commented Feb 19, 2025

We're looking into migrating into Prisma, closing for now

@MrgSub MrgSub closed this Feb 19, 2025
@ahmetskilinc
Copy link
Contributor

Opening again - would be beneficial when writing new schemas

@ahmetskilinc ahmetskilinc reopened this Mar 21, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 21, 2025

Walkthrough

The changes introduce a new configuration option, casing: 'snake_case', to both mail and database configuration files. Updates standardize string quotation marks from double to single quotes across configuration files, import statements, and schema definitions. The drizzle function call in the database connection file is updated to include the new option, and table definitions in the schema file are streamlined by removing redundant string parameters in field creation functions.

Changes

File(s) Change Summary
apps/mail/drizzle.config.ts Added new property casing: 'snake_case' in the exported configuration object.
packages/db/drizzle.config.ts Updated string quotes (double → single) and added property casing: 'snake_case' in the exported configuration object.
packages/db/src/index.ts Changed import quotes to single, adjusted the environment variable conditional check, and updated the drizzle call to include casing: 'snake_case'.
packages/db/src/schema.ts Switched double quotes to single quotes in table definitions and removed redundant string parameters in the field creation functions.

Sequence Diagram(s)

sequenceDiagram
    participant App as Application (index.ts)
    participant Drizzle as Drizzle ORM
    participant Formatter as Identifier Formatter

    App->>Drizzle: Call drizzle(conn, { schema, casing: 'snake_case' })
    Drizzle->>Formatter: Apply snake_case formatting
    Formatter-->>Drizzle: Return formatted identifiers
    Drizzle-->>App: Return configured database connection
Loading

Possibly related PRs

Suggested reviewers

  • MrgSub

Poem

I'm just a rabbit, hopping with glee,
Coding in style, as neat as can be,
With snake_case in config, our paths align,
Single quotes now making our code divine,
In the meadow of code, I cheer and bound—
A joyful hop where new features are found!
🐰🎉


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c4ee128 and bb57614.

📒 Files selected for processing (4)
  • apps/mail/drizzle.config.ts (1 hunks)
  • packages/db/drizzle.config.ts (1 hunks)
  • packages/db/src/index.ts (2 hunks)
  • packages/db/src/schema.ts (1 hunks)
🔇 Additional comments (13)
packages/db/drizzle.config.ts (2)

11-11: Properly enabling snake_case casing for database columns

The addition of casing: 'snake_case' aligns with the PR objective of configuring Drizzle ORM to use snake_case as the default naming convention for database columns, which will maintain consistency across the database schema.

For more information on casing options in Drizzle ORM, refer to the official documentation.


1-10: Standardized string quotation style

Consistent use of single quotes across the configuration file improves code style consistency.

apps/mail/drizzle.config.ts (1)

11-11: Properly enabling snake_case casing for mail app database columns

Adding the casing: 'snake_case' configuration in the mail app's Drizzle config ensures consistent naming convention across all database interactions in the application, matching the changes in the packages/db configuration.

packages/db/src/index.ts (2)

17-17: Applied snake_case casing to database connection

Adding the casing: 'snake_case' option to the drizzle connection configuration ensures that queries will use snake_case column names, aligning with the global configuration in drizzle.config.ts.

This change properly configures the database connection to use the snake_case convention when interacting with the database tables.


1-15: Standardized string quotation style

Consistent use of single quotes for string literals improves code style consistency throughout the codebase.

packages/db/src/schema.ts (8)

5-14: Simplified field definitions for user table

Removing explicit string arguments from the field definition functions streamlines the schema, relying on the snake_case configuration to automatically convert camelCase property names to snake_case column names.

This works correctly because you've set casing: 'snake_case' in the drizzle configuration, ensuring field names like emailVerified will be properly mapped to email_verified in the database.


16-27: Simplified field definitions for session table

The field definitions have been streamlined by removing redundant string parameters, allowing Drizzle to handle column naming based on the configured snake_case naming convention.


29-45: Simplified field definitions for account table

Removed redundant string arguments from field definitions, relying on the configured snake_case naming convention to automatically handle column naming.

For fields like accessTokenExpiresAt and refreshTokenExpiresAt, this will correctly map to access_token_expires_at and refresh_token_expires_at in the database.


47-54: Simplified field definitions for verification table

Fields are now defined without explicit string parameters, relying on the snake_case configuration to handle column naming consistently.


56-61: Simplified field definitions for early_access table

Field definitions have been streamlined by removing redundant string parameters, letting Drizzle handle column naming based on the snake_case configuration.

Note that this table name already uses snake_case format (early_access), which aligns well with the new convention.


63-78: Simplified field definitions for connection table

Removed redundant string arguments from all field definitions, allowing the Drizzle snake_case configuration to handle column naming.


80-89: Simplified field definitions for summary table

Field definitions have been streamlined by removing explicit string parameters, resulting in cleaner code while maintaining the same database schema through the snake_case configuration.


91-103: Simplified field definitions for note table

Field definitions now rely on the snake_case configuration rather than explicit string parameters, resulting in cleaner and more maintainable code.

Methods like defaultNow() and default values continue to work as expected with this simplified syntax.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

@tomhaerter
Copy link
Contributor Author

@ahmetskilinc updated my changes to reflect the latest schema. shouldn't be a breaking change

@tomhaerter tomhaerter changed the base branch from main to staging March 21, 2025 19:49
@MrgSub MrgSub closed this Apr 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

High Risk High Risk PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants