feat: migrate team_members to OIDC-based auth collection and update docker-compose environment configuration
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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).
|
||||
|
||||
Reference in New Issue
Block a user