Update keys inside JSONB columns with migrations apply
See original GitHub issueBy default, changes to class
properties do not affect the data inside [ColumnType(TypeName = "jsonb"])
entities resulting in a loose structure in the database and requiring manually invasive PgSQL queries to correct.
For example,
public class FooBar {
[ColumnType(TypeName = "jsonb")]
public Foo Foo { get; set; }
}
public class Foo {
public string Bar { get; set; }
}
Updated with new properties…
public class Foo {
public string Bar { get; set; }
public int Baz { get; set; }
public DateTimeOffset Qux { get; set; }
}
Results in a migration with changes that do not modify the keys inside jsonb
columns (i.e. keys baz
and qux
are not automatically added to existing json data).
Expected Behaviour
- Use postgres
update table
constructs to modify schema inside jsonb - Function similarly to traditional column insertion on
migration apply
when new properties are created
Is there an overriding or extension method call for performing this on dotnet ef database update
?
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
update jsonb column from values in another table
I create a migration to to convert a jsonb column into a one-to-many table. -- upgrade insert into device_component ( warranty_request_uuid, ...
Read more >Migrate existing data when altering the column type from ...
I want to migrate the existing string 'str1:str2' into the proper JSON string with keys as '{"key1":"str1","key2":"str2"}' before/while ...
Read more >Modifying JSON data using JSON_MODIFY() in SQL Server
Suppose you define a variable in SQL Server and it holds JSON key-value pairs. We use JSON_MODIFY() function to update the JSON string....
Read more >Work with JSONB data | Cloud Spanner
This page describes how to work with the JSONB data type when using Cloud Spanner. JSONB is a PostgreSQL data type used for...
Read more >How do you properly index specific keys in a Postgres ...
How do you properly index specific keys in a Postgres JSONB column that's an array of hashes? Hi,. I have the following in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Great discussion as the performance implications and complexity of covering all possible use cases of transformations makes sense.
Think it’ll be easier for users to implement specific
sql
operations in thecsharp
project to validate consistency, apply transforms onjsonb data
to align with type changes, relative to the code-first properties.Thanks @roji and @NinoFloris for the explanation, closing this one out!
I know it’s an academic discussion, but still 😃 What kind of DML would change existing JSON array values to object? I mean, even PostgreSQL doesn’t allow to change arbitrary column types - you have to specify a transformation yourself. In the same way, I can’t see what automatic transformations we’d be able to do… though of course users can always add a quick JSON update in their migrations via raw SQL, which applies the exact logic they want.