POC nullable field schema migration #Proof of Concept #70
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To solve the issue of schema incompatibility during versioning changes, the following is proposed:
All fields within the BigQuery table are declared to be
NULLABLE
with the exception of essential fields such asProjectID
andID
.The bq-notifier does a schema check upon the table URI referenced in the notifier setup config upon initial deployment:
Any new inferred fields (from the bq-notifier schema) that are not found in the existing table's schema, are appended, preserving any fields already existent in the existent table's schema.
Any new inferred fields that have the same names but differing types with fields found in the existing table's schema will cause the setup to fail. This is a fail safe feature preventing bq-notifier from overwriting tables that may not have been initialized by the bq-notifier.
This allows the following kinds of schema changes to occur between bq-notifier versions:
NULLABLE
fields are added to the Schema.The data in the table will migrate successfully over to the new Schema. Since the new field is
NULLABLE
, past records that do not possess the field will still satisfy the new schema. (Adding a newREQUIRED
field) would cause the table schema constraints to fail.NULLABLE
fields are removed from the Schema.The data in the table will migrate successfully over to the new Schema. Since schema migrations have an append only effect on the existing table's schema, the "removed" field will remain within the schema. New data will successfully omit the removed field while existing data containing the field will remain intact.
Adding or removing
REQUIRED
fields will break all schema constraints during migrations.