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.

Support table and column comments modeled in Prisma

See original GitHub issue

Problem

The relational database engines I am familiar with (Oracle, postgres, SQL Server, etc.) all have an internal “data dictionary” that contains metadata about all the schema and data objects, like tables, views, materialized views, indexes, columns, etc. They all allow comments on these objects to be declared using DDL statements such as:

COMMENT ON COLUMN mytable.mycolumn IS 'This is what this column holds. Here is the history. Here is a caveat and a weird case. etc.'

Prisma does not support documenting the schema in the database’s internal data dictionary.

Data definitions are critical. I can’t begin to express how important this is for future engineers on a given project, for data engineers, report writers, data scientists, InfoSec, legal, data catalog/glossary tools and efforts, governance, etc.

Suggested solution

Add an attribute to the Prisma modeling spec, something like @comment("Here is my awesome comment about this data item.") that can be placed to the right of each column, or parameterized version like @comment("my_table_name", "Here is the full business definition of this table and how it is used.") for a table or enum. When Prisma finally supports views and materialized views, those should allow comments as well.

Take each @comment string and generate and run a comment DDL statement to insert it into the underlying DB data dictionary, right after creating the table or data object. If the underlying DB engine doesn’t support comments, then Prisma would forego generating and running the comment statements. In this case, the definitions in the Prisma model could still be useful for the team and data catalog tools.

Alternatives

As of now, my teams have to write manual DDL scripts, and run them after Prisma has done its model migration into the DB schema. It is not ideal and clunky.

Additional context

If I weren’t in a hurry, I’d investigate all the databases for which you have built native connectors, to see if which ones support data dictionary comments.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:32
  • Comments:19 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
StringKecommented, Mar 13, 2022

I recommend using the @comment method.

@comment is a comment in the database /// is to generate typescript type comments

5reactions
janpiocommented, May 12, 2022

(No need to continue this discussion, we are aware of the different potential or real approaches to define comments in Prisma Schema and will consider both when we look into resolving this issue. Right now we have no further opinion than that triple slash comments are already implement to solve another use case.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data model (Reference) - Prisma
With this model definition, Prisma automatically maps the Comment model to the comments table in the underlying database. Note: You can also @map...
Read more >
Names in the underlying database - Prisma
Map model and field names to different collection/table and field/column names ... maps the Comment model to the comments table in the underlying...
Read more >
Prisma schema API (Reference)
API reference documentation for the Prisma Schema Language (PSL).
Read more >
Prisma schema (Reference)
Introspected 4 models and wrote them into prisma/schema.prisma in 239ms ... There are two types of comments that are supported in the schema...
Read more >
Relation queries (Concepts) - Prisma
Nested writes · Provide transactional guarantees for creating, updating or deleting data across multiple tables in a single Prisma Client query. · Support...
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