diff --git a/src/migrations/migrate.ts b/src/migrations/migrate.ts index 14cc32f..0acb461 100644 --- a/src/migrations/migrate.ts +++ b/src/migrations/migrate.ts @@ -4,7 +4,6 @@ import { Migrations } from "./Migrations"; import migrateToMacroIDFromEmbeddedMacro from "./migrateToMacroIDFromEmbeddedMacro"; import useQuickAddTemplateFolder from "./useQuickAddTemplateFolder"; import incrementFileNameSettingMoveToDefaultBehavior from "./incrementFileNameSettingMoveToDefaultBehavior"; -import { moment } from "obsidian"; import mutualExclusionInsertAfterAndWriteToBottomOfFile from "./mutualExclusionInsertAfterAndWriteToBottomOfFile"; const migrations: Migrations = { @@ -14,24 +13,6 @@ const migrations: Migrations = { mutualExclusionInsertAfterAndWriteToBottomOfFile, }; -const backupFolderPath = ".obsidian/plugins/quickadd/backup"; - -const getBackupPath = (backupName: string): string => - `${backupFolderPath}/${moment().format( - "DD-MM-YY_HH-mm-ss" - )}_${backupName}.json`; - -// Unfortunately, we cannot use 'app.vault.getAbstractFileByPath' here, because it doesn't seem to index files in the .obsidian folder. -async function makeBackupFolderIfNotExists() { - try { - await app.vault.createFolder(backupFolderPath); - } catch (error) { - if (!error.message?.includes("Folder already exists")) { - throw error; - } - } -} - async function migrate(plugin: QuickAdd): Promise { const migrationsToRun = Object.keys(migrations).filter( (migration: keyof Migrations) => !plugin.settings.migrations[migration] @@ -43,23 +24,6 @@ async function migrate(plugin: QuickAdd): Promise { return; } - try { - await makeBackupFolderIfNotExists(); - - const backup = structuredClone(plugin.settings); - - await app.vault.create( - getBackupPath("preMigrationBackup"), - JSON.stringify(backup) - ); - } catch (error) { - log.logError( - `Unable to create backup before migrating to new version. Please create an issue with the following error message: \n\n${error}\n\nYour data is still safe! QuickAdd won't proceed without backup.` - ); - - return; - } - // Could batch-run with Promise.all, but we want to log each migration as it runs. for (const migration of migrationsToRun as (keyof Migrations)[]) { log.logMessage( @@ -76,7 +40,7 @@ async function migrate(plugin: QuickAdd): Promise { log.logMessage(`Migration ${migration} successful.`); } catch (error) { log.logError( - `Migration '${migration}' was unsuccessful. Please create an issue with the following error message: \n\n${error}\n\nQuickAdd will now revert to backup. You can also find a backup in the QuickAdd backup folder: "${backupFolderPath}"` + `Migration '${migration}' was unsuccessful. Please create an issue with the following error message: \n\n${error}\n\nQuickAdd will now revert to backup.` ); plugin.settings = backup;