Skip to content

Commit

Permalink
Remove deletion of sources table, just rename
Browse files Browse the repository at this point in the history
  • Loading branch information
nkovacsx committed Oct 12, 2023
1 parent 2ff76e4 commit df75b56
Showing 1 changed file with 17 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,47 +113,29 @@
<!-- Drop the created column from the utxo_transaction_component table -->
<dropColumn columnName="created" tableName="utxo_transaction_component"/>

<!-- Drop the created and is_ref_input columns from the utxo_transaction_sources table -->
<dropColumn tableName="utxo_transaction_sources">
<column name="created"/>
<column name="is_ref_input"/>
</dropColumn>

<!-- Rename the columns in utxo_transaction_sources to avoid confusion -->
<renameColumn columnDataType="VARCHAR(160)"
newColumnName="referenced_state_transaction_id"
oldColumnName="ref_transaction_id"
tableName="utxo_transaction_sources"/>

<renameColumn columnDataType="INT"
newColumnName="referenced_state_index"
oldColumnName="ref_leaf_idx"
tableName="utxo_transaction_sources"/>

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

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

<!-- Add new columns: hash and index for input and reference states -->
<addColumn tableName="utxo_transaction_component">
<column name="referenced_state_transaction_id" type="VARCHAR(160)">
<constraints nullable="true"/>
</column>
<column name="referenced_state_index" type="INT">
<constraints nullable="true"/>
</column>
</addColumn>

<!--
Migrate data from the old utxo_transaction_sources table
NOTE: We can't use <update> here because both tables have the same column naming
(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.
-->
<sql>
UPDATE utxo_transaction_component txc
SET
referenced_state_transaction_id = (
SELECT ref_transaction_id from utxo_transaction_sources ts
WHERE ts.transaction_id=txc.transaction_id
AND ts.group_idx=txc.group_idx
AND ts.leaf_idx=txc.leaf_idx
),
referenced_state_index = (
SELECT ref_leaf_idx from utxo_transaction_sources ts
WHERE ts.transaction_id=txc.transaction_id
AND ts.group_idx=txc.group_idx
AND ts.leaf_idx=txc.leaf_idx
);
</sql>

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

</changeSet>

Expand Down

0 comments on commit df75b56

Please sign in to comment.