Skip to content

Commit

Permalink
Add NOT NULL constraint to the Transactions table for peace of mind
Browse files Browse the repository at this point in the history
- However, it is not expected that there should be any transactions with a null `block_height` that are missed by the migration process.
- In any case, this is the correct constraint to have going forward.
  • Loading branch information
AustEcon authored and rt121212121 committed Mar 27, 2023
1 parent 054c209 commit 00198bf
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,13 @@ def merkle_root_hash_from_proof(hash: bytes, branch: list[bytes], index:int) ->
# server hoops.
conn.execute("ALTER TABLE Transactions DROP COLUMN proof_data")

# Add the NOT NULL constraint to block_height column. SQLite doesn't allow ADD CONSTRAINT
# see: https://www.sqlite.org/omitted.html, so it has to be done this way as a workaround.
conn.execute("ALTER TABLE Transactions ADD COLUMN block_height2 NOT NULL DEFAULT 0")
conn.execute("UPDATE Transactions SET block_height2=block_height WHERE tx_hash=tx_hash;")
conn.execute("ALTER TABLE Transactions DROP COLUMN block_height")
conn.execute("ALTER TABLE Transactions RENAME COLUMN block_height2 TO block_height")

# Remove vestigial traces of `HasProofData` transaction flag (we cleared others in migration
# 22).
clear_bits_args = (~TxFlags_22.HasProofData, TxFlags_22.HasProofData)
Expand Down

0 comments on commit 00198bf

Please sign in to comment.