Support table and column comments modeled in Prisma
See original GitHub issueProblem
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:
- Created 2 years ago
- Reactions:32
- Comments:19 (4 by maintainers)
Top GitHub Comments
I recommend using the
@comment
method.@comment
is a comment in the database///
is to generate typescript type comments(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.)