From d5191073f06e8b5db662f3d35907a9d6db58937b Mon Sep 17 00:00:00 2001 From: RaymondVerhoef Date: Thu, 25 Jun 2026 18:05:39 +0200 Subject: [PATCH] feat: migrate team_members to OIDC-based auth collection and update docker-compose environment configuration --- docker-compose.yml | 4 ++ .../1781000000_team_members_to_auth.js | 37 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 3cfba2b..dd1eef5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,7 +12,11 @@ services: container_name: pocketbase-learning restart: unless-stopped working_dir: /pb + env_file: + - .env.local command: ["serve", "--http=0.0.0.0:8090", "--dir=/pb/pb_data", "--migrationsDir=/pb/pb_migrations"] + ports: + - "8090:8090" volumes: - pb_data:/pb/pb_data - ./pb_migrations:/pb/pb_migrations diff --git a/pb_migrations/1781000000_team_members_to_auth.js b/pb_migrations/1781000000_team_members_to_auth.js index 7283571..ec0aa0b 100644 --- a/pb_migrations/1781000000_team_members_to_auth.js +++ b/pb_migrations/1781000000_team_members_to_auth.js @@ -20,6 +20,25 @@ // providers) or ship a follow-up migration. migrate((app) => { // 1. Drop the old PIN-based collection (takes the PIN records with it). + // Other collections (micro_learning_completions, theme_session_completions) + // have relation fields pointing to the old team_members — PocketBase refuses + // to delete a referenced collection. Remove those relation fields first, + // delete the old collection, create the new auth collection, then re-add + // the relation fields pointing to the new collection. + const relDeps = [ + { collection: "micro_learning_completions", fieldId: "rel_team_member_id", fieldName: "team_member_id" }, + { collection: "theme_session_completions", fieldId: "rel_tsc_team_member", fieldName: "team_member_id" }, + ]; + + // Remove blocking relation fields so the old collection can be deleted. + for (const dep of relDeps) { + try { + const col = app.findCollectionByNameOrId(dep.collection); + col.fields.removeById(dep.fieldId); + app.save(col); + } catch (_) { /* collection doesn't exist yet — skip */ } + } + try { const old = app.findCollectionByNameOrId("team_members"); app.delete(old); @@ -231,6 +250,24 @@ migrate((app) => { }); app.save(collection); + + // 3. Re-add the relation fields pointing to the new auth collection. + for (const dep of relDeps) { + try { + const col = app.findCollectionByNameOrId(dep.collection); + const newField = new Field({ + id: dep.fieldId, + name: dep.fieldName, + type: "relation", + required: true, + collectionId: collection.id, + cascadeDelete: true, + maxSelect: 1, + }); + col.fields.add(newField); + app.save(col); + } catch (_) { /* collection doesn't exist — skip */ } + } }, (app) => { // Down: drop the auth collection and recreate the original PIN-based base // collection (without data — the original records are gone).