Skip to content
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

New migrations are generated if one adds a constraint expression written in lowercase without using parentheses #3827

Closed
JasonRammoray opened this issue Dec 5, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@JasonRammoray
Copy link

JasonRammoray commented Dec 5, 2022

Describe the bug
If one adds a constraint using Check decorator and provides a simple expression, like logical one, and written in lowercase without using parentheses, then migration:create will continue generating the same migration even after migration:up has been applied.
The subsequent migration, however, is not generated if one uses uppercase for sql keywords (for example, IS NOT NULL, OR).

Stack trace
None

To Reproduce
Steps to reproduce the behavior:

  1. Create an entity with two nullable fields
  2. Create a constraint for that entity as:
@Check<EntityTypeHere>({
  expression: columns => `${column.<firstColumnNameHere>} is not null or ${column.<secondColumnNameHere>} is not null`,
  name: '<some_name_here>'
})
  1. Generate a migration
  2. Migrate to that migration
  3. Try generating a migration one more time

Expected behavior
No second migration should be created given there were no changes to the entity model.

Observations
It appears if one wraps every expression in parentheses and writes sql keywords in caps, then the issue isn't reproducible.
E.g:

@Check<EntityTypeHere>({
  expression: columns => `(${column.<firstColumnNameHere>} IS NOT NULL) OR (${column.<secondColumnNameHere>} IS NOT NULL)`,
  name: '<some_name_here>',
})

Versions

Dependency Version
node 16.16.0
typescript 4.8.4
mikro-orm 5.5.3
your-driver postgresql (5.5.3)
@B4nan
Copy link
Member

B4nan commented Dec 5, 2022

Interesting, I guess postgres normalizes the query and store that instead of the expression provided by you. Will try to find some way to get around this, worst case we could compare the expression as lower case and ignore parens, could be good enough heuristic about what changed.

@B4nan B4nan added the bug Something isn't working label Dec 5, 2022
@B4nan B4nan closed this as completed in 0fd8530 Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants