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();
|
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
|
// Create an array of promises for all settings migrations
|
||||||
const migrationPromises = dexieSettings.map(async (setting) => {
|
const migrationPromises = dexieSettings.map(async (setting) => {
|
||||||
logger.info("[MigrationService] Starting to migrate settings", 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);
|
const updatedSettings = await Promise.all(migrationPromises);
|
||||||
|
|
||||||
// Step 2: Migrate the activeDid if it exists in Dexie
|
// Step 2: Migrate the activeDid if it exists in Dexie
|
||||||
if (dexieActiveDid) {
|
await migrateActiveDid();
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"[MigrationService] Finished migrating settings",
|
"[MigrationService] Finished migrating settings",
|
||||||
@@ -1467,18 +1427,6 @@ export async function migrateAll(): Promise<MigrationResult> {
|
|||||||
result.settingsMigrated = settingsResult.settingsMigrated;
|
result.settingsMigrated = settingsResult.settingsMigrated;
|
||||||
result.warnings.push(...settingsResult.warnings);
|
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)
|
// Step 4: Migrate Contacts (independent, but after accounts for consistency)
|
||||||
// ... but which is better done through the contact import view
|
// ... but which is better done through the contact import view
|
||||||
// logger.info("[MigrationService] Step 4: Migrating contacts...");
|
// logger.info("[MigrationService] Step 4: Migrating contacts...");
|
||||||
|
|||||||
@@ -200,6 +200,28 @@
|
|||||||
</div>
|
</div>
|
||||||
</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 -->
|
<!-- Success State -->
|
||||||
<div
|
<div
|
||||||
v-if="successMessage"
|
v-if="successMessage"
|
||||||
@@ -1099,6 +1121,7 @@ export default class DatabaseMigration extends Vue {
|
|||||||
private isLoading = false;
|
private isLoading = false;
|
||||||
private loadingMessage = "";
|
private loadingMessage = "";
|
||||||
private error = "";
|
private error = "";
|
||||||
|
private warning = "";
|
||||||
private exportedData: Record<string, any> | null = null;
|
private exportedData: Record<string, any> | null = null;
|
||||||
private successMessage = "";
|
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.`;
|
this.successMessage = `Successfully migrated ${totalMigrated} total records: ${result.accountsMigrated} accounts, ${result.settingsMigrated} settings, ${result.contactsMigrated} contacts.`;
|
||||||
if (result.warnings.length > 0) {
|
if (result.warnings.length > 0) {
|
||||||
this.successMessage += ` ${result.warnings.length} warnings.`;
|
this.successMessage += ` ${result.warnings.length} warnings.`;
|
||||||
|
this.warning += result.warnings.join(", ");
|
||||||
}
|
}
|
||||||
this.successMessage += " Now finish by migrating contacts.";
|
this.successMessage += " Now finish by migrating contacts.";
|
||||||
logger.info(
|
logger.info(
|
||||||
@@ -1255,8 +1279,7 @@ export default class DatabaseMigration extends Vue {
|
|||||||
result,
|
result,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Refresh comparison data after successful migration
|
this.comparison = null;
|
||||||
this.comparison = await compareDatabases();
|
|
||||||
} else {
|
} else {
|
||||||
this.error = `Migration failed: ${result.errors.join(", ")}`;
|
this.error = `Migration failed: ${result.errors.join(", ")}`;
|
||||||
logger.error(
|
logger.error(
|
||||||
@@ -1342,14 +1365,14 @@ export default class DatabaseMigration extends Vue {
|
|||||||
this.successMessage = `Successfully migrated ${result.settingsMigrated} settings.`;
|
this.successMessage = `Successfully migrated ${result.settingsMigrated} settings.`;
|
||||||
if (result.warnings.length > 0) {
|
if (result.warnings.length > 0) {
|
||||||
this.successMessage += ` ${result.warnings.length} warnings.`;
|
this.successMessage += ` ${result.warnings.length} warnings.`;
|
||||||
|
this.warning += result.warnings.join(", ");
|
||||||
}
|
}
|
||||||
logger.info(
|
logger.info(
|
||||||
"[DatabaseMigration] Settings migration completed successfully",
|
"[DatabaseMigration] Settings migration completed successfully",
|
||||||
result,
|
result,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Refresh comparison data after successful migration
|
this.comparison = null;
|
||||||
this.comparison = await compareDatabases();
|
|
||||||
} else {
|
} else {
|
||||||
this.error = `Migration failed: ${result.errors.join(", ")}`;
|
this.error = `Migration failed: ${result.errors.join(", ")}`;
|
||||||
logger.error(
|
logger.error(
|
||||||
@@ -1385,14 +1408,14 @@ export default class DatabaseMigration extends Vue {
|
|||||||
this.successMessage = `Successfully migrated ${result.accountsMigrated} accounts.`;
|
this.successMessage = `Successfully migrated ${result.accountsMigrated} accounts.`;
|
||||||
if (result.warnings.length > 0) {
|
if (result.warnings.length > 0) {
|
||||||
this.successMessage += ` ${result.warnings.length} warnings.`;
|
this.successMessage += ` ${result.warnings.length} warnings.`;
|
||||||
|
this.warning += result.warnings.join(", ");
|
||||||
}
|
}
|
||||||
logger.info(
|
logger.info(
|
||||||
"[DatabaseMigration] Account migration completed successfully",
|
"[DatabaseMigration] Account migration completed successfully",
|
||||||
result,
|
result,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Refresh comparison data after successful migration
|
this.comparison = null;
|
||||||
this.comparison = await compareDatabases();
|
|
||||||
} else {
|
} else {
|
||||||
this.error = `Migration failed: ${result.errors.join(", ")}`;
|
this.error = `Migration failed: ${result.errors.join(", ")}`;
|
||||||
logger.error(
|
logger.error(
|
||||||
|
|||||||
Reference in New Issue
Block a user