Reboot of the ActiveDID migration
#188
Open
anomalist
wants to merge 81 commits from active_did_redux
into master
pull from: active_did_redux
merge into: trent_larson:master
trent_larson:account-import-duplicate-prevention
trent_larson:activedid_migration
trent_larson:ai-context
trent_larson:android-15-check
trent_larson:android-file-save
trent_larson:android-safe-area-insets
trent_larson:app_id_fix
trent_larson:ask-for-contacts-export
trent_larson:build-dev-to-dist
trent_larson:build-improvement
trent_larson:build-ios
trent_larson:build-web-serve-test
trent_larson:build-with-env
trent_larson:capacitor-local-save
trent_larson:claim-view-error-handling
trent_larson:claimview-fullfills-offer
trent_larson:contact-gifting-current-user
trent_larson:contacts-view-fixes
trent_larson:cross-platform-factory
trent_larson:cross-platform-factory-redux
trent_larson:d9085ced6df7dc7bdcd899959cea6489cab7f8b8
trent_larson:db-backup-cross-platform
trent_larson:deep-link
trent_larson:deep-link-views-safe-area-inset
trent_larson:deep-links-android-update
trent_larson:deep_linking
trent_larson:design-tweaks-2023-12
trent_larson:dialog-notification-z-index
trent_larson:dialog-styles-unified
trent_larson:didview-invalid-did-handling
trent_larson:electron-build-capacitor-config
trent_larson:electron-build-config-overwrite
trent_larson:electron-copy-paste-keyboard-shortcuts
trent_larson:electron_fix_20250317
trent_larson:experimental_plugin
trent_larson:eye-slash
trent_larson:fix-contact-import-export
trent_larson:fix-deep-link
trent_larson:fix-service-worker
trent_larson:friend-tech-inspired-pwa-dialog
trent_larson:get-get-hash
trent_larson:gifting-periphery-improvements
trent_larson:gifting-ui-2025-05
trent_larson:home-icon-enhancements
trent_larson:home-view-notification-improvements
trent_larson:homeview-cleanup-2025-03
trent_larson:homeview-refresh-2025-02
trent_larson:imagemagick-anrdoid
trent_larson:ios-contact-copy
trent_larson:ios-qr-code-copy
trent_larson:logger-level
trent_larson:logging-upgrade
trent_larson:main
trent_larson:master
trent_larson:master-patch
trent_larson:master-settings-upgrade
trent_larson:matthew-scratch-2025-06-28
trent_larson:migrate-dexie-to-sqlite
trent_larson:nearby-filter
trent_larson:new-activity-mark-read
trent_larson:new-storage
trent_larson:nostr
trent_larson:notification-line-wrapping
trent_larson:notification-request-permission-dialog
trent_larson:notification-section
trent_larson:notification-system
trent_larson:notify-time
trent_larson:offer-edit
trent_larson:offer-validation-logic
trent_larson:onboard-alert-component
trent_larson:onboarding-dialog-fix
trent_larson:passkey
trent_larson:passkey-cache
trent_larson:performance-optimizations-testing
trent_larson:photo-reverse
trent_larson:plan-loc
trent_larson:platformservicemixin-interface-consolidation
trent_larson:playwright-pwa-install-test
trent_larson:playwright-test-00-fix
trent_larson:playwright-test-60-fix
trent_larson:playwright-test-updates
trent_larson:profile-pic
trent_larson:profile_include_location
trent_larson:project-gives
trent_larson:projectview-hide-offer-link-unregistered
trent_larson:qrcode-capacitor
trent_larson:registration-gate
trent_larson:registration-prompt-parity
trent_larson:remove-image-cache
trent_larson:replace-iconrenderer
trent_larson:search-map-fix
trent_larson:seed-phrase-backup-prompt
trent_larson:side_step
trent_larson:simple-signer
trent_larson:split_build_process
trent_larson:sql-absurd-sql
trent_larson:sql-absurd-sql-further
trent_larson:sql-wa-sqlite
trent_larson:star-projects
trent_larson:starred-projects
trent_larson:streamline-attempt
trent_larson:sw-cleanup
trent_larson:switching-identities-change-name
trent_larson:tmp
trent_larson:trent-tweaks
trent_larson:tweaks
trent_larson:ui-fixes-2024-03
trent_larson:ui-fixes-2025-03
trent_larson:ui-fixes-2025-06-w2
trent_larson:units-mocking
trent_larson:v-onboarding-2024-04
trent_larson:vite-version
trent_larson:web-serve-fix
trent_larson:web-tests
trent_larson:wip_new_notifications
Reviewers
Request review
No reviewers
Labels
Apply labels
Clear labels
No items
No Label
Milestone
Set milestone
Clear milestone
No items
No Milestone
Assignees
Assign users
Clear assignees
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.
No due date set.
Dependencies
This pull request currently doesn't have any dependencies.
Reference in new issue
There is no content yet.
Delete Branch 'active_did_redux'
Deleting a branch is permanent. It CANNOT be undone. Continue?
No
Yes
ActiveDid Migration Plan - Separate Table Architecture
Author: Matthew Raymer
Date: 2025-01-27T18:30Z
Status: 🎯 PLANNING - Active migration planning phase
Objective
Move the
activeDid
field from thesettings
table to a dedicatedactive_identity
table to improve database architecture and separateidentity selection from user preferences.
Result
This document serves as the comprehensive planning and implementation
guide for the ActiveDid migration.
Use/Run
Reference this document during implementation to ensure all migration
steps are followed correctly and all stakeholders are aligned on the
approach.
Context & Scope
Environment & Preconditions
Architecture / Process Overview
The migration follows a phased approach to minimize risk and ensure
data integrity:
Interfaces & Contracts
Database Schema Changes
settings
activeDid TEXT
active_identity
activeDid TEXT
API Contract Changes
$accountSettings()
$saveSettings()
$updateActiveDid()
Repro: End-to-End Procedure
Phase 1: Schema Creation
Phase 2: Data Migration
Phase 3: API Updates
What Works (Evidence)
✅ Current activeDid storage in settings table
src/db/tables/settings.ts:25
- activeDid field exists✅ PlatformServiceMixin integration with activeDid
src/utils/PlatformServiceMixin.ts:108
- activeDid tracking✅ Database migration infrastructure exists
src/db-sql/migration.ts:31
- migration system in placeWhat Doesn't (Evidence & Hypotheses)
❌ No separate active_identity table exists
❌ Platform services hardcoded to settings table
src/services/platforms/*.ts
- direct settings table accessRisks, Limits, Assumptions
Next Steps
References
Competence Hooks
user preferences, improves database normalization, enables future
identity management features
testing rollback scenarios, missing data validation during migration
planning
phase is necessary
Collaboration Hooks
Assumptions & Limits
Component & View Impact Analysis
High Impact Components
IdentitySection.vue
- Direct dependency onactiveDid
activeDid
from component dataCurrent Implementation:
Required Changes:
DIDView.vue
- Heavy activeDid usageactiveDid
inmounted()
lifecycleCurrent Implementation:
Required Changes:
HomeView.vue
- ActiveDid change detectiononActiveDidChanged()
watcher methodCurrent Implementation:
Required Changes:
Key Insight: HomeView will require minimal changes since it already uses
the
$accountSettings()
method, which will be updated to handle the newtable structure transparently.
Medium Impact Components
InviteOneAcceptView.vue
- Identity fallback logicactiveDid
existsClaimView.vue
- Settings retrievalactiveDid
from$accountSettings()
ContactAmountsView.vue
- Direct settings accessactiveDid
directly from settingsService Layer Impact
WebPlatformService.ts
active_identity
table queriesCapacitorPlatformService.ts
PlatformServiceMixin.ts
$accountSettings()
,$saveSettings()
API Contract Changes
$saveSettings()
methodsettings.activeDid
active_identity.activeDid
$updateActiveDid()
methodTesting Impact
Unit Tests
Integration Tests
Platform Tests
Performance Impact
Additional Table Join
Caching Considerations
Risk Assessment by Component Type
$accountSettings()
Migration Timeline Impact
Update Priority Order
Deferred for depth
-- Create new active_identity table with proper constraints
CREATE TABLE IF NOT EXISTS active_identity (
id INTEGER PRIMARY KEY CHECK (id = 1),
activeDid TEXT NOT NULL,
Since the activeDid can actually be a blank ('') value, I personally would prefer that this is nullable. (Saying "NOT NULL" but using '' to represent null just feels odd... like something that's trying to bypass type-checking.)
);
-- Add performance indexes
CREATE INDEX IF NOT EXISTS idx_active_identity_activeDid ON active_identity(activeDid);
Why put an index on activeDid? It'll never be the input to a query.
-- Add performance indexes
CREATE INDEX IF NOT EXISTS idx_active_identity_activeDid ON active_identity(activeDid);
CREATE UNIQUE INDEX IF NOT EXISTS idx_active_identity_single_record ON active_identity(id);
There's no reason to index the 'id' column since it's a primary key. (Even if it weren't, we'll only ever have one entry so an index is overkill.)
logger.info("[GiftedDialog] Settings received:", {
activeDid: this.activeDid,
apiServer: this.apiServer,
});
I vote we make this a debug.
);
}
},
I'm not convinced this is the approach we want for data consistency. If the initial migration goes wrong then we have bigger problems (and hopefully we notify the user).
This will actually pick some other value indiscriminately, and it could do it an unexpected times (eg. in the ContactsView explicitly in this PR, or any other page that accesses the getActiveIdentity). I vote we remove it, and if we feel there are migration problems then provide more feedback for the user to choose.
I will have to give this some thought. It did seem to give the whole migration more stability -- but I feel you that it seems a bit "icky"
(Unfortunately the lines have changed, but I assume this is all about the $needsActiveIdentitySelection method.)
I don't see where this is used now. Maybe the usages have been removed, in which case this could be removed. If it's still used or in planning, I'll watch for the usages... I tried to determine the purpose (like why it's good to return true if there is no active identity but there are other settings) but I don't understand.
$needsActiveIdentitySelection is still there as a definition but it unused. I'm removing it.
It's gone! 💥
I like the removal of the MASTER_SETTINGS here! 👏 Let's hope it goes well.
I vote we make all those migrations into a single one, since they're all part of the same merge when we go to master.
await this.$dbExec(
"UPDATE active_identity SET activeDid = '', lastUpdated = datetime('now') WHERE id = 1",
);
return { activeDid: "" };
I'm still not sure that these checks are necessary but I won't let that hold up things since I don't see how it can hurt. But: instead of erasing the activeDid, I suggest we keep the value and create a blank entry for it in the settings table.
I tweaked this a bit but the checks are still there. I've got it wired up to a foreign key (accounts.did).
I'll try a bit of a clean-up experiment.
Looks good to me.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
void id;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
void activeDidField;
These voids seem unnecessary. Educate me if I'm wrong.
Really depends on your philosophy of typing. I vote they stay since they only make it explicit and don't survive into the actual build.
elementWillRender:
this.numNewOffersToUser + this.numNewOffersToUserProjects > 0,
timestamp: new Date().toISOString(),
});
More logging that seems like they should be "debug" statements.
I'll be doing another pass on these before we merge into master.
return true;
}
return false;
}, { timeout: 5000 });
If these timeout, do the tests fail? (I hope so. The Playwright docs don't make it obvious.)
If I remember correctly (and pretty sure I do), there is a global timeout of 45s so "yes".
Updated. Internal documentation to spell this out for you.
if (process.env.NODE_ENV === 'development') {
process.env.VITE_DEFAULT_ENDORSER_API_SERVER = 'http://localhost:3000';
process.env.VITE_DEFAULT_PARTNER_API_SERVER = 'http://localhost:3000';
}
If this is necessary then it appears that something is wrong with the ".env.development" environment loading on line 9. Is there something deeper to fix here? (I ask because it's the addition of more environment logic, where it would be preferable to keep these forced settings isolated for maintainability.)
Yeah I saw this as well. I'll clean this up today.
Reviewers