There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
feat: update migration test page (#2871)
Alex Yang7960b6a22e48
diff --git a/apps/web/src/pages/_debug/migration.tsx b/apps/web/src/pages/_debug/migration.tsxindex 3f1efe12f9..672dffe225 100644--- a/apps/web/src/pages/_debug/migration.tsx+++ b/apps/web/src/pages/_debug/migration.tsx@@ -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 (<divstyle={{@@ -133,6 +156,7 @@ const MigrationInner = () => {</li>))}</ul>+ {writeIntoProductionNode}<Suspense fallback="loading...">{id && <WorkspaceInner />}</Suspense></div>);diff --git a/packages/y-indexeddb/src/__tests__/index.spec.ts b/packages/y-indexeddb/src/__tests__/index.spec.tsindex f056529863..f77445c482 100644--- a/packages/y-indexeddb/src/__tests__/index.spec.ts+++ b/packages/y-indexeddb/src/__tests__/index.spec.ts@@ -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]));+ }+ });});diff --git a/packages/y-indexeddb/src/utils.ts b/packages/y-indexeddb/src/utils.tsindex 516885adb2..9258975145 100644--- a/packages/y-indexeddb/src/utils.ts+++ b/packages/y-indexeddb/src/utils.ts@@ -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,+ },+ ],+ });+}