Repository navigation
Migration of existing databases #149
Description
Activity
Related to the aw-watcher-android-test bucket rename discussed in #176.
Problem: Users who installed aw-android before the watcher was renamed have a
aw-watcher-android-test_<hostname>bucket instead ofaw-watcher-android_<hostname>. The existingmigrateHostname()JNI call only renames the hostname portion of the bucket ID, not thetestprefix.Proposed migration approach (Kotlin-level, no new JNI needed):
During the migration step in
BackgroundService.kt, aftermigrateHostname()completes:- Call
rustInterface.getBuckets()to list all buckets - Find any bucket where
id.startsWith("aw-watcher-android-test_") - For each such bucket:
- Get all events via
rustInterface.getEvents(oldId, -1) - Create the new bucket
aw-watcher-android_<hostname>viarustInterface.createBucket(...) - Replay events via
rustInterface.heartbeat(newId, event, pulsetime) - Delete the old bucket (via HTTP
DELETE /api/0/buckets/<id>— no JNI needed, aw-server runs locally onlocalhost:5600)
- Get all events via
- Guard with a preference key (e.g.
AWPreferences.hasMigratedTestBucket) so it runs once
This keeps all migration logic in aw-android with no aw-server-rust changes needed.
- Call
@TimeToBuildBob Seems to not be fully resolved, see #243
Confirmed — this is not fully resolved. I traced the shipped path rather than assuming ActivityWatch/aw-server-rust#628 was sufficient:
- The server migration only runs when Android calls
migrateWatcherAndroidBucketNames(). aw-androidmaster never declares or calls that JNI method; startup only callsmigrateHostname().- Even after wiring it, #628 uses
UPDATE OR IGNORE. If bothaw-watcher-android-testandaw-watcher-androidexist — exactly the post-upgrade state in Releases marked "pre-release" on github seem to be getting automatically pushed to the Play Store & auto-installed on devices #243 — the unique-name collision skips the old bucket, so its events remain stranded.
So this needs an idempotent merge, not just a rename: move old-bucket events to the existing canonical bucket (preserving IDs/timestamps/data), delete the old bucket only after the move commits, and rename directly only when no canonical bucket exists. It should run during startup before the migration is marked complete.
I am not opening a duplicate PR from this dispatch: the sibling session handling #150 already owns the implementation lane. I sent it this exact root cause/scope; #149 and #150 should stay open until the merged-bucket collision case has a regression test and the Android startup call is wired.
- The server migration only runs when Android calls
Follow-up from the root-cause note above: PRs are open.
- fix(datastore): merge disjoint aw-watcher-android-test events on name collision aw-server-rust#661 — merge disjoint events when both buckets exist (partial merge so one overlapping cutover event does not strand the rest of the history).
- fix(android): migrate aw-watcher-android-test buckets on startup #244 — wire the JNI call on startup and do not mark the migration complete while leftover
-testbuckets remain.
Submodule bump waits on #661 merging so CI can fetch the SHA from upstream.
The new version needs to gracefully handle migration of the existing database without a "unknown" hostname to the actual device hostname.