-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to version-aware expression for generated merkle root columns (…
- Loading branch information
Showing
1 changed file
with
18 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
sequencer/api/migrations/V36__alter_merkle_root_column_expressions.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-- The generated columns for header merkle roots were originally created by extracting fields | ||
-- `block_merkle_tree_root` and `fee_merkle_tree_root` from the header JSON. Post 0.1, though, the | ||
-- header serialization changed so that these fields are now nested one level deeper: | ||
-- `fields.block_merkle_tree_root` and `fields.fee_merkle_tree_root`. This migration alters the | ||
-- generated column expression to use NULL coalescing to extract the value from either of these | ||
-- paths depending on which version of the header we have. | ||
-- | ||
-- Pre 17.x (we target Postgres >= 16.x), there is not explicit instruction for changing the | ||
-- expression of a generated column, so the best we can do is drop and re-add the column with a | ||
-- different expression. | ||
|
||
ALTER TABLE header | ||
DROP column block_merkle_tree_root, | ||
ADD column block_merkle_tree_root text | ||
GENERATED ALWAYS AS (coalesce(data->'fields'->>'block_merkle_tree_root', data->>'block_merkle_tree_root')) STORED NOT NULL, | ||
DROP column fee_merkle_tree_root, | ||
ADD column fee_merkle_tree_root text | ||
GENERATED ALWAYS AS (coalesce(data->'fields'->>'fee_merkle_tree_root', data->>'fee_merkle_tree_root')) STORED NOT NULL; |