Files
Docwell/Database/pb_migrations/1763700000_properties.js
T
tajniak81andClaude Opus 5.5 ec11abd8b8 Add page properties, tags, All docs, collections and journals
Phase B (items 1-6) of docs/AFFINE.md.

Properties: workspaces define custom page properties (text, number,
checkbox, date, select, multi-select, person, link) in the new
workspace_properties collection; pages keep their values in
pages.properties, checked against each property's type. The Info panel
under the title shows tags, custom and built-in properties, following
each property's visibility; the Info side panel shows them all, with the
page's collections and the journal. Settings gains Page properties and
Tags sections.

Tags: coloured, per workspace (tags collection, pages.tags); create from
the picker, rename, recolour, merge and delete. Search filters by tag.

All docs: GET /workspaces/{id}/docs lists the pages the caller can open
with their properties, narrowed by space, tag, collection or filter
rules evaluated on the server. The view shows a list, grid or cards,
groups and orders by any property, picks the properties shown, and acts
on several pages at once (tag, move, trash, collect).

Collections (page_collections): saved rules plus pages added or taken
out by hand, private to their creator until shared with the workspace,
listed in the sidebar.

Journals: one page per person and day in a private journal space
(spaces.journal_owner) that workspace admins do not see into, made on
first use. A week strip marks days with pages, new days can start from
a template, and dates in read mode open that day's journal.

The migration and schema snapshot, OpenAPI spec and generated Go, TS and
Dart types are updated (the Dart generator learns untyped values), the
mobile editor bundle is rebuilt, the new strings are translated into all
five languages, and the user guide covers the new features.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 16:35:42 +01:00

112 lines
5.1 KiB
JavaScript

// SPDX-License-Identifier: AGPL-3.0-or-later
/// <reference path="../pb_data/types.d.ts" />
// Phase B of docs/AFFINE.md: page properties, tags, collections and journals.
//
// - workspace_properties: the custom properties every page of a workspace can
// fill in. pages.properties holds the values as { "<property id>": value }.
// - tags: coloured labels per workspace; pages.tags lists a page's tags.
// - page_collections: saved views of pages (rules plus pages added by hand),
// private to their creator or shared with the workspace.
// - Journals: one page per person and day. They live in the person's journal
// space (spaces.journal_owner); pages.journal_date is the day (YYYY-MM-DD)
// and spaces.journal_template the page new journals are filled from.
migrate(
(app) => {
const users = app.findCollectionByNameOrId("users");
const workspaces = app.findCollectionByNameOrId("workspaces");
const pages = app.findCollectionByNameOrId("pages");
const spaces = app.findCollectionByNameOrId("spaces");
app.save(
new Collection({
type: "base",
name: "workspace_properties",
fields: [
{ name: "workspace", type: "relation", collectionId: workspaces.id, maxSelect: 1, required: true, cascadeDelete: true },
{ name: "name", type: "text", required: true, max: 80 },
{
name: "type",
type: "select",
required: true,
maxSelect: 1,
values: ["text", "number", "checkbox", "date", "select", "multi_select", "member", "link"],
},
// Select and multi-select choices: [{ "id", "name", "color" }].
{ name: "options", type: "json", maxSize: 20000 },
{ name: "visibility", type: "select", maxSelect: 1, values: ["always", "hide_empty", "never"] },
{ name: "position", type: "number" },
{ name: "created", type: "autodate", onCreate: true, onUpdate: false },
{ name: "updated", type: "autodate", onCreate: true, onUpdate: true },
],
indexes: ["CREATE INDEX idx_workspace_properties_ws ON workspace_properties (workspace, position)"],
}),
);
const tags = new Collection({
type: "base",
name: "tags",
fields: [
{ name: "workspace", type: "relation", collectionId: workspaces.id, maxSelect: 1, required: true, cascadeDelete: true },
{ name: "name", type: "text", required: true, max: 60 },
{ name: "color", type: "text", max: 20 },
{ name: "created", type: "autodate", onCreate: true, onUpdate: false },
{ name: "updated", type: "autodate", onCreate: true, onUpdate: true },
],
indexes: ["CREATE UNIQUE INDEX idx_tags_name ON tags (workspace, name COLLATE NOCASE)"],
});
app.save(tags);
app.save(
new Collection({
type: "base",
name: "page_collections",
fields: [
{ name: "workspace", type: "relation", collectionId: workspaces.id, maxSelect: 1, required: true, cascadeDelete: true },
{ name: "creator", type: "relation", collectionId: users.id, maxSelect: 1, cascadeDelete: true },
{ name: "name", type: "text", required: true, max: 120 },
{ name: "icon", type: "text", max: 32 },
// { "match": "all" | "any", "rules": [{ "field", "op", "value" }] }
{ name: "filter", type: "json", maxSize: 20000 },
// Page ids added by hand, and page ids the rules match but were taken out.
{ name: "include", type: "json", maxSize: 50000 },
{ name: "exclude", type: "json", maxSize: 50000 },
{ name: "shared", type: "bool" },
{ name: "created", type: "autodate", onCreate: true, onUpdate: false },
{ name: "updated", type: "autodate", onCreate: true, onUpdate: true },
],
indexes: ["CREATE INDEX idx_page_collections_ws ON page_collections (workspace, creator)"],
}),
);
pages.fields.add(new JSONField({ name: "properties", maxSize: 100000 }));
pages.fields.add(new RelationField({ name: "tags", collectionId: tags.id, maxSelect: 100, cascadeDelete: false }));
pages.fields.add(new TextField({ name: "journal_date", max: 10 }));
pages.addIndex("idx_pages_journal", false, "space, journal_date", "");
app.save(pages);
spaces.fields.add(new RelationField({ name: "journal_owner", collectionId: users.id, maxSelect: 1, cascadeDelete: true }));
spaces.fields.add(new RelationField({ name: "journal_template", collectionId: pages.id, maxSelect: 1, cascadeDelete: false }));
app.save(spaces);
},
(app) => {
const spaces = app.findCollectionByNameOrId("spaces");
spaces.fields.removeByName("journal_owner");
spaces.fields.removeByName("journal_template");
app.save(spaces);
const pages = app.findCollectionByNameOrId("pages");
pages.removeIndex("idx_pages_journal");
pages.fields.removeByName("properties");
pages.fields.removeByName("tags");
pages.fields.removeByName("journal_date");
app.save(pages);
app.delete(app.findCollectionByNameOrId("page_collections"));
app.delete(app.findCollectionByNameOrId("tags"));
app.delete(app.findCollectionByNameOrId("workspace_properties"));
},
);