question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Include `@@index` and `@map` information in `getDMMF`

See original GitHub issue

Problem

Given schema

model UserEmailHistory {
  id               Int       @id @default(autoincrement())
  user_alias       String    @map("alias")
  send_count       Int
  historyable_id   Int?
  historyable_type String?
  user_id          Int
  created_at       DateTime?
  updated_at       DateTime? @updatedAt

  @@index([user_id], name: "user_email_history_user_id_foreign")
  @@map("user_email_history")
}

using getDMMF will dump as

{
  "name": "UserEmailHistory",
  "isEmbedded": false,
  "dbName": "user_email_history",
  "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": "user_alias",
      "kind": "scalar",
      "isList": false,
      "isRequired": true,
      "isUnique": false,
      "isId": false,
      "isReadOnly": false,
      "type": "String",
      "hasDefaultValue": false,
      "isGenerated": false,
      "isUpdatedAt": false
    },
    {
      "name": "send_count",
      "kind": "scalar",
      "isList": false,
      "isRequired": true,
      "isUnique": false,
      "isId": false,
      "isReadOnly": false,
      "type": "Int",
      "hasDefaultValue": false,
      "isGenerated": false,
      "isUpdatedAt": false
    },
    {
      "name": "historyable_id",
      "kind": "scalar",
      "isList": false,
      "isRequired": false,
      "isUnique": false,
      "isId": false,
      "isReadOnly": false,
      "type": "Int",
      "hasDefaultValue": false,
      "isGenerated": false,
      "isUpdatedAt": false
    },
    {
      "name": "historyable_type",
      "kind": "scalar",
      "isList": false,
      "isRequired": false,
      "isUnique": false,
      "isId": false,
      "isReadOnly": false,
      "type": "String",
      "hasDefaultValue": false,
      "isGenerated": false,
      "isUpdatedAt": false
    },
    {
      "name": "user_id",
      "kind": "scalar",
      "isList": false,
      "isRequired": true,
      "isUnique": false,
      "isId": false,
      "isReadOnly": false,
      "type": "Int",
      "hasDefaultValue": false,
      "isGenerated": false,
      "isUpdatedAt": false
    },
    {
      "name": "created_at",
      "kind": "scalar",
      "isList": false,
      "isRequired": false,
      "isUnique": false,
      "isId": false,
      "isReadOnly": false,
      "type": "DateTime",
      "hasDefaultValue": false,
      "isGenerated": false,
      "isUpdatedAt": false
    },
    {
      "name": "updated_at",
      "kind": "scalar",
      "isList": false,
      "isRequired": false,
      "isUnique": false,
      "isId": false,
      "isReadOnly": false,
      "type": "DateTime",
      "hasDefaultValue": false,
      "isGenerated": false,
      "isUpdatedAt": true
    }
  ],
  "isGenerated": false,
  "idFields": [],
  "uniqueFields": [],
  "uniqueIndexes": []
}

the @@index and @map information are both missing, this make printing dmmf back to schema impossible.

Suggested solution

Return indexes in Model field just like uniqueFields and uniqueIndexes. add colName or fieldName to show the original db columnName just like dbName.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
dimaipcommented, Jul 1, 2022

We also need @map information on fields quite desperately! See my usecase https://github.com/prisma/prisma/issues/14087

Shouldn’t be a difficult things to fix, right? And would open so many possibilities for better tooling. 🙏

1reaction
dimaipcommented, Jul 5, 2022

For the time being I had to jump through terrible hoops doing prisma.schema pre-processing and extracting all the needed attributes (@map and @db.ObjectId) into the field’s documentation, and accessing it via DMMF from there.

But yeah, would be actually great to see all Prisma schema attributes accessible in DMMF.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upgrade to Prisma 4
Guides on how to upgrade to Prisma 4.
Read more >
How to configure indexes in Prisma - LogRocket Blog
Here, we explore what Prisma is, what database indexes are, their importance to database operations, and how to configure them.
Read more >
Trouble using "Integer" type in Prisma ORM schema for ...
npx prisma generate Environment variables loaded from .env Prisma schema loaded from prisma/schema.prisma Error: Get DMMF: Schema parsing ...
Read more >
prisma-schema-transformer - npm
This project utilizes the getDMMF method from @prisma/sdk to perform some post-processing work on generated Prisma schema, including the ...
Read more >
ScalaSTM — Indexed Map
View , which are STM-integrated concurrent maps. ... Note that we're careful to add all of the existing elements of the map to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found