4 ms·
So how do you apply this in the real world when dealing with schema versions and database migrations?
by korijn 4y ago
So how do you apply this in the real world when dealing with schema versions and database migrations?
- willmeyers 4y agoAdd a new constraint that supports the new schema version, migrate json columns to conform to new schema as need be, and then drop old constraint. This assumes your schema is backwards compatible. If it isn't I would probably not use a DB constraint and just handle everything on the application layer.
- korijn 4y agoThanks, that makes sense.
- alexvoda 4y agoIf the schema is not backwards compatible it either means you will have to do a data migration or it means you want to keep track of the schema version along with the data. In both cases it is much easier if the json columns are split off into a separate table.
- dtech 4y agoYou could add a schema_version column and use one constraint per schema version. It will only be per major version, if the schema is backwards compatible there's no problem.