// SPDX-License-Identifier: AGPL-3.0-or-later /// // Inline comments. A comment points at a range of the page's text through // anchor: Yjs relative positions (encoded by the editor), which follow the // text as people edit. Commenters cannot change the document, so the anchor // lives here instead of as a mark in the text. migrate( (app) => { const users = app.findCollectionByNameOrId("users"); const pages = app.findCollectionByNameOrId("pages"); const workspaces = app.findCollectionByNameOrId("workspaces"); app.save( new Collection({ type: "base", name: "comments", fields: [ { name: "page", type: "relation", collectionId: pages.id, maxSelect: 1, required: true, cascadeDelete: true }, { name: "workspace", type: "relation", collectionId: workspaces.id, maxSelect: 1, required: true, cascadeDelete: true }, { name: "author", type: "relation", collectionId: users.id, maxSelect: 1, cascadeDelete: false }, { name: "body", type: "text", required: true, max: 5000 }, // The commented text when the comment was written. { name: "quote", type: "text", max: 500 }, { name: "anchor", type: "json", maxSize: 4096 }, { name: "created", type: "autodate", onCreate: true, onUpdate: false }, { name: "updated", type: "autodate", onCreate: true, onUpdate: true }, ], indexes: ["CREATE INDEX idx_comments_page ON comments (page, created)"], }), ); }, (app) => { try { app.delete(app.findCollectionByNameOrId("comments")); } catch (_) {} }, );