kanban-dev-webapp/pocketbase/pb_migrations/1789600100_created_clients.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

56 lines
No EOL
1.4 KiB
JavaScript

/// <reference path="../pb_data/types.d.ts" />
/**
* `clients` — the companies the developer works for.
*
* A client owns projects. Client-manager users are scoped to exactly one
* client, and that scoping is what stops one customer seeing another's work.
*/
migrate(
(app) => {
const collection = new Collection({
name: "clients",
type: "base",
listRule: "@request.auth.id != ''",
viewRule: "@request.auth.id != ''",
createRule: null,
updateRule: null,
deleteRule: null,
fields: [
{
name: "name",
type: "text",
required: true,
max: 120,
presentable: true,
},
{
name: "slug",
type: "text",
required: true,
max: 60,
pattern: "^[a-z0-9-]+$",
},
{ name: "brand_color", type: "text", required: false, max: 7 },
{ name: "active", type: "bool", required: false },
{
name: "created",
type: "autodate",
onCreate: true,
onUpdate: false,
},
{
name: "updated",
type: "autodate",
onCreate: true,
onUpdate: true,
},
],
indexes: ["CREATE UNIQUE INDEX idx_clients_slug ON clients (slug)"],
});
return app.save(collection);
},
(app) => {
return app.delete(app.findCollectionByNameOrId("clients"));
}
);