mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-12 07:36:42 +08:00
feat: update migration test page (#2871)
This commit is contained in:
@@ -4,14 +4,17 @@ import type {
|
||||
LocalWorkspace,
|
||||
} from '@affine/env/workspace';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import type { RootWorkspaceMetadataV1 } from '@affine/workspace/atom';
|
||||
import { rootWorkspacesMetadataAtom } from '@affine/workspace/atom';
|
||||
import {
|
||||
migrateLocalBlobStorage,
|
||||
upgradeV1ToV2,
|
||||
} from '@affine/workspace/migration';
|
||||
import { createIndexedDBDownloadProvider } from '@affine/workspace/providers';
|
||||
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
|
||||
import { Workspace } from '@blocksuite/store';
|
||||
import { assertExists, Workspace } from '@blocksuite/store';
|
||||
import { NoSsr } from '@mui/material';
|
||||
import { rootStore } from '@toeverything/plugin-infra/manager';
|
||||
import {
|
||||
atom,
|
||||
createStore,
|
||||
@@ -20,6 +23,7 @@ import {
|
||||
useAtomValue,
|
||||
useSetAtom,
|
||||
} from 'jotai';
|
||||
import { useRouter } from 'next/router';
|
||||
import type { ReactElement } from 'react';
|
||||
import { Suspense, use, useCallback } from 'react';
|
||||
|
||||
@@ -114,6 +118,25 @@ const WorkspaceInner = () => {
|
||||
const MigrationInner = () => {
|
||||
const ids = useAtomValue(workspaceIdsAtom);
|
||||
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 (
|
||||
<div
|
||||
style={{
|
||||
@@ -133,6 +156,7 @@ const MigrationInner = () => {
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{writeIntoProductionNode}
|
||||
<Suspense fallback="loading...">{id && <WorkspaceInner />}</Suspense>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
downloadBinary,
|
||||
getMilestones,
|
||||
markMilestone,
|
||||
overwriteBinary,
|
||||
revertUpdate,
|
||||
setMergeCount,
|
||||
} from '../index';
|
||||
@@ -488,4 +489,17 @@ describe('utils', () => {
|
||||
}, 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));
|
||||
}
|
||||
}
|
||||
|
||||
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