Skip to content

Commit c750bdc

Browse files
committed
legacy-data: Tolerate dupe account, proceeding to next account
1 parent 0e34d96 commit c750bdc

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

lib/model/legacy_app_data.dart

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,32 @@ Future<void> migrateLegacyAppData(AppDatabase db) async {
9191
assert(debugLog(" (account ignored because missing metadata)"));
9292
continue;
9393
}
94-
await db.createAccount(AccountsCompanion.insert(
95-
realmUrl: account.realm,
96-
userId: account.userId!,
97-
email: account.email,
98-
apiKey: account.apiKey,
99-
zulipVersion: account.zulipVersion!,
100-
// no zulipMergeBase; legacy app didn't record it
101-
zulipFeatureLevel: account.zulipFeatureLevel!,
102-
// This app doesn't yet maintain ackedPushToken (#322), so avoid recording
103-
// a value that would then be allowed to get stale. See discussion:
104-
// https://github.com/zulip/zulip-flutter/pull/1588#discussion_r2148817025
105-
// TODO(#322): apply ackedPushToken
106-
// ackedPushToken: drift.Value(account.ackedPushToken),
107-
));
94+
try {
95+
await db.createAccount(AccountsCompanion.insert(
96+
realmUrl: account.realm,
97+
userId: account.userId!,
98+
email: account.email,
99+
apiKey: account.apiKey,
100+
zulipVersion: account.zulipVersion!,
101+
// no zulipMergeBase; legacy app didn't record it
102+
zulipFeatureLevel: account.zulipFeatureLevel!,
103+
// This app doesn't yet maintain ackedPushToken (#322), so avoid recording
104+
// a value that would then be allowed to get stale. See discussion:
105+
// https://github.com/zulip/zulip-flutter/pull/1588#discussion_r2148817025
106+
// TODO(#322): apply ackedPushToken
107+
// ackedPushToken: drift.Value(account.ackedPushToken),
108+
));
109+
} on AccountAlreadyExistsException {
110+
// There's one known way this can actually happen: the legacy app doesn't
111+
// prevent duplicates on (realm, userId), only on (realm, email).
112+
//
113+
// So if e.g. the user changed their email on an account at some point
114+
// in the past, and didn't go and delete the old version from the
115+
// list of accounts, then the old version (the one later in the list,
116+
// since the legacy app orders accounts by recency) will get dropped here.
117+
assert(debugLog(" (account ignored because duplicate)"));
118+
continue;
119+
}
108120
}
109121

110122
assert(debugLog("Done migrating legacy app data."));

0 commit comments

Comments
 (0)