Allow for check constraints in shorthands #1183
Labels
c: feature
Request for new feature
s: waiting for user interest
Waiting for more users interested in this feature
Milestone
Description
Consider this check constraint example from the postgres documentation.
You can make this table in node-pg-migrate like so:
But what if you wanted to have
price
fields with the same constraint on many tables? That's a perfect case for creating a shorthand for the price column.There's a huge problem here. What if someone wants to make a column of type price, but the column name isn't literally
price
?This isn't going to work because you would need
check: "retail_price > 0"
, but the shorthand just hasprice > 0
Suggested solution
When writing a check constraint in a shorthand, there should be some way to template the column name. I don't know what the syntax would be, this is just the first thing that came to mind without putting much thought into it.
Alternative
Maybe the shorthands could be written using the shorthand, but then node-pg-migrate will intelligently replace the shorthand name in the constraint with the actual column name. Then this original example would actually work.
It seems like this would be complicated and prone to danger, however, because you might have a situation like this
In which you do not want to replace price.
Additional context
No response
The text was updated successfully, but these errors were encountered: