feat(idb): add IDB content version check system, wire to journals

Adds check_and_clear_idb_tables() helper in core__idb_dexie.ts that clears
Dexie tables when their content version changes. Version numbers live in
IDB_CONTENT_VERSIONS (store_versions.ts); state tracked in localStorage
(ae_idb_ver__{module}__{table}) so each table clears exactly once per bump.

Wired into db_journals.ts (pilot): journal_entry at v3 clears stale
content_md_html/history_md_html data cached before the properties_to_save fix.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Scott Idem
2026-05-14 16:53:55 -04:00
parent 042265008c
commit 95a86b16fa
4 changed files with 144 additions and 0 deletions

View File

@@ -37,6 +37,61 @@ export const AE_PRES_MGMT_LOC_VERSION = 1; // Added 2026-04-02: new standalone P
export const AE_BADGES_LOC_VERSION = 1; // Added 2026-04-02: promoted from events_loc.badges
export const AE_LEADS_LOC_VERSION = 1; // Added 2026-04-03: promoted from events_loc.leads
/**
* IDB_CONTENT_VERSIONS — per-table Dexie content version tracking.
*
* NOT YET ACTIVE. Wiring task tracked in TODO__Agents.md (post June 10).
*
* HOW IT WILL WORK (when wired):
* Each db_*.ts will call a helper (core__idb_dexie.ts) on open that checks a
* lightweight `_meta` table. If the stored version for a table doesn't match
* the constant here, the table is cleared and the version record is updated.
* The SWR pattern then repopulates from the API on next access.
*
* HOW TO USE (once active):
* Bump a table's version here when properties_to_save changes in a way that
* makes existing cached records stale (e.g. adding/removing stored fields,
* changing computed field behavior). Do NOT bump for schema-only changes
* (new indexes, new tables) — those belong in db.version() Dexie migrations.
*
* IDAA NOTES:
* IDAA tables (posts, archives) are already cleared aggressively via
* indexedDB.deleteDatabase() on sign-out and on auth failure in (idaa)/+layout.svelte.
* The content version check is a complementary mechanism for deploy-time resets,
* NOT a replacement for the auth-driven wipe. When wiring, ensure IDAA tables are
* only cleared on IDB open (not mid-session), and that the _meta table itself is
* also cleared when deleteDatabase() is called.
*/
export const IDB_CONTENT_VERSIONS = {
journals: {
journal: 3,
journal_entry: 3 // 2026-05-14: removed content_md_html + history_md_html from properties_to_save
},
events: {
event: 1,
event_session: 1,
event_presenter: 1,
event_badge: 1,
event_device: 1,
event_location: 1,
event_file: 1
},
core: {
site_domain: 1,
person: 1,
user: 1
},
// IDAA modules — see IDAA NOTES above before wiring these
posts: {
post: 1,
post_comment: 1
},
archives: {
archive: 1,
archive_content: 1
}
};
// Version check side-effect: runs on import, before any persisted() call.
// Guard presence of `localStorage` and its functions for safety (SSR, Node flags).
if (