-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues with constraints #467
Comments
PRs welcome! |
ab-pm
added a commit
to ab-pm/node-pg-migrate
that referenced
this issue
Aug 14, 2019
* added escaping to `references` field when only a table name is given * now also creates default constraint names when you don't pass anything in `addConstraint` fixes salsita#467
ab-pm
added a commit
to ab-pm/node-pg-migrate
that referenced
this issue
Aug 14, 2019
- add some tests (not exhaustive though) - update docs - a `referencesConstraintComment` on a column definition auto-generates a constraint name if none is given Closes salsita#467.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I noticed a few issues with setting constraints:
references
field for foreign keys is not escaped, leading to invalid syntax when using identifiers that are also keywords. I understand that this is because one might not only have the table name in there but also the column names (e.g.references: '"user"(id)'
), but since using only the table name works in Postgres (defaulting to the primary key column) it would be really nice to escape this when the property holds a string that does not contain parenthesis. Maybe even split up inreferencesTable: Name
andreferencesColumns: Name | Array<Name>
? Please adjust the documentation thatreferences
currently expects a String, not a single (table) name.referencesConstraintName
totally makes sense in column definitions. However, it is also documented as an option foraddConstraint
, and using it there (together with the normalconstraint_name
- even when that is empty) totally breaks the generated SQL command.foreignKeys
option foraddConstraint
is documented as an "[object or array of objects]". When I tried passing an array, it did create twoCONSTRAINT
statements with the same name which was of course rejected by Postgres.pgm.sql
:-(I'd love if
addConstraint
could support acomment
option, and ifcreateTable
/addColumns
could support areferencesConstraintComment
option.I'll try to make a PR if you agree!
The text was updated successfully, but these errors were encountered: