Skip to content

Commit

Permalink
CORE-17431 utxo_transaction_metadata table and related migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
vlajos committed Oct 10, 2023
1 parent edc6b36 commit 2ce8960
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,54 @@

<!-- 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="data" type="${json.column.type}">
<constraints nullable="false"/>
</column>
<column name="cpi_file_checksum_hash" type="VARCHAR(160)">
<constraints nullable="false"/>
</column>
<column name="group_parameters_hash" 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
hash,
convert_from(data, 'UTF-8')::jsonb AS data,
convert_from(data, 'UTF-8')::jsonb->'cpiMetadata'->'fileChecksum' AS cpi_file_checksum_hash,
convert_from(data, 'UTF-8')::jsonb->'membershipGroupParametersHash' AS group_parameters_hash
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)"/>

</changeSet>

</databaseChangeLog>

0 comments on commit 2ce8960

Please sign in to comment.