Skip to content

Refresh all connection-local state on PRAGMA data_version changes - #28

Merged
gorbak25 merged 2 commits into
mainfrom
gorbak/reload-config-when-db-version-changes
Oct 12, 2026
Merged

gorbak25 merged 2 commits into
mainfrom
gorbak/reload-config-when-db-version-changes

Conversation

@gorbak25

Copy link
Copy Markdown

When PRAGMA data_version changes, we previously only reloaded db_version, but the config may have changed too. This PR refreshes all connection-local state on a data_version change and is structured so more reload_* methods can be added later (e.g. caches we'd like to keep across commit boundaries).

This is extracted from #26, where knowing the current config is needed to pick the right queries/code paths. Splitting it out makes the motivation clearer.

data_version is also checked in x_crsql_set_ts to work around a vtab limitation: when the schema changes on another connection, we need to regenerate our cached statements in addition to reloading config and db_version. That regeneration fails during a write to crsql_changes because of nested trigger limitations. Since #26 makes set_ts a prerequisite for most crsql operations, it's the best place to optimistically reload connection state.

fill_db_version_if_needed consumed the data_version check for its own
cache, leaving other cached state (e.g. merge-equal-values config)
stale when a different code path observed the change first.

Introduce refresh_connection_state_if_needed which performs the single
data_version check and fans out to per-cache reload_* functions
(reload_db_version, reload_connection_config). Invoke it from the
db_version fill path, crsql_config_get, crsql_set_ts, and crsql_changes
merge inserts so every cached value is reloaded consistently from the
same snapshot.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@gorbak25
gorbak25 requested a review from somtochiama October 11, 2026 15:59
@gorbak25
gorbak25 added this pull request to stack #30 October 11, 2026 22:14
The fill_db_version_if_needed wrapper no longer earns its name now
that the shared refresher handles first-use initialization itself.
@gorbak25
gorbak25 merged commit 64077d9 into main Oct 12, 2026
9 checks passed
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.

2 participants