shinkan-jinkendo/backend/migrations/041_bootstrap_superadmin.sql
Lars b661d0edb2
Some checks failed
Deploy Development / deploy (push) Successful in 37s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 6s
Test Suite / playwright-tests (push) Failing after 39s
feat: update application version to 0.8.20 and enhance superadmin role management
- Bumped application version to 0.8.20 in both backend and frontend files.
- Introduced migration 041 to promote the oldest admin user to superadmin if no superadmin exists.
- Updated registration logic to assign the superadmin role to the first user and those in ADMIN_BOOTSTRAP_EMAILS.
- Enhanced changelog to document the new version and changes made in this release.
2026-05-05 21:10:19 +02:00

21 lines
635 B
SQL

-- Migration 041: Super-Admin für bestehende Installationen
-- Bisheriger Bootstrap (registration_role) setzte nur 'admin'. Viele Endpunkte
-- (z. B. Verein löschen, Super-Rolle vergeben) verlangen 'superadmin'.
-- Wenn noch kein Super-Admin existiert: den ältesten Nutzer mit role = admin hochstufen.
UPDATE profiles p
SET role = 'superadmin', updated_at = NOW()
FROM (
SELECT id
FROM profiles
WHERE lower(trim(COALESCE(role, ''))) = 'admin'
ORDER BY id ASC
LIMIT 1
) sub
WHERE p.id = sub.id
AND NOT EXISTS (
SELECT 1
FROM profiles
WHERE lower(trim(COALESCE(role, ''))) = 'superadmin'
);