-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Possibility to skip some models #45
Comments
Hey @igeligel, thanks for the suggestion. What is |
Hi @iiian, you're correct next-auth is part of the next.js ecosystem. It is a package that makes it fairly simple to setup authentication for a website. It supports various providers, and Prisma is one of them. You can check the provider documentation here, the expected schema has strict requirements for casing, some fields of the generated Prisma client are expected to be snake_case (such as We faced the same issue as @igeligel, I've myself been bitten by the casing while cleaning up our DB schema. I now would like to rely on a tool such as |
Got it, thanks for motivating the need--the problem makes sense to me now. Just commenting, seems like the disable feature is useful, and simultaneously the same could be achieved if just overrides for syntax expectations were allowed: // prisma-case-format:override
// --field-case=camel
// --map-field-case=snake
model GotchaNextAuthModel {
// now fields are forced to format as camel, with snake @map anno's
tokenType String @map('token_type')
expiresAt String @map('expires_at')
}
// prisma-case-format:end-override That way, |
I like comments as the trigger, but we'll probably end up wanting to do a commandline arg as well, I'll have to think on that. Ultimately, I think I hope to support this feature by the end of the year--is that soon enough? |
The override syntax is a neat idea, that would make it nicer to handle models that require a specific casing. Looking at next-auth models, I would say that An idea would be to support override comments on the same line, in addition to an override block like the one you suggested. // 👇 set a default case for the model, for both the Prisma client and columns @map()
//
// prisma-case-format:override(field-case=camel,map-field-case=snake)
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
// 👇 override some columns, only --field-case
refresh_token String? @db.Text // prisma-case-format:override(field-case=snake)
access_token String? @db.Text // prisma-case-format:override(field-case=snake)
expires_at Int? // prisma-case-format:override(field-case=snake)
token_type String? // prisma-case-format:override(field-case=snake)
scope String?
id_token String? @db.Text // prisma-case-format:override(field-case=snake)
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
}
// prisma-case-format:end-override
Here the logic would be straight forward:
I don't think something more complicated such as nested override blocks would make too much sense here, that wouldn't be too readable. What do you think? I slightly changed your override syntax to make it simpler to use inlined, but that's just a suggestion and my personal preference 😄.
Oh for sure, yes! |
Yep sounds good to me -- I guess we'll just have to say "it has to be the first part of a comment", because we're seizing control of the inline comment, which might clash with other functionality put forth by I'm almost wondering if there's not value in just creating a Are there any comments pushing back against |
I had to look it up because I wasn't sure but it doesn't seem to be an official project made by Vercel: https://opencollective.com/nextauth. The package name sounds official but it is made by the community at large. I'm myself not too familiar with Next.js and its community, I couldn't tell you if this schema weirdness is something people push back against or if it seen as normal. I literally learned about next-auth 2 days ago when doing changes to tables used by a Next.js application and broke signin/signup after renaming some specific columns used by next-auth's Github provider (they aren't documented anywhere on next-auth website or GitHub repo, I only found out about it thanks to Prisma having really good error messages). So, not really a fan :) That's why I've been looking for a linter/auto-formatter.
Yes I agree, that's a fair point. |
I found this comment:
|
I'll start with the inline # alternative to specifying cmd line args
defaults:
table: pascal,plural
field: camel
enum: pascal
mapTable: snake
mapField: snake
mapEnum: snake
uses_next_auth: true # optional: apply default conventions for "next-auth" models
overrides:
ModelX:
defaults: # specify overridden defaults for this scope
table: snake,singular
mapTable: pascal
fields: # apply element-wise overrides
# alternate short-hand; note this works in model-wise defaults & global defaults
userId: field=pascal;mapField=pascal,plural
other_model: disable # shut it off entirely |
Okay, so I ended up not going for the The next PR will contain updates for the # file: .prisma-case-format
uses_next_auth: false
default: ...
override: #edited -- not overrides!
Account:
default: 'table=pascal; mapTable=pascal;'
field:
id: 'field=camel; mapField=camel'
userId: 'field=camel; mapField=camel'
type: 'field=camel; mapField=camel'
provider: 'field=camel; mapField=camel'
providerAccountId: 'field=camel; mapField=camel'
refresh_token: 'field=snake; mapField=snake'
access_token: 'field=snake; mapField=snake'
expires_at: 'field=snake; mapField=snake'
token_type: 'field=snake; mapField=snake'
scope: 'field=snake; mapField=snake'
id_token: 'field=snake; mapField=snake'
session_state: 'field=snake; mapField=snake'
user: 'field=snake; mapField=snake'
Session:
default: 'table=pascal; mapTable=pascal; field=camel; mapField=camel'
User:
default: 'table=pascal; mapTable=pascal; field=camel; mapField=camel'
VerificationToken:
default: 'table=pascal; mapTable=pascal; field=camel; mapField=camel' note that the above example is strictly equivalent to # file: .prisma-case-format
uses_next_auth: true or to specifying the commandline argument |
|
Hey @iiian, |
That was fast! Thanks so much, I will try it out right away :) |
Ok, I tried the beta version. Here is the diff I get after running --- a/services/shared/prisma/schema.prisma
+++ b/services/shared/prisma/schema.prisma
@@ -12,24 +12,24 @@ generator client {
/// Table required by Next-Auth
model Account {
/// Columns required by Next-Auth
- id String @id @default(cuid())
- userId String @map("user_id")
- user User @relation(fields: [userId], references: [id], onDelete: Cascade)
- type String
- provider String
- providerAccountId String @map("provider_account_id")
- refresh_token_expires_in Int?
- refresh_token String? @db.Text
- access_token String? @db.Text
- expires_at Int?
- token_type String?
- scope String?
- id_token String? @db.Text
- session_state String?
+ id String @id @default(cuid())
+ userId String @map("user_id")
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
+ type String
+ provider String
+ providerAccountId String @map("provider_account_id")
+ refreshTokenExpiresIn Int? @map("refresh_token_expires_in")
+ refreshToken String? @map("refresh_token") @db.Text
+ accessToken String? @map("access_token") @db.Text
+ expiresAt Int? @map("expires_at")
+ tokenType String? @map("token_type")
+ scope String?
+ idToken String? @map("id_token") @db.Text
+ sessionState String? @map("session_state") My config file: # file: .prisma-case-format
default: 'table=pascal; mapTable=snake,plural; field=camel; mapField=snake;'
overrides:
Account:
default: 'table=pascal; mapTable=pascal;'
field:
id: 'field=camel; mapField=camel'
userId: 'field=camel; mapField=camel'
type: 'field=camel; mapField=camel'
provider: 'field=camel; mapField=camel'
providerAccountId: 'field=camel; mapField=camel'
refresh_token_expires_in: 'field=snake; mapField=snake'
refresh_token: 'field=snake; mapField=snake'
access_token: 'field=snake; mapField=snake'
expires: 'field=snake; mapField=snake'
token_type: 'field=snake; mapField=snake'
scope: 'field=snake; mapField=snake'
id_token: 'field=snake; mapField=snake'
session_state: 'field=snake; mapField=snake'
user: 'field=snake; mapField=snake'
Session:
default: 'table=pascal; mapTable=pascal; field=camel; mapField=camel'
User:
default: 'table=pascal; mapTable=pascal; field=camel; mapField=camel'
VerificationToken:
default: 'table=pascal; mapTable=pascal; field=camel; mapField=camel' Looking at fields such as I also noticed an issue for fields mapping to a DB column with a different name (not just a different case): @@ -73,121 +73,121 @@ model User {
/// Table required by Next-Auth
model VerificationToken {
/// Columns required by Next-Auth
identifier String
token String @unique
- expires DateTime @map("expires_at") @db.Timestamptz(3)
+ expires DateTime @db.Timestamptz(3)
@@unique([identifier, token])
@@map("verification_tokens")
} Here the DB column is |
Did you try it with |
Okay, bizarre. It seems to be working when you use |
😄 it's Anyway, renaming it to |
Btw. tried and it works! Thanks so much! |
Great suggestion, I think somebody else had previously requested this feature but didn't do a great job of explaining it |
Thanks @iiian for the quick implementation 🙏. And updates to the readme are clear and easy to follow, that's appreciated! |
Some bug report:
config: # file: .prisma-case-format
uses_next_auth: true schema:
If the |
Thanks @igeligel ! I was actually trying to replicate this. |
Where is |
Would like to have an option to disable the linter for some models.
Proposal:
I came across this issue when wanting to use next-auth
The text was updated successfully, but these errors were encountered: