Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORE-17431 utxo_transaction_metadata table and related migrations #1286

Merged
merged 5 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,59 @@

<!-- Drop the utxo_cpk table -->
<dropTable tableName="utxo_cpk"/>

<createTable tableName="utxo_transaction_metadata">
<column name="hash" type="VARCHAR(160)">
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="canonical_data" type="VARBINARY(1048576)">
<constraints nullable="false"/>
</column>
<column name="group_parameters_hash" type="VARCHAR(160)">
<constraints nullable="false"/>
</column>
<column name="cpi_file_checksum" type="VARCHAR(160)">
<constraints nullable="false"/>
</column>
</createTable>

<!-- Add utxo_transaction.metadata_hash nullable to let migrate data later -->
<addColumn tableName="utxo_transaction">
<column name="metadata_hash" type="VARCHAR(160)">
<constraints nullable="true" foreignKeyName="fk_utxo_transaction_metadata" references="utxo_transaction_metadata(hash)"/>
</column>
</addColumn>

<!-- Populate utxo_transaction_metadata. Postgresql only since, no other dbs were supported before 5.1. So only Postgres can have data which needs to be migrated. -->
<!-- ^^ is this correct?? -->
<sql dbms="postgresql">
INSERT INTO utxo_transaction_metadata
SELECT DISTINCT
hash,
data as canonical_data,
convert_from(data, 'UTF-8')::jsonb->'membershipGroupParametersHash' AS group_parameters_hash,
convert_from(data, 'UTF-8')::jsonb->'cpiMetadata'->'fileChecksum' AS cpi_file_checksum
FROM
utxo_transaction_component
WHERE
group_idx=0 AND
leaf_idx=0;
</sql>

<!-- Migrate utxo_transaction.metadata_hash -->
<update tableName="utxo_transaction">
<column name="metadata_hash"
valueComputed="(select hash from utxo_transaction_component c where c.transaction_id=id and group_idx=0 and leaf_idx=0)"/>
</update>

<!-- Change utxo_transaction.metadata_hash to not nullable -->
<addNotNullConstraint tableName="utxo_transaction" columnName="metadata_hash" columnDataType="VARCHAR(160)"/>

<!-- Old metadata records are not needed anymore. -->
<delete tableName="utxo_transaction_component">
<where>group_idx=0 AND leaf_idx=0</where>
</delete>

</changeSet>

</databaseChangeLog>
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cordaProductVersion = 5.1.0
# NOTE: update this each time this module contains a breaking change
## NOTE: currently this is a top level revision, so all API versions will line up, but this could be moved to
## a per module property in which case module versions can change independently.
cordaApiRevision = 32
cordaApiRevision = 33

# Main
kotlinVersion = 1.8.21
Expand Down