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-16183 Ledger data model simplifications (part 1) #1270

Merged
Merged
Show file tree
Hide file tree
Changes from 10 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 @@ -3,18 +3,106 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.3.xsd">

<property name="json.column.type" value="JSONB" dbms="postgresql"/>

<!-- Please note that HSQLDB schema is supported for integration test purposes only. -->
<property name="json.column.type" value="CLOB" dbms="hsqldb"/>
nkovacsx marked this conversation as resolved.
Show resolved Hide resolved

<changeSet author="R3.Corda" id="ledger-utxo-creation-v5.1">
nkovacsx marked this conversation as resolved.
Show resolved Hide resolved
<createIndex
indexName="utxo_visible_transaction_state_idx_consumed"
tableName="utxo_visible_transaction_state">
<column name="consumed"/>
</createIndex>

<createIndex
indexName="utxo_transaction_output_idx_type"
tableName="utxo_transaction_output">
<column name="type"/>
</createIndex>

<!-- Add new status column to utxo_transaction -->
<addColumn tableName="utxo_transaction">
<column name="status" type="VARCHAR(255)">
nkovacsx marked this conversation as resolved.
Show resolved Hide resolved
<constraints nullable="true"/>
</column>
<column name="updated" type="TIMESTAMP">
<constraints nullable="true"/>
</column>
</addColumn>

<!-- Migrate data from the old status table -->
<update tableName="utxo_transaction">
<column name="status"
valueComputed="(select status from utxo_transaction_status uts where uts.transaction_id=id)"/>
<column name="updated"
valueComputed="(select updated from utxo_transaction_status uts where uts.transaction_id=id)"/>
</update>

<!-- Drop the old status table -->
<dropTable tableName="utxo_transaction_status"/>

<!-- After status data migration we can make the status/updated column non-nullable -->
<addNotNullConstraint tableName="utxo_transaction" columnName="status" columnDataType="VARCHAR(255)"/>
nkovacsx marked this conversation as resolved.
Show resolved Hide resolved
<addNotNullConstraint tableName="utxo_transaction" columnName="updated" columnDataType="TIMESTAMP"/>

<!-- Add new custom_representation and consumed columns to utxo_transaction_output -->
<addColumn tableName="utxo_transaction_output">
<column name="custom_representation" type="${json.column.type}">
<constraints nullable="true"/>
</column>
<column name="consumed" type="TIMESTAMP">
<constraints nullable="true"/>
</column>
</addColumn>

<!--
Migrate data from the old visible states table
NOTE: We can't use <update> here because both tables have the same column naming
nkovacsx marked this conversation as resolved.
Show resolved Hide resolved
(transaction_id, group_idx etc.) and the SQL statement generated will not work in
Postgres, and we have no way to alias the base table.
-->
nkovacsx marked this conversation as resolved.
Show resolved Hide resolved
<sql>
UPDATE utxo_transaction_output txo
SET
custom_representation = (
SELECT custom_representation from utxo_visible_transaction_state vts
WHERE vts.transaction_id=txo.transaction_id
AND vts.group_idx=txo.group_idx
AND vts.leaf_idx=txo.leaf_idx
nkovacsx marked this conversation as resolved.
Show resolved Hide resolved
),
consumed = (
SELECT consumed from utxo_visible_transaction_state vts
WHERE vts.transaction_id=txo.transaction_id
AND vts.group_idx=txo.group_idx
AND vts.leaf_idx=txo.leaf_idx
);
</sql>

<!-- After visible states data migration we can make the custom_representation column non-nullable -->
<addNotNullConstraint tableName="utxo_transaction_output"
columnName="custom_representation"
columnDataType="${json.column.type}"/>

<!-- Drop the utxo_visible_transaction_state table after data migration -->
<dropTable tableName="utxo_visible_transaction_state"/>

<!-- Rename utxo_transaction_output to utxo_visible_transaction_output -->
<renameTable newTableName="utxo_visible_transaction_output" oldTableName="utxo_transaction_output"/>

<!-- Re-create the index on the consumed column in the new table -->
<createIndex
indexName="utxo_visible_transaction_output_idx_consumed"
tableName="utxo_visible_transaction_output">
<column name="consumed"/>
</createIndex>

<!-- Drop the created column from the utxo_transaction_component table -->
<dropColumn columnName="created" tableName="utxo_transaction_component"/>

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

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

<!-- Drop the utxo_cpk table -->
<dropTable tableName="utxo_cpk"/>
</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 = 28
cordaApiRevision = 29

# Main
kotlinVersion = 1.8.21
Expand Down