Skip to content

Conversation

@ValuedMammal
Copy link
Collaborator

@ValuedMammal ValuedMammal commented Jan 11, 2026

`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.

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.
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