Add a new optional or required property, remove a property
Adding a new property does not require a migration transform document, it can be achieved by simply adding the property to the schema, if a new required property is added, then the default value for that property will be the default value for the property type, e.g. 0 for numeric types, an empty string for string types, false for boolean types.
If the property type does not have a sensible default (e.g. it is a non-null enum property, or non-null complex property), then a migration document may be provided to populate the new property.
When a property is deleted, the original value is captured in a post-migration column on the original table, with all constraints removed.
For example, given this initial schema:
MySchema:
type: object
version: 1
properties:
unchanged:
type: string
deleted:
type: string
The following updated schema:
MySchema:
type: object
version: 2
properties:
unchanged:
type: string
deleted:
type: string
addedOptional:
type: string
addedRequired:
type: string!
addedCustom:
type: string!
The following migration document:
- target: MySchema
fromVersion: 1
toVersion: 2
properties:
addedCustom: "'default value'"
And the following initial row:
| unchanged | deleted |
|---|---|
| "staying" | "going" |
Then after a successful migration with migration id m1, the row will be as follows:
| unchanged | addedOptional | addedRequired | addedCustom | _going_m1 |
|---|---|---|---|---|
| "staying" | (null) | "" | "defaultValue" | "going" |
Note: The _going_m1 column will be set to nullable if the target storage supports constraints, and regardless of
the original nullability of this property.