db migration

This commit is contained in:
fyears 2024-02-25 23:21:42 +08:00
parent 5f5b5de505
commit 768d6636d0
8 changed files with 54 additions and 43 deletions

View File

@ -1,7 +1,7 @@
{
"id": "remotely-save",
"name": "Remotely Save",
"version": "0.3.40",
"version": "0.4.1",
"minAppVersion": "0.13.21",
"description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.",
"author": "fyears",

View File

@ -1,7 +1,7 @@
{
"id": "remotely-save",
"name": "Remotely Save",
"version": "0.3.40",
"version": "0.4.1",
"minAppVersion": "0.13.21",
"description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.",
"author": "fyears",

View File

@ -1,6 +1,6 @@
{
"name": "remotely-save",
"version": "0.3.40",
"version": "0.4.1",
"description": "This is yet another sync plugin for Obsidian app.",
"scripts": {
"dev2": "node esbuild.config.mjs --watch",

View File

@ -281,10 +281,10 @@
"settings_logtohttpserver": "Log To HTTP(S) Server Temporarily",
"settings_logtohttpserver_desc": "It's very dangerous and please use the function with greate cautions!!!!! It will temporarily allow sending console loggings to HTTP(S) server.",
"settings_logtohttpserver_reset_notice": "Your input doesn't starts with \"http(s)\". Already removed the setting of logging to HTTP(S) server.",
"settings_delsyncmap": "Delete Sync Mappings History In DB",
"settings_delsyncmap_desc": "Sync mappings history stores the actual LOCAL last modified time of the REMOTE objects. Clearing it may cause unnecessary data exchanges in next-time sync. Click the button to delete sync mappings history in DB.",
"settings_delsyncmap_button": "Delete Sync Mappings",
"settings_delsyncmap_notice": "Sync mappings history (in local DB) deleted",
"settings_delprevsync": "Delete Prev Sync Details In DB",
"settings_delprevsync_desc": "The sync algorithm keeps the previous successful sync information in DB to determine the file changes. If you want to ignore them so that all files are treated newly created, you can delete the prev sync info here.",
"settings_delprevsync_button": "Delete Prev Sync Details",
"settings_delprevsync_notice": "Previous sync history (in local DB) deleted",
"settings_outputbasepathvaultid": "Output Vault Base Path And Randomly Assigned ID",
"settings_outputbasepathvaultid_desc": "For debugging purposes.",
"settings_outputbasepathvaultid_button": "Output",

View File

@ -281,10 +281,10 @@
"settings_logtohttpserver": "临时设定终端日志实时转发到 HTTP(S) 服务器。",
"settings_logtohttpserver_desc": "非常危险,谨慎行动!!!!!临时设定终端日志实时转发到 HTTP(S) 服务器。",
"settings_logtohttpserver_reset_notice": "您的输入不是“http(s)”开头的。已移除了终端日志转发到 HTTP(S) 服务器的设定。",
"settings_delsyncmap": "删除数据库里的同步映射历史",
"settings_delsyncmap_desc": "同步映射历史存储了本地真正的最后修改时间和远程文件时间的映射。删除之可能会导致下一次同步时发生不必要的数据交换。点击按钮删除数据库里的同步映射历史。",
"settings_delsyncmap_button": "删除同步映射历史",
"settings_delsyncmap_notice": "(本地数据库里的)同步映射历史已被删除。",
"settings_delprevsync": "删除数据库里的上次同步明细",
"settings_delprevsync_desc": "同步算法需要上次成功同步的信息来决定文件变更,这个信息保存在本地的数据库里。如果您想忽略这些信息从而所有文件都被视为新创建的话,可以在此删除之前的信息。",
"settings_delprevsync_button": "删除上次同步明细",
"settings_delprevsync_notice": "(本地数据库里的)上次同步明细已被删除。",
"settings_outputbasepathvaultid": "输出资料库对应的位置和随机分配的 ID",
"settings_outputbasepathvaultid_desc": "用于调试。",
"settings_outputbasepathvaultid_button": "输出",

View File

@ -281,10 +281,10 @@
"settings_logtohttpserver": "臨時設定終端日誌實時轉發到 HTTP(S) 伺服器。",
"settings_logtohttpserver_desc": "非常危險,謹慎行動!!!!!臨時設定終端日誌實時轉發到 HTTP(S) 伺服器。",
"settings_logtohttpserver_reset_notice": "您的輸入不是“http(s)”開頭的。已移除了終端日誌轉發到 HTTP(S) 伺服器的設定。",
"settings_delsyncmap": "刪除資料庫裡的同步對映歷史",
"settings_delsyncmap_desc": "同步對映歷史儲存了本地真正的最後修改時間和遠端檔案時間的對映。刪除之可能會導致下一次同步時發生不必要的資料交換。點選按鈕刪除資料庫裡的同步對映歷史。",
"settings_delsyncmap_button": "刪除同步對映歷史",
"settings_delsyncmap_notice": "(本地資料庫裡的)同步對映歷史已被刪除。",
"settings_delprevsync": "刪除資料庫裡的上次同步明細",
"settings_delprevsync_desc": "同步演算法需要上次成功同步的資訊來決定檔案變更,這個資訊儲存在本地的資料庫裡。如果您想忽略這些資訊從而所有檔案都被視為新建立的話,可以在此刪除之前的資訊。",
"settings_delprevsync_button": "刪除上次同步明細",
"settings_delprevsync_notice": "(本地資料庫裡的)上次同步明細已被刪除。",
"settings_outputbasepathvaultid": "輸出資料庫對應的位置和隨機分配的 ID",
"settings_outputbasepathvaultid_desc": "用於除錯。",
"settings_outputbasepathvaultid_button": "輸出",

View File

@ -80,22 +80,32 @@ export interface InternalDBs {
* @returns
*/
const fromSyncMappingsToPrevSyncRecords = (
syncMappings: SyncMetaMappingRecord[]
oldSyncMappings: SyncMetaMappingRecord[]
): Entity[] => {
return [];
const res: Entity[] = [];
for (const oldMapping of oldSyncMappings) {
const newEntity: Entity = {
key: oldMapping.localKey,
keyEnc: oldMapping.remoteKey,
keyRaw:
oldMapping.remoteKey !== undefined && oldMapping.remoteKey !== ""
? oldMapping.remoteKey
: oldMapping.localKey,
mtimeCli: oldMapping.localMtime,
mtimeSvr: oldMapping.remoteMtime,
size: oldMapping.localSize,
sizeEnc: oldMapping.remoteSize,
sizeRaw:
oldMapping.remoteKey !== undefined && oldMapping.remoteKey !== ""
? oldMapping.remoteSize
: oldMapping.localSize,
etag: oldMapping.remoteExtraKey,
};
/**
* TODO
* @param db
* @param vaultRandomID
* @param prevSyncRecord
*/
const setPrevSyncRecordByVault = async (
db: InternalDBs,
vaultRandomID: string,
prevSyncRecord: Entity
) => {};
res.push(newEntity);
}
return res;
};
/**
*
@ -115,12 +125,14 @@ const migrateDBsFrom20220326To20240220 = async (
const syncMappings = await getAllSyncMetaMappingByVault(db, vaultRandomID);
const prevSyncRecords = fromSyncMappingsToPrevSyncRecords(syncMappings);
for (const prevSyncRecord of prevSyncRecords) {
await setPrevSyncRecordByVault(db, vaultRandomID, prevSyncRecord);
await upsertPrevSyncRecordByVault(db, vaultRandomID, prevSyncRecord);
}
// clear not used data
await clearFileHistoryOfEverythingByVault(db, vaultRandomID);
await clearAllSyncMetaMappingByVault(db, vaultRandomID);
// // clear not used data
// // as of 20240220, we don't call them,
// // for the opportunity for users to downgrade
// await clearFileHistoryOfEverythingByVault(db, vaultRandomID);
// await clearAllSyncMetaMappingByVault(db, vaultRandomID);
await db.versionTbl.setItem(`${vaultRandomID}\tversion`, newVer);
log.debug(`finish upgrading internal db from ${oldVer} to ${newVer}`);
@ -322,10 +334,6 @@ export const clearAllSyncMetaMappingByVault = async (
}
};
export const clearAllSyncMetaMapping = async (db: InternalDBs) => {
await db.syncMappingTbl.clear();
};
export const insertSyncPlanRecordByVault = async (
db: InternalDBs,
syncPlan: SyncPlanType,

View File

@ -25,7 +25,7 @@ import {
import { exportVaultSyncPlansToFiles } from "./debugMode";
import { exportQrCodeUri } from "./importExport";
import {
clearAllSyncMetaMapping,
clearAllPrevSyncRecordByVault,
clearAllSyncPlanRecords,
destroyDBs,
upsertLastSuccessSyncTimeByVault,
@ -2166,13 +2166,16 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
});
new Setting(debugDiv)
.setName(t("settings_delsyncmap"))
.setDesc(t("settings_delsyncmap_desc"))
.setName(t("settings_delprevsync"))
.setDesc(t("settings_delprevsync_desc"))
.addButton(async (button) => {
button.setButtonText(t("settings_delsyncmap_button"));
button.setButtonText(t("settings_delprevsync_button"));
button.onClick(async () => {
await clearAllSyncMetaMapping(this.plugin.db);
new Notice(t("settings_delsyncmap_notice"));
await clearAllPrevSyncRecordByVault(
this.plugin.db,
this.plugin.vaultRandomID
);
new Notice(t("settings_delprevsync_notice"));
});
});