forked from trent_larson/crowd-funder-for-time-pwa
IndexedDB migration: don't run activeDid migration twice, include warnings in output, don't automatically compare afterward
This commit is contained in:
@@ -1081,17 +1081,6 @@ export async function migrateSettings(): Promise<MigrationResult> {
|
||||
});
|
||||
const platformService = PlatformServiceFactory.getInstance();
|
||||
|
||||
// Find the master settings (accountDid is null) which contains the activeDid
|
||||
const masterSettings = dexieSettings.find(setting => !setting.accountDid);
|
||||
let dexieActiveDid: string | undefined;
|
||||
|
||||
if (masterSettings?.activeDid) {
|
||||
dexieActiveDid = masterSettings.activeDid;
|
||||
logger.info("[MigrationService] Found activeDid in Dexie master settings", {
|
||||
activeDid: dexieActiveDid,
|
||||
});
|
||||
}
|
||||
|
||||
// Create an array of promises for all settings migrations
|
||||
const migrationPromises = dexieSettings.map(async (setting) => {
|
||||
logger.info("[MigrationService] Starting to migrate settings", setting);
|
||||
@@ -1152,36 +1141,7 @@ export async function migrateSettings(): Promise<MigrationResult> {
|
||||
const updatedSettings = await Promise.all(migrationPromises);
|
||||
|
||||
// Step 2: Migrate the activeDid if it exists in Dexie
|
||||
if (dexieActiveDid) {
|
||||
try {
|
||||
// Verify that the activeDid exists in SQLite accounts
|
||||
const accountExists = await platformService.dbQuery(
|
||||
"SELECT did FROM accounts WHERE did = ?",
|
||||
[dexieActiveDid],
|
||||
);
|
||||
|
||||
if (accountExists?.values?.length) {
|
||||
// Update the master settings with the activeDid
|
||||
await updateDefaultSettings({ activeDid: dexieActiveDid });
|
||||
logger.info("[MigrationService] Successfully migrated activeDid", {
|
||||
activeDid: dexieActiveDid,
|
||||
});
|
||||
result.warnings.push(`Migrated activeDid: ${dexieActiveDid}`);
|
||||
} else {
|
||||
logger.warn("[MigrationService] activeDid from Dexie not found in SQLite accounts", {
|
||||
activeDid: dexieActiveDid,
|
||||
});
|
||||
result.warnings.push(
|
||||
`activeDid from Dexie (${dexieActiveDid}) not found in SQLite accounts - skipping activeDid migration`,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error("[MigrationService] Failed to migrate activeDid:", error);
|
||||
result.errors.push(`Failed to migrate activeDid: ${error}`);
|
||||
}
|
||||
} else {
|
||||
logger.info("[MigrationService] No activeDid found in Dexie settings");
|
||||
}
|
||||
await migrateActiveDid();
|
||||
|
||||
logger.info(
|
||||
"[MigrationService] Finished migrating settings",
|
||||
@@ -1467,18 +1427,6 @@ export async function migrateAll(): Promise<MigrationResult> {
|
||||
result.settingsMigrated = settingsResult.settingsMigrated;
|
||||
result.warnings.push(...settingsResult.warnings);
|
||||
|
||||
// Step 3: Migrate ActiveDid (depends on accounts and settings)
|
||||
logger.info("[MigrationService] Step 3: Migrating activeDid...");
|
||||
const activeDidResult = await migrateActiveDid();
|
||||
if (!activeDidResult.success) {
|
||||
result.errors.push(
|
||||
`ActiveDid migration failed: ${activeDidResult.errors.join(", ")}`,
|
||||
);
|
||||
// Don't fail the entire migration for activeDid issues
|
||||
logger.warn("[MigrationService] ActiveDid migration failed, but continuing with migration");
|
||||
}
|
||||
result.warnings.push(...activeDidResult.warnings);
|
||||
|
||||
// Step 4: Migrate Contacts (independent, but after accounts for consistency)
|
||||
// ... but which is better done through the contact import view
|
||||
// logger.info("[MigrationService] Step 4: Migrating contacts...");
|
||||
|
||||
@@ -200,6 +200,28 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Warning State -->
|
||||
<div
|
||||
v-if="warning"
|
||||
class="mb-6 bg-red-50 border border-red-200 rounded-lg p-4"
|
||||
>
|
||||
<div class="flex">
|
||||
<div class="flex-shrink-0">
|
||||
<IconRenderer
|
||||
icon-name="warning"
|
||||
svg-class="h-5 w-5 text-red-400"
|
||||
fill="currentColor"
|
||||
/>
|
||||
</div>
|
||||
<div class="ml-3">
|
||||
<h3 class="text-sm font-medium text-red-800">Warning</h3>
|
||||
<div class="mt-2 text-sm text-red-700">
|
||||
<p>{{ warning }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Success State -->
|
||||
<div
|
||||
v-if="successMessage"
|
||||
@@ -1099,6 +1121,7 @@ export default class DatabaseMigration extends Vue {
|
||||
private isLoading = false;
|
||||
private loadingMessage = "";
|
||||
private error = "";
|
||||
private warning = "";
|
||||
private exportedData: Record<string, any> | null = null;
|
||||
private successMessage = "";
|
||||
|
||||
@@ -1248,6 +1271,7 @@ export default class DatabaseMigration extends Vue {
|
||||
this.successMessage = `Successfully migrated ${totalMigrated} total records: ${result.accountsMigrated} accounts, ${result.settingsMigrated} settings, ${result.contactsMigrated} contacts.`;
|
||||
if (result.warnings.length > 0) {
|
||||
this.successMessage += ` ${result.warnings.length} warnings.`;
|
||||
this.warning += result.warnings.join(", ");
|
||||
}
|
||||
this.successMessage += " Now finish by migrating contacts.";
|
||||
logger.info(
|
||||
@@ -1255,8 +1279,7 @@ export default class DatabaseMigration extends Vue {
|
||||
result,
|
||||
);
|
||||
|
||||
// Refresh comparison data after successful migration
|
||||
this.comparison = await compareDatabases();
|
||||
this.comparison = null;
|
||||
} else {
|
||||
this.error = `Migration failed: ${result.errors.join(", ")}`;
|
||||
logger.error(
|
||||
@@ -1342,14 +1365,14 @@ export default class DatabaseMigration extends Vue {
|
||||
this.successMessage = `Successfully migrated ${result.settingsMigrated} settings.`;
|
||||
if (result.warnings.length > 0) {
|
||||
this.successMessage += ` ${result.warnings.length} warnings.`;
|
||||
this.warning += result.warnings.join(", ");
|
||||
}
|
||||
logger.info(
|
||||
"[DatabaseMigration] Settings migration completed successfully",
|
||||
result,
|
||||
);
|
||||
|
||||
// Refresh comparison data after successful migration
|
||||
this.comparison = await compareDatabases();
|
||||
this.comparison = null;
|
||||
} else {
|
||||
this.error = `Migration failed: ${result.errors.join(", ")}`;
|
||||
logger.error(
|
||||
@@ -1385,14 +1408,14 @@ export default class DatabaseMigration extends Vue {
|
||||
this.successMessage = `Successfully migrated ${result.accountsMigrated} accounts.`;
|
||||
if (result.warnings.length > 0) {
|
||||
this.successMessage += ` ${result.warnings.length} warnings.`;
|
||||
this.warning += result.warnings.join(", ");
|
||||
}
|
||||
logger.info(
|
||||
"[DatabaseMigration] Account migration completed successfully",
|
||||
result,
|
||||
);
|
||||
|
||||
// Refresh comparison data after successful migration
|
||||
this.comparison = await compareDatabases();
|
||||
this.comparison = null;
|
||||
} else {
|
||||
this.error = `Migration failed: ${result.errors.join(", ")}`;
|
||||
logger.error(
|
||||
|
||||
Reference in New Issue
Block a user