From cbb2bdf80c6398be336f32e6588f62132f85b303 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 17 Oct 2022 14:20:54 -0400 Subject: [PATCH] Update text column with CRDT backfill --- server/scripts/20221008000000-backfill-crdt.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/server/scripts/20221008000000-backfill-crdt.ts b/server/scripts/20221008000000-backfill-crdt.ts index ee0f95d4c..f76f5eff3 100644 --- a/server/scripts/20221008000000-backfill-crdt.ts +++ b/server/scripts/20221008000000-backfill-crdt.ts @@ -1,7 +1,11 @@ import "./bootstrap"; -import { updateYFragment } from "@getoutline/y-prosemirror"; +import { + updateYFragment, + yDocToProsemirrorJSON, +} from "@getoutline/y-prosemirror"; +import { Node } from "prosemirror-model"; import * as Y from "yjs"; -import { parser } from "@server/editor"; +import { parser, schema, serializer } from "@server/editor"; import { Document } from "@server/models"; const limit = 100; @@ -52,6 +56,13 @@ export default async function main(exit = false) { const state = Y.encodeStateAsUpdate(ydoc); document.state = Buffer.from(state); + const node = Node.fromJSON( + schema, + yDocToProsemirrorJSON(ydoc, "default") + ); + const text = serializer.serialize(node, undefined); + document.text = text; + await document.save({ hooks: false, silent: true,