- Add Migration 005 to fix critical security vulnerability
- Change foreign key constraint from ON DELETE SET NULL to ON DELETE RESTRICT
- Prevents accidental account deletion through database constraints
- Update Active Pointer pattern documentation with current state analysis
- Achieve 83% compliance with Active Pointer + Smart Deletion Pattern
Security Impact: HIGH - Fixes critical data loss vulnerability
Migration: 005_active_identity_constraint_fix
Pattern Compliance: 5/6 components (83%)
Author: Matthew Raymer
- Update migration 003 to match master deployment (hasBackedUpSeed)
- Rename migration 004 for active_identity table creation
- Update migration service validation for new structure
- Fix TypeScript compatibility issue in migration.ts
- Streamline active identity upgrade plan documentation
- Ensure all migrations are additional per team guidance
Migration structure now follows "additional migrations only" principle:
- 003: hasBackedUpSeed (assumes master deployment)
- 004: active_identity table with data migration
- iOS/Android compatibility confirmed with SQLCipher 4.9.0
Files: migration.ts, migrationService.ts, active-identity-upgrade-plan.md
The migration 003_active_identity_and_seed_backup was failing on iOS when
switching from master to active_did_redux branch because it attempted to
execute multiple SQL operations in a single block. When the ALTER TABLE
statement for hasBackedUpSeed failed (due to column already existing),
the entire migration was marked as "already applied" even though the
active_identity table was never created.
Changes:
- Split migration 003 into two separate migrations:
- 003_active_identity_and_seed_backup: Creates active_identity table
- 003b_add_hasBackedUpSeed_to_settings: Adds hasBackedUpSeed column
- Added data migration logic to copy existing activeDid from settings
to active_identity table during migration
- Added debug logging to track migration results
- Ensured atomic operations so table creation doesn't depend on column addition
This fix ensures that:
- The active_identity table is always created successfully
- Existing activeDid values are preserved during migration
- The app remembers the active identity between master and active_did_redux builds
- Migration errors are handled gracefully without affecting other operations
Fixes iOS migration issue where app would lose active identity state
when switching between branches, causing users to lose their selected
identity and requiring manual re-selection.
Tested: Migration now works correctly on iOS simulator when switching
from master branch (with old schema) to active_did_redux branch.
- Fix $getActiveIdentity() logic flow preventing false "empty table" warnings
- Implement auto-selection of first account when activeDid is null after migration
- Consolidate 003 and 003b migrations into single 003 migration
- Re-introduce foreign key constraint for activeDid referential integrity
- Add comprehensive debug logging for migration troubleshooting
- Remove 003b validation logic and update migration name mapping
Fixes migration from master to active_did_redux branch and ensures system
always has valid activeDid for proper functionality.
- Split consolidated migration into 3 separate migrations
- Preserve master's 001_initial and 002_add_iViewContent structure
- Move active_identity creation to new 003_active_identity_and_seed_backup
- Add hasBackedUpSeed field from registration-prompt-parity branch
- Remove activeDid performance index for simplified migration
- Maintain foreign key constraints and smart deletion pattern
- Remove unused $getAllAccountDids method from PlatformServiceMixin
This restructure ensures backward compatibility with master branch
while adding advanced features (active_identity table, seed backup
tracking) in a clean, maintainable migration sequence.
- Consolidate migrations: merge 002/003 into 001_initial with UNIQUE did constraint
- Add foreign key: active_identity.activeDid REFERENCES accounts.did ON DELETE RESTRICT
- Replace empty string defaults with NULL for proper empty state handling
- Implement atomic smart deletion with auto-switch logic in IdentitySwitcherView
- Add DAL methods: $getAllAccountDids, $getActiveDid, $setActiveDid, $pickNextAccountDid
- Add migration bootstrapping to auto-select first account if none selected
- Block deletion of last remaining account with user notification
Refs: doc/active-pointer-smart-deletion-pattern.md
The complex table rewrite approach in migration 003_active_did_separation was
failing on iOS SQLite, causing "no such table: active_identity" errors. The
migration was being marked as applied despite validation failures.
Changes:
- Simplify migration SQL to only create active_identity table and migrate data
- Remove complex table rewrite that was failing on iOS SQLite versions
- Remove foreign key constraint that could cause compatibility issues
- Update validation logic to focus on active_identity table existence only
- Remove validation check for activeDid column removal from settings table
This approach is more reliable across different SQLite versions and platforms
while maintaining the core functionality of separating activeDid into its own
table for better database architecture.
Fixes iOS build database errors and ensures migration completes successfully.
- Add missing migrations table creation to 001_initial migration
- Consolidate migrations 003-006 into single 003_active_did_separation migration
- Rename migration for better clarity and logical grouping
- Preserve all original SQL operations and data integrity constraints
- Reduce migration complexity while maintaining functionality
This consolidation improves maintainability by grouping related schema changes
into logical atomic operations, reducing the total migration count by 50%.
- Add hasBackedUpSeed boolean flag to Settings interface
- Create database migration 003_add_hasBackedUpSeed_to_settings
- Update SeedBackupView to set flag when user reveals seed phrase
- Modify DataExportSection to conditionally show notification dot
- Implement robust error handling for database operations
The notification dot on the "Backup Identifier Seed" button only
appears while the user hasn't backed up their seed phrase. Once they
visit SeedBackupView and click "Reveal my Seed Phrase", the setting
is persisted and the notification dot disappears.
- Add $getActiveIdentity() method to PlatformServiceMixin interface
- Update HomeView.vue to use new active_identity API methods
- Update ContactsView.vue to use new active_identity API methods
- Fix apiServer default handling in PlatformServiceMixin
- Ensure DEFAULT_ENDORSER_API_SERVER is used when apiServer is empty
- Add comprehensive logging for debugging ActiveDid migration
- Resolve TypeScript interface issues with Vue mixins
- Add migration 003 with data migration logic to prevent data loss
- Create dedicated ActiveIdentity interface in separate file for better architecture
- Implement $getActiveIdentity method in PlatformServiceMixin
- Enhance $updateActiveDid with dual-write pattern for backward compatibility
- Maintain separation of concerns between settings and active identity types
- Follow project architectural pattern with dedicated type definition files
The migration creates active_identity table alongside existing settings,
automatically copying existing activeDid data to prevent user data loss.
Dual-write pattern ensures backward compatibility during transition.
Migration includes:
- Schema creation with proper constraints and indexes
- Automatic data transfer from settings.activeDid to active_identity.activeDid
- Validation to ensure data exists before migration
- Atomic operation: schema and data migration happen together
- Add type checking to build scripts for production/test builds only
- Fix TypeScript errors in migration service, router, and platform services
- Add electronAPI type declarations for Electron platform
- Remove type checking from development builds for faster hot reload
- Update tsconfig.node.json to resolve configuration conflicts
- Ensure type safety for production while maintaining fast development workflow
- Fix logToDb() to use actual database schema: 'date' and 'message' columns
- Change INSERT query from non-existent 'timestamp, level' to existing 'date, message'
- Change DELETE cleanup to use 'date' column instead of 'timestamp'
- Embed log level in message text as '[LEVEL] message' instead of separate column
- Use toDateString() format to match schema instead of toISOString()
Resolves: "table logs has no column named timestamp" infinite error loop
Critical: Enables Electron app initialization by matching code to existing schema
Impact: Stops database logging from crashing and allows normal app startup
- Fix logToDb() to use actual database schema: 'date' and 'message' columns
- Change INSERT query from non-existent 'timestamp, level' to existing 'date, message'
- Change DELETE cleanup to use 'date' column instead of 'timestamp'
- Embed log level in message text as '[LEVEL] message' instead of separate column
- Use toDateString() format to match schema instead of toISOString()
Resolves: "table logs has no column named timestamp" infinite error loop
Critical: Enables Electron app initialization by matching code to existing schema
Impact: Stops database logging from crashing and allows normal app startup
- Add comprehensive IndexedDB to SQLite migration service (1,397 lines)
- Create migration UI with progress tracking and validation (1,492 lines)
- Fix Electron TypeScript compilation and SQLite plugin issues
- Expand migration system with detailed documentation and error handling
- Add development guide and coding standards
Resolves: #electron-startup #database-migration #typescript-errors
Impact: Enables user-friendly database migration with full data verification
- Add comprehensive IndexedDB to SQLite migration service (1,397 lines)
- Create migration UI with progress tracking and validation (1,492 lines)
- Fix Electron TypeScript compilation and SQLite plugin issues
- Expand migration system with detailed documentation and error handling
- Add development guide and coding standards
Resolves: #electron-startup #database-migration #typescript-errors
Impact: Enables user-friendly database migration with full data verification
- Temporarily disable log inserts to break error loop and reveal underlying issues
- Fix secret table column mismatch: use 'secretBase64' for new schema, matching code expectations
- Add migration for correct secret table column
- Add rich comments and TODOs for future schema/code alignment
Author: Matthew Raymer
SECURITY AUDIT CHECKLIST:
- [x] No sensitive data exposed in logs
- [x] Database schema and code now consistent for secrets/logs/settings
- [x] No direct client exposure of secrets
- [x] Logging disabled to prevent error amplification
- [x] All changes reviewed for privacy and data integrity
- Temporarily disable log inserts to break error loop and reveal underlying issues
- Fix secret table column mismatch: use 'secretBase64' for new schema, matching code expectations
- Add migration for correct secret table column
- Add rich comments and TODOs for future schema/code alignment
Author: Matthew Raymer
SECURITY AUDIT CHECKLIST:
- [x] No sensitive data exposed in logs
- [x] Database schema and code now consistent for secrets/logs/settings
- [x] No direct client exposure of secrets
- [x] Logging disabled to prevent error amplification
- [x] All changes reviewed for privacy and data integrity
- Add detailed file-level documentation with architecture overview and usage examples
- Document all interfaces, classes, and methods with JSDoc comments
- Include migration philosophy, best practices, and schema evolution guidelines
- Add extensive inline documentation for database schema and table purposes
- Document privacy and security considerations in database design
- Provide troubleshooting guidance and logging explanations
- Add template and examples for future migration development
- Include platform-specific documentation for Capacitor SQLite integration
- Document validation and integrity checking processes with detailed steps
The migration system is now thoroughly documented for maintainability and
onboarding of new developers to the codebase.
- Add detailed file-level documentation with architecture overview and usage examples
- Document all interfaces, classes, and methods with JSDoc comments
- Include migration philosophy, best practices, and schema evolution guidelines
- Add extensive inline documentation for database schema and table purposes
- Document privacy and security considerations in database design
- Provide troubleshooting guidance and logging explanations
- Add template and examples for future migration development
- Include platform-specific documentation for Capacitor SQLite integration
- Document validation and integrity checking processes with detailed steps
The migration system is now thoroughly documented for maintainability and
onboarding of new developers to the codebase.
- Root cause: Migration names were not being properly inserted into migrations table
- Fixed parameter binding in Capacitor platform service migration functions
- Added detailed debugging to track SQL execution and parameter passing
- Reverted migrations back to proper form (without IF NOT EXISTS workarounds)
- Enhanced extractMigrationNames to handle Capacitor SQLite result format
The migration system should now properly track applied migrations and avoid
re-running them on subsequent app starts.
- Root cause: Migration names were not being properly inserted into migrations table
- Fixed parameter binding in Capacitor platform service migration functions
- Added detailed debugging to track SQL execution and parameter passing
- Reverted migrations back to proper form (without IF NOT EXISTS workarounds)
- Enhanced extractMigrationNames to handle Capacitor SQLite result format
The migration system should now properly track applied migrations and avoid
re-running them on subsequent app starts.
- Add comprehensive console logging for Electron with emojis for better visibility
- Use CREATE TABLE IF NOT EXISTS and INSERT OR IGNORE to prevent duplicate creation errors
- Add specialized column existence checking for ALTER TABLE ADD COLUMN operations
- Improve migration tracking with detailed status reporting (applied/skipped counts)
- Add proper error handling for existing schema scenarios
- Enhanced documentation and type safety for migration system
This resolves issues where migrations would fail with 'table already exists' or
'duplicate column' errors when the database schema was already properly set up.
The enhanced logging makes it clear to users when migrations are being skipped
vs. applied, improving the debugging experience in Electron.
- Add comprehensive console logging for Electron with emojis for better visibility
- Use CREATE TABLE IF NOT EXISTS and INSERT OR IGNORE to prevent duplicate creation errors
- Add specialized column existence checking for ALTER TABLE ADD COLUMN operations
- Improve migration tracking with detailed status reporting (applied/skipped counts)
- Add proper error handling for existing schema scenarios
- Enhanced documentation and type safety for migration system
This resolves issues where migrations would fail with 'table already exists' or
'duplicate column' errors when the database schema was already properly set up.
The enhanced logging makes it clear to users when migrations are being skipped
vs. applied, improving the debugging experience in Electron.
- Enhanced migration service to handle duplicate column errors gracefully
- Added detection for 'duplicate column' and 'already exists' errors
- Migration service now marks partially applied migrations as complete
- Prevents Electron app crashes due to cross-platform database conflicts
- Improved robustness for database schema migrations
Fixes database initialization issues when switching between platforms
(web, mobile, electron) that may have different migration states.
- Enhanced migration service to handle duplicate column errors gracefully
- Added detection for 'duplicate column' and 'already exists' errors
- Migration service now marks partially applied migrations as complete
- Prevents Electron app crashes due to cross-platform database conflicts
- Improved robustness for database schema migrations
Fixes database initialization issues when switching between platforms
(web, mobile, electron) that may have different migration states.
- Updated migration 001_initial to use INSERT OR IGNORE for secret and settings tables
- Prevents unique constraint failures when database already exists from previous runs
- Allows clean migration process without requiring database deletion
- Database initialization now works properly in development environment
Fixes:
- UNIQUE constraint failed: secret.id error resolved
- Migration process now handles existing data gracefully
- Fresh database creation works without conflicts
- Electron app now starts successfully with working database
All major Electron issues resolved:
✅ TypeScript compilation working
✅ SQLite plugin properly configured
✅ UI assets loading correctly
✅ Database migrations successful
✅ App startup and initialization working
- Updated migration 001_initial to use INSERT OR IGNORE for secret and settings tables
- Prevents unique constraint failures when database already exists from previous runs
- Allows clean migration process without requiring database deletion
- Database initialization now works properly in development environment
Fixes:
- UNIQUE constraint failed: secret.id error resolved
- Migration process now handles existing data gracefully
- Fresh database creation works without conflicts
- Electron app now starts successfully with working database
All major Electron issues resolved:
✅ TypeScript compilation working
✅ SQLite plugin properly configured
✅ UI assets loading correctly
✅ Database migrations successful
✅ App startup and initialization working
- Fix import in src/db-sql/migration.ts to use named imports and alias runMigrations to avoid naming conflict
- Add missing migration management functions (registerMigration, runMigrations) to migrationService with full typing and logging
- Update function signatures to accept SQL parameters for compatibility with AbsurdSqlDatabaseService
- Clean up Prettier formatting issues in migrationService and migration.ts
- Confirmed dev server and linter run cleanly
Co-authored-by: Matthew Raymer
- Fix import in src/db-sql/migration.ts to use named imports and alias runMigrations to avoid naming conflict
- Add missing migration management functions (registerMigration, runMigrations) to migrationService with full typing and logging
- Update function signatures to accept SQL parameters for compatibility with AbsurdSqlDatabaseService
- Clean up Prettier formatting issues in migrationService and migration.ts
- Confirmed dev server and linter run cleanly
Co-authored-by: Matthew Raymer
- Add camera state tracking and listener management
- Implement addCameraStateListener and removeCameraStateListener methods
- Add state transitions during scanning operations
- Improve error handling with state updates
- Add proper type imports for CameraState and CameraStateListener
This change ensures CapacitorQRScanner fully implements the QRScannerService
interface and provides proper camera state feedback to consumers. Camera state
is now tracked through the entire lifecycle of scanning operations, with
appropriate state transitions for initialization, active scanning, errors,
and cleanup.
- Add camera state tracking and listener management
- Implement addCameraStateListener and removeCameraStateListener methods
- Add state transitions during scanning operations
- Improve error handling with state updates
- Add proper type imports for CameraState and CameraStateListener
This change ensures CapacitorQRScanner fully implements the QRScannerService
interface and provides proper camera state feedback to consumers. Camera state
is now tracked through the entire lifecycle of scanning operations, with
appropriate state transitions for initialization, active scanning, errors,
and cleanup.