-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
fix: correctly strip type conversion in postgres for default values #7681
fix: correctly strip type conversion in postgres for default values #7681
Conversation
4df2618
to
fbac17b
Compare
Use better regex to remove only type conversion, not the whole string to the end Closes: 7110
445f934
to
ca07fd1
Compare
dbdaad7
to
b95e078
Compare
This makes sure updated regex does not break migrations chnages introduced in typeorm#7647
This should cover all existing types in postgres. Regex I used for reference: https://regex101.com/r/qHG4lQ/1 |
#5132 has a reproduction example. Can you please add a test for it? |
a92eaf2
to
c69503f
Compare
c69503f
to
5499674
Compare
Added a test. I've change bigint to int, as it failed in oracle with usupported type errror. To tell the truth, it seems that this issue was already resolved before my changes. |
As for #1729, #3076, not sure if we'll still cover all possible cases after that:
default: () => "(now() at time zone 'utc')" - doesn't work, as postgres converts it to
Complex cases such as |
I think this is only the way to handle such cases. We have a plan to add a sublayer between ORM and database where we can store mappings between entity and table metadata. It will allow us to handle any comparisons for defaults, checks, expressions, views, etc. |
thank you for contribution! |
Use better regex to remove only type conversion, not the whole string to the end
Closes: 7110
Description of change
When loading schema with postgres driver typeorm currently strips explicit type conversions from column default value. But current RegExp in some cases does this incorrectly, that leads to part of string after conversion being stripped to the end.
For example value
to_char(nextval('orders_display_id_seq'::regclass), 'FMU999'::text)
is stripped to justto_char(nextval('orders_display_id_seq'
. This behaviour causes duplications when generating migrations.Fixes #7110
Fixes #5132
Pull-Request Checklist
master
branchnpm run lint
passes with this changenpm run test
passes with this changeFixes #0000