[Experimental] Add include_old and include_metadata options #60
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.
The goal is to allow more fine-grained tracking of updates to rows, especially when the rows contain nested json data.
One example is having an array column, and the developer adds or removes individual items to the array. Currently we record the entire new array, but that does not provide the individual updates to the developer in the uploadData function.
Right now the best workaround is to create a new
insert_only
table, that you use to associate custom metadata per transaction.This PR experiments with adding two new options that can be configured per table, which should simplify the process of custom metadata for a lot of use cases.
Specific use case examples:
include_old
Instead of just including updated fields in
data
inps_crud
, this additionally includes all previous values inold
. This option can be extended to support an array of columns to include, instead of all columns.The
old
data could be used to:id
column).TODO:
include_old
for delete operations.include_old
.include_metadata
This adds a
_metadata
column to the view. This is alwaysnull
when reading, but can be set when inserting or updating. Unfortunately, it is not possible to set this when deleting rows. We could theoretically work around this by having a virtualUPDATE myview SET _delete = true, _metadata = ...
type update, but leaving that for later.You can store any custom metadata here - it could include the old value of columns or custom values provided in code. It could be a number, plain text, or dynamically constructed json.
The metadata can be used for any custom metadata required for uploading operations. We do not impose any restriction or meaning on the structure here, although we could support some structured operations in a higher-level update.
This can also be combined with
include_old
.TODO:
include_metadata
for insert operations.UPDATE ... SET _deleted = true, _metadata = ...