From ec13f203ffd317a381f9e38a75b9362f8b2e3a8c Mon Sep 17 00:00:00 2001 From: Robin Langer Date: Mon, 9 Mar 2026 06:49:37 +1100 Subject: [PATCH] fix: remove admin unclaim guard, add catch-up migration for rel_type arrays MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The admin-blocks-admin guard in unclaim was preventing cleanup of test accounts. Migration 014 ensures facilitates.source_types includes 'organization' and created.target_types includes 'program' — fixes that were added to 013 after it had already run in production. Co-Authored-By: Claude Opus 4.6 --- app/api/auth/unclaim/route.ts | 8 -------- db/migrations/014_fix_rel_type_arrays.sql | 11 +++++++++++ 2 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 db/migrations/014_fix_rel_type_arrays.sql diff --git a/app/api/auth/unclaim/route.ts b/app/api/auth/unclaim/route.ts index f7e6e68..2bc4060 100644 --- a/app/api/auth/unclaim/route.ts +++ b/app/api/auth/unclaim/route.ts @@ -27,14 +27,6 @@ export async function POST(request: NextRequest) { ); } - // Safety: don't let admins unclaim *other* admins (self-unclaim is fine) - if (targetUser.is_admin && targetUser.id !== user.id) { - return NextResponse.json( - { error: 'Cannot unclaim another admin user' }, - { status: 403 } - ); - } - const personCount = await countUserPersons(targetUser.id); if (personCount <= 1) { diff --git a/db/migrations/014_fix_rel_type_arrays.sql b/db/migrations/014_fix_rel_type_arrays.sql new file mode 100644 index 0000000..f02ed67 --- /dev/null +++ b/db/migrations/014_fix_rel_type_arrays.sql @@ -0,0 +1,11 @@ +-- Migration 014: Fix rel_type source/target arrays +-- Catch-up for changes added to 013 after it had already run in production. +-- All statements are idempotent (setting to the correct final state). + +-- facilitates: ensure 'organization' is in source_types +UPDATE rel_types SET source_types = '{person,organization,catalyst}' +WHERE key = 'facilitates'; + +-- created: ensure 'program' is in target_types +UPDATE rel_types SET target_types = '{project,event,program}' +WHERE key = 'created';