mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
fix: only run migration in local workspace (#3570)
This commit is contained in:
@@ -36,15 +36,15 @@ async function tryMigration() {
|
|||||||
const adapter = WorkspaceAdapters[oldMeta.flavour];
|
const adapter = WorkspaceAdapters[oldMeta.flavour];
|
||||||
assertExists(adapter);
|
assertExists(adapter);
|
||||||
const upgrade = async () => {
|
const upgrade = async () => {
|
||||||
|
if (oldMeta.flavour !== WorkspaceFlavour.LOCAL) {
|
||||||
|
console.warn('not supported');
|
||||||
|
return;
|
||||||
|
}
|
||||||
const workspace = await adapter.CRUD.get(oldMeta.id);
|
const workspace = await adapter.CRUD.get(oldMeta.id);
|
||||||
if (!workspace) {
|
if (!workspace) {
|
||||||
console.warn('cannot find workspace', oldMeta.id);
|
console.warn('cannot find workspace', oldMeta.id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (workspace.flavour !== WorkspaceFlavour.LOCAL) {
|
|
||||||
console.warn('not supported');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const doc = workspace.blockSuiteWorkspace.doc;
|
const doc = workspace.blockSuiteWorkspace.doc;
|
||||||
const provider = createIndexedDBDownloadProvider(
|
const provider = createIndexedDBDownloadProvider(
|
||||||
workspace.id,
|
workspace.id,
|
||||||
@@ -83,11 +83,14 @@ async function tryMigration() {
|
|||||||
// create a new workspace and push it to metadata
|
// create a new workspace and push it to metadata
|
||||||
promises.push(upgrade());
|
promises.push(upgrade());
|
||||||
} else if (oldMeta.version < WorkspaceVersion.DatabaseV3) {
|
} else if (oldMeta.version < WorkspaceVersion.DatabaseV3) {
|
||||||
console.log('migrate to v3');
|
|
||||||
const adapter = WorkspaceAdapters[oldMeta.flavour];
|
const adapter = WorkspaceAdapters[oldMeta.flavour];
|
||||||
assertExists(adapter);
|
assertExists(adapter);
|
||||||
promises.push(
|
promises.push(
|
||||||
(async () => {
|
(async () => {
|
||||||
|
if (oldMeta.flavour !== WorkspaceFlavour.LOCAL) {
|
||||||
|
console.warn('not supported');
|
||||||
|
return;
|
||||||
|
}
|
||||||
const workspace = await adapter.CRUD.get(oldMeta.id);
|
const workspace = await adapter.CRUD.get(oldMeta.id);
|
||||||
if (workspace) {
|
if (workspace) {
|
||||||
const provider = createIndexedDBDownloadProvider(
|
const provider = createIndexedDBDownloadProvider(
|
||||||
@@ -107,11 +110,11 @@ async function tryMigration() {
|
|||||||
const index = newMetadata.findIndex(
|
const index = newMetadata.findIndex(
|
||||||
meta => meta.id === oldMeta.id
|
meta => meta.id === oldMeta.id
|
||||||
);
|
);
|
||||||
console.log('migrate to v3');
|
|
||||||
newMetadata[index] = {
|
newMetadata[index] = {
|
||||||
...oldMeta,
|
...oldMeta,
|
||||||
version: WorkspaceVersion.DatabaseV3,
|
version: WorkspaceVersion.DatabaseV3,
|
||||||
};
|
};
|
||||||
|
console.log('migrate to v3');
|
||||||
})()
|
})()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -121,8 +124,8 @@ async function tryMigration() {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('migration done');
|
console.log('migration done');
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(e => {
|
||||||
console.error('migration failed');
|
console.error('migration failed', e);
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
localStorage.setItem('jotai-workspaces', JSON.stringify(newMetadata));
|
localStorage.setItem('jotai-workspaces', JSON.stringify(newMetadata));
|
||||||
|
|||||||
Reference in New Issue
Block a user