mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 01:09:54 +08:00
feat: update migration test page (#2871)
This commit is contained in:
@@ -4,14 +4,17 @@ import type {
|
|||||||
LocalWorkspace,
|
LocalWorkspace,
|
||||||
} from '@affine/env/workspace';
|
} from '@affine/env/workspace';
|
||||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||||
|
import type { RootWorkspaceMetadataV1 } from '@affine/workspace/atom';
|
||||||
|
import { rootWorkspacesMetadataAtom } from '@affine/workspace/atom';
|
||||||
import {
|
import {
|
||||||
migrateLocalBlobStorage,
|
migrateLocalBlobStorage,
|
||||||
upgradeV1ToV2,
|
upgradeV1ToV2,
|
||||||
} from '@affine/workspace/migration';
|
} from '@affine/workspace/migration';
|
||||||
import { createIndexedDBDownloadProvider } from '@affine/workspace/providers';
|
import { createIndexedDBDownloadProvider } from '@affine/workspace/providers';
|
||||||
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
|
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
|
||||||
import { Workspace } from '@blocksuite/store';
|
import { assertExists, Workspace } from '@blocksuite/store';
|
||||||
import { NoSsr } from '@mui/material';
|
import { NoSsr } from '@mui/material';
|
||||||
|
import { rootStore } from '@toeverything/plugin-infra/manager';
|
||||||
import {
|
import {
|
||||||
atom,
|
atom,
|
||||||
createStore,
|
createStore,
|
||||||
@@ -20,6 +23,7 @@ import {
|
|||||||
useAtomValue,
|
useAtomValue,
|
||||||
useSetAtom,
|
useSetAtom,
|
||||||
} from 'jotai';
|
} from 'jotai';
|
||||||
|
import { useRouter } from 'next/router';
|
||||||
import type { ReactElement } from 'react';
|
import type { ReactElement } from 'react';
|
||||||
import { Suspense, use, useCallback } from 'react';
|
import { Suspense, use, useCallback } from 'react';
|
||||||
|
|
||||||
@@ -114,6 +118,25 @@ const WorkspaceInner = () => {
|
|||||||
const MigrationInner = () => {
|
const MigrationInner = () => {
|
||||||
const ids = useAtomValue(workspaceIdsAtom);
|
const ids = useAtomValue(workspaceIdsAtom);
|
||||||
const [id, setId] = useAtom(targetIdAtom);
|
const [id, setId] = useAtom(targetIdAtom);
|
||||||
|
const router = useRouter();
|
||||||
|
const onWriteIntoProduction = useCallback(() => {
|
||||||
|
assertExists(id);
|
||||||
|
const metadata: RootWorkspaceMetadataV1 = {
|
||||||
|
id,
|
||||||
|
flavour: WorkspaceFlavour.LOCAL,
|
||||||
|
version: undefined,
|
||||||
|
};
|
||||||
|
rootStore.set(rootWorkspacesMetadataAtom, [metadata]);
|
||||||
|
router.push('/').catch(console.error);
|
||||||
|
}, [id, router]);
|
||||||
|
const writeIntoProductionNode = id && (
|
||||||
|
<button
|
||||||
|
data-test-id="write into production"
|
||||||
|
onClick={onWriteIntoProduction}
|
||||||
|
>
|
||||||
|
write into production
|
||||||
|
</button>
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
@@ -133,6 +156,7 @@ const MigrationInner = () => {
|
|||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
{writeIntoProductionNode}
|
||||||
<Suspense fallback="loading...">{id && <WorkspaceInner />}</Suspense>
|
<Suspense fallback="loading...">{id && <WorkspaceInner />}</Suspense>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
downloadBinary,
|
downloadBinary,
|
||||||
getMilestones,
|
getMilestones,
|
||||||
markMilestone,
|
markMilestone,
|
||||||
|
overwriteBinary,
|
||||||
revertUpdate,
|
revertUpdate,
|
||||||
setMergeCount,
|
setMergeCount,
|
||||||
} from '../index';
|
} from '../index';
|
||||||
@@ -488,4 +489,17 @@ describe('utils', () => {
|
|||||||
}, 0)
|
}, 0)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('overwrite binary', async () => {
|
||||||
|
await overwriteBinary('test', new Uint8Array([1, 2, 3]));
|
||||||
|
{
|
||||||
|
const binary = await downloadBinary('test');
|
||||||
|
expect(binary).toEqual(new Uint8Array([1, 2, 3]));
|
||||||
|
}
|
||||||
|
await overwriteBinary('test', new Uint8Array([0, 0]));
|
||||||
|
{
|
||||||
|
const binary = await downloadBinary('test');
|
||||||
|
expect(binary).toEqual(new Uint8Array([0, 0]));
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -143,3 +143,24 @@ export async function downloadBinary(
|
|||||||
return mergeUpdates(doc.updates.map(({ update }) => update));
|
return mergeUpdates(doc.updates.map(({ update }) => update));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function overwriteBinary(
|
||||||
|
guid: string,
|
||||||
|
update: UpdateMessage['update'],
|
||||||
|
dbName = DEFAULT_DB_NAME
|
||||||
|
) {
|
||||||
|
const dbPromise = openDB<BlockSuiteBinaryDB>(dbName, dbVersion, {
|
||||||
|
upgrade: upgradeDB,
|
||||||
|
});
|
||||||
|
const db = await dbPromise;
|
||||||
|
const t = db.transaction('workspace', 'readwrite').objectStore('workspace');
|
||||||
|
await t.put({
|
||||||
|
id: guid,
|
||||||
|
updates: [
|
||||||
|
{
|
||||||
|
timestamp: Date.now(),
|
||||||
|
update,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user