Skip to content

Conversation

@ValuedMammal
Copy link
Collaborator

@ValuedMammal ValuedMammal commented Jan 11, 2026

0002_schema.up.sql changes the block table's PRIMARY KEY from (height, hash) to height only, in order to prevent multiple rows from contending for the same height. Note that this operation is potentially destructive. If two or more rows existed at the same height, they will be removed from the database since we can't reliably determine which block hash is the correct one.

Additionally, the anchor block_hash column previously had the type INTEGER, and this was a mistake in the schema, since block hashes are typically represented as a hex string. Thus we change the type of the block_hash column to TEXT.

fix #8
fix #12

`0002_schema.up.sql` changes the PRIMARY KEY of `block`
table from `(height, hash)` to `height` only, in order
to prevent multiple rows from contending for the same height.

**NOTE** this operation is potentially destructive. If two
or more rows existed at the same height, they'll now be
missing from the database since we can't reliably determine
which block hash is the correct one.

Additionally, the anchor `block_hash` column previously
had the type INTEGER, and this was a mistake in the schema,
since block hashes are typically represented as a hex string.
Thus we change the type of the `block_hash` column to TEXT.
Now that the schema has a unique constraint on block
height, we can remove the extra select query.
@ValuedMammal ValuedMammal marked this pull request as ready for review January 31, 2026 15:22
@ValuedMammal ValuedMammal merged commit 4d57478 into bitcoindevkit:master Jan 31, 2026
3 checks passed
@ValuedMammal ValuedMammal deleted the schema_0002 branch January 31, 2026 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

schema: anchor block_hash column should have type TEXT schema: block table should not allow duplicate heights

1 participant