forked from jsnbuchanan/crowd-funder-for-time-pwa
chore: sync adjustments
This commit is contained in:
@@ -65,14 +65,6 @@ Follow this implementation checklist step-by-step to complete the migration.
|
|||||||
|
|
||||||
-- Insert default record (will be updated during migration)
|
-- Insert default record (will be updated during migration)
|
||||||
INSERT OR IGNORE INTO active_identity (id, activeDid, lastUpdated) VALUES (1, '', datetime('now'));
|
INSERT OR IGNORE INTO active_identity (id, activeDid, lastUpdated) VALUES (1, '', datetime('now'));
|
||||||
|
|
||||||
-- MIGRATE EXISTING DATA: Copy activeDid from settings to active_identity
|
|
||||||
-- This prevents data loss when migration runs on existing databases
|
|
||||||
UPDATE active_identity
|
|
||||||
SET activeDid = (SELECT activeDid FROM settings WHERE id = 1),
|
|
||||||
lastUpdated = datetime('now')
|
|
||||||
WHERE id = 1
|
|
||||||
AND EXISTS (SELECT 1 FROM settings WHERE id = 1 AND activeDid IS NOT NULL AND activeDid != '');
|
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
@@ -124,7 +116,7 @@ async $getActiveIdentity(): Promise<{ activeDid: string }> {
|
|||||||
async $accountSettings(did?: string, defaults: Settings = {}): Promise<Settings> {
|
async $accountSettings(did?: string, defaults: Settings = {}): Promise<Settings> {
|
||||||
try {
|
try {
|
||||||
// Get settings without activeDid (unchanged logic)
|
// Get settings without activeDid (unchanged logic)
|
||||||
const settings = await this._getSettingsWithoutActiveDid();
|
const settings = await this.$getMasterSettings(defaults);
|
||||||
|
|
||||||
if (!settings) {
|
if (!settings) {
|
||||||
return defaults;
|
return defaults;
|
||||||
@@ -142,9 +134,61 @@ async $accountSettings(did?: string, defaults: Settings = {}): Promise<Settings>
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### 4. Component Updates Required
|
### 4. Updated $updateActiveDid Method
|
||||||
|
|
||||||
**35+ components need this pattern change:**
|
```typescript
|
||||||
|
// Update in PlatformServiceMixin.ts
|
||||||
|
async $updateActiveDid(newDid: string | null): Promise<boolean> {
|
||||||
|
try {
|
||||||
|
if (newDid === null) {
|
||||||
|
// Clear active identity in both tables
|
||||||
|
await this.$dbExec(
|
||||||
|
"UPDATE active_identity SET activeDid = '', lastUpdated = datetime('now') WHERE id = 1"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Keep legacy field in sync (backward compatibility)
|
||||||
|
await this.$dbExec(
|
||||||
|
"UPDATE settings SET activeDid = '' WHERE id = ?",
|
||||||
|
[MASTER_SETTINGS_KEY]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Validate DID exists before setting
|
||||||
|
const accountExists = await this.$dbQuery(
|
||||||
|
"SELECT did FROM accounts WHERE did = ?",
|
||||||
|
[newDid]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!accountExists?.values?.length) {
|
||||||
|
logger.error(`[PlatformServiceMixin] Cannot set activeDid to non-existent DID: ${newDid}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update active identity in new table
|
||||||
|
await this.$dbExec(
|
||||||
|
"UPDATE active_identity SET activeDid = ?, lastUpdated = datetime('now') WHERE id = 1",
|
||||||
|
[newDid]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Keep legacy field in sync (backward compatibility)
|
||||||
|
await this.$dbExec(
|
||||||
|
"UPDATE settings SET activeDid = ? WHERE id = ?",
|
||||||
|
[newDid, MASTER_SETTINGS_KEY]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update internal tracking
|
||||||
|
await this._updateInternalActiveDid(newDid);
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("[PlatformServiceMixin] Error updating activeDid:", error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. Component Updates Required
|
||||||
|
|
||||||
|
**35 components need this pattern change:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
// CURRENT PATTERN (replace in all components):
|
// CURRENT PATTERN (replace in all components):
|
||||||
@@ -157,7 +201,7 @@ this.activeDid = activeIdentity.activeDid || "";
|
|||||||
|
|
||||||
**Components requiring updates:**
|
**Components requiring updates:**
|
||||||
|
|
||||||
#### Views (25 components)
|
#### Views (28 components)
|
||||||
- `src/views/DIDView.vue` (line 378)
|
- `src/views/DIDView.vue` (line 378)
|
||||||
- `src/views/TestView.vue` (line 654)
|
- `src/views/TestView.vue` (line 654)
|
||||||
- `src/views/ContactAmountsView.vue` (line 226)
|
- `src/views/ContactAmountsView.vue` (line 226)
|
||||||
@@ -188,7 +232,7 @@ this.activeDid = activeIdentity.activeDid || "";
|
|||||||
- `src/views/ConfirmGiftView.vue` (line 549)
|
- `src/views/ConfirmGiftView.vue` (line 549)
|
||||||
- `src/views/ContactImportView.vue` (line 342)
|
- `src/views/ContactImportView.vue` (line 342)
|
||||||
|
|
||||||
#### Components (10 components)
|
#### Components (7 components)
|
||||||
- `src/components/OfferDialog.vue` (line 177)
|
- `src/components/OfferDialog.vue` (line 177)
|
||||||
- `src/components/PhotoDialog.vue` (line 270)
|
- `src/components/PhotoDialog.vue` (line 270)
|
||||||
- `src/components/GiftedDialog.vue` (line 223)
|
- `src/components/GiftedDialog.vue` (line 223)
|
||||||
@@ -241,7 +285,7 @@ private async initializeSettings() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### 5. Data Migration Function
|
### 6. Data Migration Function
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
// Add to migration.ts
|
// Add to migration.ts
|
||||||
@@ -290,9 +334,11 @@ async function migrateActiveDidToSeparateTable(): Promise<MigrationResult> {
|
|||||||
result.warnings.push(`Successfully migrated activeDid: ${activeDid}`);
|
result.warnings.push(`Successfully migrated activeDid: ${activeDid}`);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("[PlatformServiceMixin] Error getting active identity:", error);
|
result.errors.push(`Migration failed: ${error}`);
|
||||||
throw error;
|
logger.error("[ActiveDid Migration] Critical error during migration:", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user