-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
should use mapped column and table names #18
Comments
@keenahn good idea. I think I prefer to haven an option to use the names either from the models/fields or the names for |
Yeah having the option at least would be cool! I think I'd prefer to export the actual Database Schema for the diagram, even though the Prisma client surfaces another API. Another thing to look at would be to include the db type attributes such as But overall, awesome little utility, I'm starting to integrate it into my workflow! |
For the following schema with model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.DateTime(0)
updatedAt DateTime @updatedAt @map("updated_at")
email String @unique
name String? @db.VarChar(255)
@@map("user")
} DMMF{
"enums": [],
"models": [
{
"name": "User",
"dbName": "user", // 👈 @@map
"fields": [
{
"name": "id",
"kind": "scalar",
"isList": false,
"isRequired": true,
"isUnique": false,
"isId": true,
"isReadOnly": false,
"type": "Int",
"hasDefaultValue": true,
"default": { "name": "autoincrement", "args": [] },
"isGenerated": false,
"isUpdatedAt": false
},
{
"name": "createdAt",
"kind": "scalar",
"isList": false,
"isRequired": true,
"isUnique": false,
"isId": false,
"isReadOnly": false,
"type": "DateTime",
"hasDefaultValue": true,
"default": { "name": "now", "args": [] },
"isGenerated": false,
"isUpdatedAt": false
},
{
"name": "updatedAt",
"kind": "scalar",
"isList": false,
"isRequired": true,
"isUnique": false,
"isId": false,
"isReadOnly": false,
"type": "DateTime",
"hasDefaultValue": false,
"isGenerated": false,
"isUpdatedAt": true
},
{
"name": "email",
"kind": "scalar",
"isList": false,
"isRequired": true,
"isUnique": true,
"isId": false,
"isReadOnly": false,
"type": "String",
"hasDefaultValue": false,
"isGenerated": false,
"isUpdatedAt": false
},
{
"name": "name",
"kind": "scalar",
"isList": false,
"isRequired": false,
"isUnique": false,
"isId": false,
"isReadOnly": false,
"type": "String",
"hasDefaultValue": false,
"isGenerated": false,
"isUpdatedAt": false
}
],
"isGenerated": false,
"primaryKey": null,
"uniqueFields": [],
"uniqueIndexes": []
}
],
"types": []
} |
I added npm i -D [email protected] generator dbml {
provider = "node ./dist/generator.js"
mapToDbSchema = "true" // 👈 enable mapToDbSchema with the new option
}
model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
email String @unique
name String?
@@map("user") // 👈 this will be used in the dbml schema
} |
Could anybody confirm that release |
@dominikjasek Did you add |
It works on table names but not on relations, when using |
Ah good point. I might have missed that! I'll look into it soon |
@dominikjasek Please update to |
Thanks! I confirm it is working. |
hallo guy i have // This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
generator dbml {
provider = "node node_modules/prisma-dbml-generator/dist/generator.js"
mapToDbSchema = true
includeRelationFields = false
projectName = "Backend DB"
}
generator docs {
provider = "node node_modules/prisma-docs-generator"
}
generator nestgraphql {
provider = "node node_modules/prisma-nestjs-graphql"
output = "./@generated/graphql"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
displayName String @map("display_name")
password String
@@map("user")
}
model Movies {
id Int @id @default(autoincrement())
title String?
code String?
description Json?
thumbnail String
seo Seo? @relation(fields: [seoId], references: [id])
seoId Int? @map("seo_id")
movieVideo MovieVideo[]
video Video[]
@@map("movies")
}
model MovieVideo {
movieId Int @map("movie_id")
videoId Int @map("video_id")
movie Movies @relation(fields: [movieId], references: [id])
video Video @relation(fields: [videoId], references: [id])
@@id([movieId, videoId])
@@map("movie_video")
}
model Seo {
id Int @id @default(autoincrement())
title String?
description String?
keywords String[]
slug String @default(dbgenerated("'<(10,4),11>'::circle"))
thumbnail String
movies Movies[]
@@map("seo")
}
model VideoProvider {
id Int @id @default(autoincrement())
provider String
video Video[]
@@map("video_provider")
}
model Video {
id Int @id @default(autoincrement())
url String
providerId Int @map("provider_id")
provider VideoProvider @relation(fields: [providerId], references: [id])
movieVideo MovieVideo[]
movies Movies? @relation(fields: [moviesId], references: [id])
moviesId Int? @map("movies_id")
@@map("video")
}
model VideoCategory {
id Int @id @default(autoincrement())
name String?
@@map("video_category")
}
model Actor {
id Int @id @default(autoincrement())
name String?
images String[]
@@map("actor")
}
|
can you create a new option to make name field to snake case ? Because a lot of user using snake case in @Map notation |
since this is supposed to be the actual database diagram, shouldn't the generated dbml use the mapped table and column names from
@map
and@@map
?The text was updated successfully, but these errors were encountered: