Usage of `@map` and `@@map` as a best practice to name tables and columns in a database

Say we have a legacy database somewhere that has its table names and column names. One way to use @map and @@map is to ensure that the names of our models and fields map to the names of the tables and columns, respectively in that database. Apart from this use case, can I use these as a best practice whenever I am creating my Models where essentially a legacy database does not exist but I am building from scratch. Example: When I define a Model named Category and I use
model Category {
id Int @id @default(autoincrement())
name String
posts Post[]

@@map("categories")
}
model Category {
id Int @id @default(autoincrement())
name String
posts Post[]

@@map("categories")
}
Here the reason for using @@map is just to ensure that the new table created in my database has the name categories . Essentially, this way I am thinking about what names I can pick for the columns and tables in my real database.
3 Replies
Prisma AI Help
Prisma AI Help2mo ago
You decided to hold for human wisdom. We'll chime in soon! Meanwhile, #ask-ai is there if you need a quick second opinion.
Nurul
Nurul2mo ago
Hey 👋 Yes, you can use @map and @@map as a best practice even when building a database from scratch. This approach allows you to define your Prisma models and fields using naming conventions that are more natural or preferred in your application code, while still controlling the exact names used in the underlying database.
Abdullah Zeeshan
Abdullah ZeeshanOP2mo ago
Thanks so much ❤️ .

Did you find this page helpful?