Update existing rows with default value #2471
Replies: 5 comments
-
To get the value from initializer, we would need to create entity instance via ctor, and that might not be always possible due to some dependencies in the constructor. It might even have sideeffects to call the entity ctor (although it would be very weird ctor implementation, but it is possible). With ts-morph this would be obviously possible just via reflection. |
Beta Was this translation helpful? Give feedback.
-
I suggest to use the |
Beta Was this translation helpful? Give feedback.
-
To me that does not sounds much better than explicit Also the value might not be even usable (e.g. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I see, but that means both of this requires to create new entity instance to extract the value, so not a general solution, rather a hack...
I don't really understand how you expect to get the actual default values - it is still needed to create the entity instance, as the values are effectively just assignemnts done inside the entity ctor. There is no other way to get those (only via ts-morph reflection, which has its own group of problems). Also as a rule of thumb it is not suggested to mix DDL with DML queries ( On the other hand I can confirm I do this myself sometimes, especially when I want to seed some data via |
Beta Was this translation helpful? Give feedback.
-
Is your feature request related to a problem? Please describe.
If I create a new column like this
And I have existing rows for this table, the migration will be:
And it will fail
Describe the solution you'd like
A migration that would work is
Also you might not want to update existing row with the default value, so an optional
existingDefault
could be valuableIn my example, I could have
@Property({existingDefault: 'active'})
generatingDescribe alternatives you've considered
I have been doing this manually, but thought that could be a nice feature
(Note that I am working with pg)
Beta Was this translation helpful? Give feedback.
All reactions