Files
PilotVault/API Server/pocketbase/pb_migrations/1720300300_add_users_organization.js
tajniak81andClaude Opus 4.8 afc6952eda Initial commit: PilotVault multi-service project
Add API Server (Go/PocketBase), Web App (Go BFF + Vue), Fly App
(Flutter/DJI MSDK), Adobe Plugin, and Docker/Docker AIO deployment
configs. Design assets and build artifacts are gitignored.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-13 11:43:33 +02:00

35 lines
1.0 KiB
JavaScript

/// <reference path="../pb_data/types.d.ts" />
// Adds an `organization` relation field to the `users` auth collection, pointing
// at the `organizations` collection. Not required (maxSelect 1), so users may be
// org-less. cascadeDelete is false: deleting an org does not delete its members.
//
// Depends on 1720300200_add_organizations.js. Idempotent: no-op if the field is
// already present. Written for PocketBase v0.22+/v0.23.
migrate(
(app) => {
const users = app.findCollectionByNameOrId('users')
if (users.fields.getByName('organization')) return
const orgs = app.findCollectionByNameOrId('organizations')
users.fields.add(
new Field({
name: 'organization',
type: 'relation',
required: false,
collectionId: orgs.id,
cascadeDelete: false,
minSelect: 0,
maxSelect: 1,
presentable: false,
}),
)
app.save(users)
},
(app) => {
const users = app.findCollectionByNameOrId('users')
users.fields.removeByName('organization')
app.save(users)
},
)