webdevcody / code-racer

https://code-racer-eight.vercel.app
MIT License
698 stars 520 forks source link

Prisma Schema conventions #39

Closed acollierr17 closed 1 year ago

acollierr17 commented 1 year ago

Hello!

I suggest we follow a few conventions with the Prisma schema with Postgres and, generally, a SQL database/dialect.

@map attribute

Using the @map attribute, any fields named in the schema using camelCase should be mapped to their respective column name using snake_case.

For example, with #37, there's a plan to change the field <User>.name to <User>.displayName. We can add the attribute @map("display_name") to commit this change to the database.

As most of us with Prisma knowledge know, we still use .displayName in the schema and Prisma Client. But display_name would be used in the database instead.

@@map

This is very similar to the @map attribute. However, with @@map, we map the model name to its respective database table name to follow the snake_case standard.

We currently have a User model defined. Following this standard, we can place @@map("users") at the end of the model to prepare to commit these changes.

These are the conventions I have in mind right now. As the repo progresses, I'll watch for changes to the schema!

Reference: Prisma schema reference

Ragudos commented 1 year ago

Right, I forgot about the names having to be snake_case in Prisma, that's my bad. I'll keep that in mind!

benjokazooiee commented 1 year ago

I just got this done. Working on pulling.

benjokazooiee commented 1 year ago

This has been merged and can be closed.