/// // Extends `drones` with the identity a connected aircraft reports over the wire // (serial + firmware were already modelled; the firmware versions and the // aircraft registration were not), so that connecting a drone in the Fly App can // auto-populate its fleet entry in the Web App's Drones tab. // // Added fields: // - firmware aircraft firmware package version (auto-filled) // - controller_firmware remote-controller firmware version (auto-filled) // - registration FAA/CAA aircraft registration number (hand-entered). // Distinct from `operator_number`, which is the EU/ // Trafikstyrelsen *operator* ID displayed on the drone. // // `name` is also relaxed to optional: it is the pilot's custom label, and a // drone auto-added on connection has no label until the pilot gives it one (the // UI falls back to model + serial). // // Apply by copying into your PocketBase deployment's `pb_migrations/` directory // and restarting. Written for PocketBase v0.22+/v0.23. Idempotent: each field is // added only if absent, so re-running is a no-op. // // Depends on 1720300700_add_logbook.js (drones). migrate( (app) => { const drones = app.findCollectionByNameOrId('drones') const add = (field) => { if (!drones.fields.find((f) => f.name === field.name)) drones.fields.add(new Field(field)) } add({ name: 'firmware', type: 'text', max: 80 }) add({ name: 'controller_firmware', type: 'text', max: 80 }) add({ name: 'registration', type: 'text', max: 60 }) // The custom name is optional — auto-added drones arrive unnamed. const name = drones.fields.find((f) => f.name === 'name') if (name) name.required = false // One fleet entry per serial: the auto-add path keys off the serial, and a // duplicate would silently fork a drone's history across two records. const idx = 'CREATE UNIQUE INDEX `idx_drones_serial` ON `drones` (`serial`) WHERE `serial` != \'\'' if (!drones.indexes.find((i) => i.includes('idx_drones_serial'))) drones.indexes.push(idx) app.save(drones) }, (app) => { const drones = app.findCollectionByNameOrId('drones') for (const n of ['firmware', 'controller_firmware', 'registration']) { const f = drones.fields.find((x) => x.name === n) if (f) drones.fields.removeById(f.id) } const name = drones.fields.find((f) => f.name === 'name') if (name) name.required = true drones.indexes = drones.indexes.filter((i) => !i.includes('idx_drones_serial')) app.save(drones) }, )