Skip to content

Migration of existing databases #149

Description

@0xbrayo

The new version needs to gracefully handle migration of the existing database without a "unknown" hostname to the actual device hostname.

Activity

  1. TimeToBuildBob commented on Jul 12, 2026

    @TimeToBuildBob
    Contributor

    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 of aw-watcher-android_<hostname>. The existing migrateHostname() JNI call only renames the hostname portion of the bucket ID, not the test prefix.

    Proposed migration approach (Kotlin-level, no new JNI needed):

    During the migration step in BackgroundService.kt, after migrateHostname() completes:

    1. Call rustInterface.getBuckets() to list all buckets
    2. Find any bucket where id.startsWith("aw-watcher-android-test_")
    3. For each such bucket:
      • Get all events via rustInterface.getEvents(oldId, -1)
      • Create the new bucket aw-watcher-android_<hostname> via rustInterface.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 on localhost:5600)
    4. 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.

  2. ErikBjare commented on Aug 27, 2026

    @ErikBjare
    Member

    @TimeToBuildBob Seems to not be fully resolved, see #243

  3. TimeToBuildBob commented on Aug 27, 2026

    @TimeToBuildBob
    Contributor

    Confirmed — this is not fully resolved. I traced the shipped path rather than assuming ActivityWatch/aw-server-rust#628 was sufficient:

    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.

  4. TimeToBuildBob commented on Aug 27, 2026

    @TimeToBuildBob
    Contributor

    Follow-up from the root-cause note above: PRs are open.

    Submodule bump waits on #661 merging so CI can fetch the SHA from upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions