CI / go (Server) (push) Failing after 22m50s
CI / go (Web-App) (push) Canceled after 0s
CI / frontend (push) Failing after 8m47s
CI / desktop (ubuntu-latest) (push) Successful in 2h56m50s
CI / mobile (push) Failing after 5m33s
CI / docker (push) Successful in 1h43m8s
Docs / build (push) Successful in 16m2s
Docs / deploy (push) Skipped
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
docwell-db no longer needs a Docwell image: the stack runs tajniak81/pocketbase-docker-root as it is, and docwell-server does what the migrations and pb_hooks used to do inside PocketBase. On start, docwell-server now: - waits for PocketBase and imports Docwell's collections from an embedded snapshot (internal/pbschema). Existing collections and fields are matched by name, so their data is kept; the admin-managed users options (OAuth2 providers, magic link) are left untouched. - writes the DOCWELL_APP_NAME, DOCWELL_WEB_URL, DOCWELL_MAIL_FROM, DOCWELL_SMTP_* and DOCWELL_S3_* settings into PocketBase, as the boot hook did. It also replaces the hook's two routes: token checks use PocketBase's auth-refresh (the organization name is read as the superuser), and Docwell's own emails go out over SMTP from the server. PocketBase never returns the SMTP password, so the server keeps a copy in the superuser-only instance_settings collection; a password saved before this change has to be entered once more in the admin panel. Database/ keeps pb_migrations as the source of the schema; export-schema.sh regenerates the snapshot from them. Database/Dockerfile and pb_hooks are removed, the release no longer builds docwell-db, the AIO image runs PocketBase without migrations or hooks, and the compose files default DB_IMAGE to the stock image and pass the settings to the server instead of the database. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
194 lines
8.2 KiB
JavaScript
194 lines
8.2 KiB
JavaScript
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
/// <reference path="../pb_data/types.d.ts" />
|
|
|
|
// Initial Docwell schema. All record API rules stay null (superuser only): PocketBase
|
|
// is a private service and docwell-server is the only client allowed to use it.
|
|
|
|
const timestamps = () => [
|
|
{ name: "created", type: "autodate", onCreate: true, onUpdate: false },
|
|
{ name: "updated", type: "autodate", onCreate: true, onUpdate: true },
|
|
];
|
|
|
|
const relation = (name, collection, opts = {}) => ({
|
|
name,
|
|
type: "relation",
|
|
collectionId: collection.id,
|
|
maxSelect: 1,
|
|
cascadeDelete: false,
|
|
...opts,
|
|
});
|
|
|
|
migrate(
|
|
(app) => {
|
|
// Authentication uses PocketBase's built-in "users" auth collection
|
|
// (passwords, tokens, verification, password reset, OTP, MFA, OAuth2).
|
|
// docwell-server forwards the auth calls; signup goes through the server
|
|
// with the superuser token, so the record API rules stay closed.
|
|
const users = app.findCollectionByNameOrId("users");
|
|
users.listRule = null;
|
|
users.viewRule = null;
|
|
users.createRule = null;
|
|
users.updateRule = null;
|
|
users.deleteRule = null;
|
|
// Disabled accounts cannot sign in with any method.
|
|
users.authRule = "status != 'disabled'";
|
|
users.passwordAuth.enabled = true;
|
|
users.passwordAuth.identityFields = ["email"];
|
|
|
|
users.fields.add(new SelectField({ name: "status", values: ["active", "invited", "disabled"], maxSelect: 1 }));
|
|
users.fields.add(new BoolField({ name: "is_admin" }));
|
|
users.fields.add(new TextField({ name: "locale", max: 16 }));
|
|
users.fields.add(new SelectField({ name: "theme", values: ["system", "light", "dark"], maxSelect: 1 }));
|
|
users.fields.add(new DateField({ name: "last_seen" }));
|
|
|
|
// Email links open docwell-web pages ({APP_URL} = DOCWELL_WEB_URL, set by
|
|
// docwell-server on start), never the private PocketBase dashboard.
|
|
users.verificationTemplate.subject = "Verify your {APP_NAME} email";
|
|
users.verificationTemplate.body =
|
|
"<p>Hello,</p><p>Confirm your email address for {APP_NAME}:</p>" +
|
|
'<p><a href="{APP_URL}/verify-email?token={TOKEN}">Verify email</a></p>' +
|
|
"<p>If you did not create an account, you can ignore this email.</p>";
|
|
users.resetPasswordTemplate.subject = "Reset your {APP_NAME} password";
|
|
users.resetPasswordTemplate.body =
|
|
"<p>Hello,</p><p>Someone asked to reset the password of your {APP_NAME} account:</p>" +
|
|
'<p><a href="{APP_URL}/reset-password?token={TOKEN}">Choose a new password</a></p>' +
|
|
"<p>If it was not you, you can ignore this email.</p>";
|
|
users.confirmEmailChangeTemplate.body =
|
|
"<p>Hello,</p><p>Confirm your new email address for {APP_NAME}:</p>" +
|
|
'<p><a href="{APP_URL}/confirm-email-change?token={TOKEN}">Confirm new email</a></p>';
|
|
app.save(users);
|
|
|
|
const workspaces = new Collection({
|
|
type: "base",
|
|
name: "workspaces",
|
|
fields: [
|
|
{ name: "name", type: "text", required: true, max: 120 },
|
|
{ name: "slug", type: "text", required: true, max: 64, pattern: "^[a-z0-9-]+$" },
|
|
{ name: "logo", type: "file", maxSelect: 1, maxSize: 2097152 },
|
|
{ name: "settings", type: "json" },
|
|
...timestamps(),
|
|
],
|
|
indexes: ["CREATE UNIQUE INDEX idx_workspaces_slug ON workspaces (slug)"],
|
|
});
|
|
app.save(workspaces);
|
|
|
|
const workspaceMembers = new Collection({
|
|
type: "base",
|
|
name: "workspace_members",
|
|
fields: [
|
|
relation("workspace", workspaces, { required: true, cascadeDelete: true }),
|
|
relation("user", users, { required: true, cascadeDelete: true }),
|
|
{ name: "role", type: "select", values: ["owner", "admin", "member", "guest"], maxSelect: 1, required: true },
|
|
...timestamps(),
|
|
],
|
|
indexes: ["CREATE UNIQUE INDEX idx_wsm_unique ON workspace_members (workspace, user)"],
|
|
});
|
|
app.save(workspaceMembers);
|
|
|
|
const spaces = new Collection({
|
|
type: "base",
|
|
name: "spaces",
|
|
fields: [
|
|
relation("workspace", workspaces, { required: true, cascadeDelete: true }),
|
|
{ name: "name", type: "text", required: true, max: 120 },
|
|
{ name: "slug", type: "text", required: true, max: 64, pattern: "^[a-z0-9-]+$" },
|
|
{ name: "icon", type: "text", max: 32 },
|
|
{ name: "description", type: "text", max: 1000 },
|
|
{ name: "visibility", type: "select", values: ["open", "private"], maxSelect: 1, required: true },
|
|
{ name: "default_role", type: "select", values: ["editor", "commenter", "viewer"], maxSelect: 1 },
|
|
...timestamps(),
|
|
],
|
|
indexes: ["CREATE UNIQUE INDEX idx_spaces_slug ON spaces (workspace, slug)"],
|
|
});
|
|
app.save(spaces);
|
|
|
|
const spaceMembers = new Collection({
|
|
type: "base",
|
|
name: "space_members",
|
|
fields: [
|
|
relation("space", spaces, { required: true, cascadeDelete: true }),
|
|
{ name: "principal_type", type: "select", values: ["user", "group"], maxSelect: 1, required: true },
|
|
{ name: "principal_id", type: "text", required: true },
|
|
{ name: "role", type: "select", values: ["admin", "editor", "commenter", "viewer"], maxSelect: 1, required: true },
|
|
...timestamps(),
|
|
],
|
|
indexes: ["CREATE UNIQUE INDEX idx_spm_unique ON space_members (space, principal_type, principal_id)"],
|
|
});
|
|
app.save(spaceMembers);
|
|
|
|
const pages = new Collection({
|
|
type: "base",
|
|
name: "pages",
|
|
fields: [
|
|
relation("workspace", workspaces, { required: true, cascadeDelete: true }),
|
|
relation("space", spaces, { required: true, cascadeDelete: true }),
|
|
{ name: "title", type: "text", max: 500 },
|
|
{ name: "icon", type: "text", max: 32 },
|
|
{ name: "cover", type: "file", maxSelect: 1, maxSize: 10485760 },
|
|
// Fractional index string for ordering siblings without renumbering.
|
|
{ name: "position", type: "text", required: true, max: 128 },
|
|
relation("creator", users),
|
|
relation("last_editor", users),
|
|
{ name: "content_json", type: "json", maxSize: 20971520 },
|
|
{ name: "content_text", type: "text", max: 0 },
|
|
{ name: "word_count", type: "number", onlyInt: true, min: 0 },
|
|
{ name: "is_template", type: "bool" },
|
|
{ name: "archived_at", type: "date" },
|
|
{ name: "deleted_at", type: "date" },
|
|
...timestamps(),
|
|
],
|
|
indexes: ["CREATE INDEX idx_pages_workspace ON pages (workspace, updated)"],
|
|
});
|
|
app.save(pages);
|
|
|
|
// Self-relation needs the collection id, so it is added after the first save.
|
|
pages.fields.add(new RelationField({ name: "parent", collectionId: pages.id, maxSelect: 1, cascadeDelete: true }));
|
|
pages.indexes = [
|
|
"CREATE INDEX idx_pages_workspace ON pages (workspace, updated)",
|
|
"CREATE INDEX idx_pages_tree ON pages (space, parent, position)",
|
|
];
|
|
app.save(pages);
|
|
|
|
const pageYdoc = new Collection({
|
|
type: "base",
|
|
name: "page_ydoc",
|
|
fields: [
|
|
relation("page", pages, { required: true, cascadeDelete: true }),
|
|
{ name: "state", type: "file", maxSelect: 1, maxSize: 52428800, protected: true },
|
|
{ name: "state_vector", type: "text", max: 0 },
|
|
...timestamps(),
|
|
],
|
|
indexes: ["CREATE UNIQUE INDEX idx_page_ydoc_page ON page_ydoc (page)"],
|
|
});
|
|
app.save(pageYdoc);
|
|
|
|
const pageYupdates = new Collection({
|
|
type: "base",
|
|
name: "page_yupdates",
|
|
fields: [
|
|
relation("page", pages, { required: true, cascadeDelete: true }),
|
|
// Base64-encoded Yjs update; compacted into page_ydoc and pruned.
|
|
{ name: "update", type: "text", required: true, max: 0 },
|
|
{ name: "client_id", type: "text", max: 32 },
|
|
...timestamps(),
|
|
],
|
|
indexes: ["CREATE INDEX idx_page_yupdates_page ON page_yupdates (page, created)"],
|
|
});
|
|
app.save(pageYupdates);
|
|
},
|
|
(app) => {
|
|
for (const name of ["page_yupdates", "page_ydoc", "pages", "space_members", "spaces", "workspace_members", "workspaces"]) {
|
|
try {
|
|
app.delete(app.findCollectionByNameOrId(name));
|
|
} catch (_) {}
|
|
}
|
|
const users = app.findCollectionByNameOrId("users");
|
|
for (const name of ["status", "is_admin", "locale", "theme", "last_seen"]) {
|
|
users.fields.removeByName(name);
|
|
}
|
|
users.authRule = "";
|
|
app.save(users);
|
|
},
|
|
);
|