kanban-dev-webapp/pocketbase/pb_migrations/1789600600_created_subtasks_comments.js
Dave ba990f0109 feat(schema): all collections + role-scoped API rules on remote PB
- migrations/ documented in pocketbase/pb_migrations/ for local PB
- scripts/setup-remote.ts applies them via admin API to remote PB
- collections: clients, projects, columns, cards, subtasks, comments, activity, settings
- user extension: role (owner|client_manager), client (relation)
- writes: owner only for app collections, superuser-only for activity and settings
2026-09-16 09:41:20 +02:00

82 lines
No EOL
2.5 KiB
JavaScript

/// <reference path="../pb_data/types.d.ts" />
/**
* `subtasks` and `comments`, both children of a card and both cascade-deleted
* with it.
*
* Comment bodies are markdown authored by a client. They are rendered without
* raw HTML — see Plan 1b. Never render a comment body with
* dangerouslySetInnerHTML.
*/
migrate(
(app) => {
const cards = app.findCollectionByNameOrId("cards");
const users = app.findCollectionByNameOrId("users");
const subtasks = new Collection({
name: "subtasks",
type: "base",
listRule: "@request.auth.id != ''",
viewRule: "@request.auth.id != ''",
createRule: null,
updateRule: null,
deleteRule: null,
fields: [
{
name: "card",
type: "relation",
required: true,
collectionId: cards.id,
cascadeDelete: true,
minSelect: 0,
maxSelect: 1,
},
{ name: "title", type: "text", required: true, max: 200, presentable: true },
{ name: "done", type: "bool", required: false },
{ name: "position", type: "number", required: true },
{ name: "created", type: "autodate", onCreate: true, onUpdate: false },
{ name: "updated", type: "autodate", onCreate: true, onUpdate: true },
],
indexes: ["CREATE INDEX idx_subtasks_card ON subtasks (card, position)"],
});
app.save(subtasks);
const comments = new Collection({
name: "comments",
type: "base",
listRule: "@request.auth.id != ''",
viewRule: "@request.auth.id != ''",
createRule: null,
updateRule: null,
deleteRule: null,
fields: [
{
name: "card",
type: "relation",
required: true,
collectionId: cards.id,
cascadeDelete: true,
minSelect: 0,
maxSelect: 1,
},
{
name: "author",
type: "relation",
required: true,
collectionId: users.id,
cascadeDelete: false,
minSelect: 0,
maxSelect: 1,
},
{ name: "body", type: "text", required: true, max: 20000 },
{ name: "created", type: "autodate", onCreate: true, onUpdate: false },
{ name: "updated", type: "autodate", onCreate: true, onUpdate: true },
],
indexes: ["CREATE INDEX idx_comments_card ON comments (card, created)"],
});
return app.save(comments);
},
(app) => {
app.delete(app.findCollectionByNameOrId("comments"));
return app.delete(app.findCollectionByNameOrId("subtasks"));
}
);