Generated columns (MySQL) #24063
Labels
kind/feature
A request for a new feature.
team/schema
Issue for team Schema.
topic: generated columns
topic: mysql
Problem
It is currently not clear how to setup prisma schema to allow for generated mysql columns. Assume we have the following column migration
The question then is how do you setup a schema so that
total
would not be required when creating this record. If your schema isthen
lineItem.create(...)
will require you to set total to something and mysql query will crash because you are not allowed to set/update generated columns. If your schema isthen in your query responses total will potentially be undefined, which is better but we are using typescript and it is a pain to check if a column is set when we know there is no way it isn't set. Finally, I did found a way that does work
This, however, feels like a hack that might stop working at some point in the future. If the above is the intended way to achieve my usecase then I guess this is not a feature request, but it would be good if someone confirmed this approach will continue to work in the future.
Suggested solution
Assuming the above is not intended to work then I would be happy with anything basic like an option to mark column as db generated, e.g.
The above would be good enough for my usecase.
Alternatives
there is also an option to provide complete support for generated columns, e.g.
@db.generated("GENERATED ALWAYS AS (`price`*`count`) STORED")
this would just be an extension of the above solution.
Additional context
I have looked into the
Computed Fields
feature, unfortunatelly I cannot use that approach due to existing databases depending on this column :(.The text was updated successfully, but these errors were encountered: