Copy important settings from previous MASTER settings #202

Merged
trentlarson merged 5 commits from copy-settings into master 2 weeks ago
  1. 2
      src/components/TopMessage.vue
  2. 12
      src/db-sql/migration.ts
  3. 2
      src/services/migrationService.ts
  4. 9
      src/utils/PlatformServiceMixin.ts
  5. 4
      src/views/HomeView.vue
  6. 3
      src/views/IdentitySwitcherView.vue

2
src/components/TopMessage.vue

@ -28,7 +28,7 @@ import { logger } from "../utils/logger";
export default class TopMessage extends Vue { export default class TopMessage extends Vue {
// Enhanced PlatformServiceMixin v4.0 provides: // Enhanced PlatformServiceMixin v4.0 provides:
// - Cached database operations: this.$contacts(), this.$settings(), this.$accountSettings() // - Cached database operations: this.$contacts(), this.$settings(), this.$accountSettings()
// - Settings shortcuts: this.$saveSettings(), this.$saveMySettings() // - Settings shortcuts: this.$saveSettings()
// - Cache management: this.$refreshSettings(), this.$clearAllCaches() // - Cache management: this.$refreshSettings(), this.$clearAllCaches()
// - Ultra-concise database methods: this.$db(), this.$exec(), this.$query() // - Ultra-concise database methods: this.$db(), this.$exec(), this.$query()
// - All methods use smart caching with TTL for massive performance gains // - All methods use smart caching with TTL for massive performance gains

12
src/db-sql/migration.ts

@ -68,9 +68,19 @@ const MIG_004_SQL = `
WHERE id = 1 WHERE id = 1
AND EXISTS (SELECT 1 FROM settings WHERE id = 1 AND activeDid IS NOT NULL AND activeDid != ''); AND EXISTS (SELECT 1 FROM settings WHERE id = 1 AND activeDid IS NOT NULL AND activeDid != '');
-- Copy important settings that were set in the MASTER_SETTINGS_KEY to the main identity.
-- (We're not doing them all because some were already identity-specific and others aren't as critical.)
UPDATE settings
SET lastViewedClaimId = (SELECT lastViewedClaimId FROM settings WHERE id = 1),
profileImageUrl = (SELECT profileImageUrl FROM settings WHERE id = 1),
showShortcutBvc = (SELECT showShortcutBvc FROM settings WHERE id = 1),
warnIfProdServer = (SELECT warnIfProdServer FROM settings WHERE id = 1),
warnIfTestServer = (SELECT warnIfTestServer FROM settings WHERE id = 1)
WHERE id = 2;
-- CLEANUP: Remove orphaned settings records and clear legacy activeDid values -- CLEANUP: Remove orphaned settings records and clear legacy activeDid values
-- which usually simply deletes the MASTER_SETTINGS_KEY record.
-- This completes the migration from settings-based to table-based active identity -- This completes the migration from settings-based to table-based active identity
-- Use guarded operations to prevent accidental data loss
DELETE FROM settings WHERE accountDid IS NULL; DELETE FROM settings WHERE accountDid IS NULL;
UPDATE settings SET activeDid = NULL; UPDATE settings SET activeDid = NULL;
`; `;

2
src/services/migrationService.ts

@ -799,7 +799,7 @@ export async function runMigrations<T>(
} }
// Only show completion message in development // Only show completion message in development
logger.debug( logger.log(
`🎉 [Migration] Migration process complete! Summary: ${appliedCount} applied, ${skippedCount} skipped`, `🎉 [Migration] Migration process complete! Summary: ${appliedCount} applied, ${skippedCount} skipped`,
); );
} catch (error) { } catch (error) {

9
src/utils/PlatformServiceMixin.ts

@ -1212,6 +1212,11 @@ export const PlatformServiceMixin = {
* @param changes Settings changes to save * @param changes Settings changes to save
* @returns Promise<boolean> Success status * @returns Promise<boolean> Success status
*/ */
/**
* Since this is unused, and since it relies on this.activeDid which isn't guaranteed to exist,
* let's take this out for the sake of safety.
* Totally remove after start of 2026 (since it would be obvious by then that it's not used).
*
async $saveMySettings(changes: Partial<Settings>): Promise<boolean> { async $saveMySettings(changes: Partial<Settings>): Promise<boolean> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
const currentDid = (this as any).activeDid; const currentDid = (this as any).activeDid;
@ -1221,6 +1226,7 @@ export const PlatformServiceMixin = {
} }
return await this.$saveUserSettings(currentDid, changes); return await this.$saveUserSettings(currentDid, changes);
}, },
**/
// ================================================= // =================================================
// CACHE MANAGEMENT METHODS // CACHE MANAGEMENT METHODS
@ -2040,7 +2046,8 @@ declare module "@vue/runtime-core" {
did: string, did: string,
changes: Partial<Settings>, changes: Partial<Settings>,
): Promise<boolean>; ): Promise<boolean>;
$saveMySettings(changes: Partial<Settings>): Promise<boolean>; // @deprecated; see implementation note above
// $saveMySettings(changes: Partial<Settings>): Promise<boolean>;
// Cache management methods // Cache management methods
$refreshSettings(): Promise<Settings>; $refreshSettings(): Promise<Settings>;

4
src/views/HomeView.vue

@ -645,7 +645,9 @@ export default class HomeView extends Vue {
if (resp.status === 200) { if (resp.status === 200) {
// Ultra-concise settings update with automatic cache invalidation! // Ultra-concise settings update with automatic cache invalidation!
await this.$saveMySettings({ isRegistered: true }); await this.$saveUserSettings(this.activeDid, {
isRegistered: true,
});
this.isRegistered = true; this.isRegistered = true;
} }
} catch (error) { } catch (error) {

3
src/views/IdentitySwitcherView.vue

@ -306,6 +306,9 @@ export default class IdentitySwitcherView extends Vue {
} }
await this.$exec("DELETE FROM accounts WHERE id = ?", [id]); await this.$exec("DELETE FROM accounts WHERE id = ?", [id]);
await this.$exec("DELETE FROM settings WHERE accountDid = ?", [
accountDid,
]);
}); });
// Update UI // Update UI

Loading…
Cancel
Save