Tradeoffs: datamodel.prisma to create database vs introspecting a manually configured database


#1

Does anyone have any advice on either building a datamodel first and thereby creating tables, vs building your database first and then introspecting it?

I’m in the process of experimenting with both paths. Using the datamodel to produce the DB, Prisma creates many join tables to create the relationships between your types. When I was thinking about my DB design before using Prisma, I had in mind to use a bunch of foreign keys on the same tables without needing many join tables. Just from a performance perspective this would seem the better way to go although introspecting the DB is more complicated and it doesn’t appear to be as easy to update the DB and the datamodel in the future.

What are the tradeoffs? When would it be more ideal to use one method over the other?

Much thanks.


#2

Hi,

I will prefer manually writing the datamodel as this will give you the following benefits:

  1. You will be able to use our SDL based migrations(We turn off migrations for introspected databases to prevent data loss)
  2. In the future, if you plan to change the database, it will require no change in the datamodel(current Postgres introspection uses specific directives)
  3. We also do performance optimizations for manually written datamodel.
  4. Manually writing relations is quite easy with SDL and you will not have to manage any database constraints(like foreign keys and indexes)

While it seems tempting to use introspection with a new project it will not pay off in the long. Introspection is meant to be used with existing databases with ton of data so that they can easily be used with the beautiful API that prisma provides.

Let me know if you have any other question in this regard.


#3

Thank you for your response @pantharshit00.

I was wondering about the kind of performance optimizations Prisma does for a manually written datamodel.


#4

@aryeh

I don’t know the very exact details as I do not work on the backend but I know it more efficient to query relation data via the database structure we create.


#5

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.