Skip to content

Replace script file hashing with schema hashing in migrations#2304

Open
gabrielbosio wants to merge 3 commits into
nextfrom
schema-hash-guard
Open

Replace script file hashing with schema hashing in migrations#2304
gabrielbosio wants to merge 3 commits into
nextfrom
schema-hash-guard

Conversation

@gabrielbosio

@gabrielbosio gabrielbosio commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Closes #2307.

@gabrielbosio gabrielbosio changed the title [WIP] Add schema hash guard Replace script file hashing with schema hashing in migrations Jul 6, 2026
@gabrielbosio
gabrielbosio marked this pull request as ready for review July 6, 2026 21:56
@igamigo
igamigo requested a review from JereSalo July 7, 2026 12:34

@igamigo igamigo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! LGTM, thanks!

@JereSalo JereSalo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • We can remove the migrations table from sqlite-store/src/store.sql as it's no longer used after this PR. And with this we could remove the added test of stale_migrations_row_does_not_affect_acceptance, as it's not necessary. I think removing the table would be breaking but if this goes to next then it shouldn't be something to worry about I guess.

fn schema_hash(conn: &Connection) -> Result<Hash> {
let mut stmt = conn.prepare(
"SELECT type, name, tbl_name, sql FROM sqlite_schema \
WHERE sql IS NOT NULL AND name NOT LIKE 'sqlite_%' \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: in LIKE the _ symbol behaves as a single character wildcard, and here we want to say that the name shouldn't start with "sqlite_". If we wanted to be more precise we could use name NOT GLOB 'sqlite_*' instead (note that GLOB uses * as multi-character wildcard).

This just covers against unlikely edge cases in which you have an object named, for example, "sqlitesomething" and we don't want to ignore it for the fingerprint in that case.

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.

Improve migration hashing

3 participants