fix: correct profiles.user_type constraint and admin_profiles column names in reset/seed
- reset_environment: profiles PATCH now sets only school_id=null (removing invalid user_type='platform_admin' that violated profiles_user_type_check constraint) - seed_environment: same profiles PATCH fix; admin_profiles upsert now uses correct column names (admin_role, is_super_admin, display_name) matching 002_schema.sql - Platform admin status is correctly tracked via admin_profiles.is_super_admin=true and JWT user_metadata.user_type='platform_admin', not profiles.user_type Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
@@ -381,18 +381,19 @@ def seed() -> Dict[str, Any]:
|
||||
KCAR_ID = "d9e1d1a9-04c4-4611-bb05-57babf4a9a28"
|
||||
try:
|
||||
_rest_upsert(url, headers, "admin_profiles", {
|
||||
"id": KCAR_ID,
|
||||
"email": "[email protected]",
|
||||
"role": "super_admin",
|
||||
"permissions": ["all"],
|
||||
"metadata": {"seeded": True},
|
||||
"id": KCAR_ID,
|
||||
"email": "[email protected]",
|
||||
"display_name": "Kevin Carroll",
|
||||
"admin_role": "super_admin",
|
||||
"is_super_admin": True,
|
||||
"metadata": {"seeded": True},
|
||||
}, on_conflict="id")
|
||||
logger.info(" kcar → admin_profiles ✓")
|
||||
except Exception as e:
|
||||
errors.append(f"kcar_admin: {e}")
|
||||
logger.error(f" {e}")
|
||||
|
||||
# Fix kcar's auth user_metadata so user_type is "platform_admin", not "teacher".
|
||||
# Fix kcar's auth user_metadata and profiles.user_type to "platform_admin".
|
||||
# Without this, POST /user/init assigns kcar to the default school on first login.
|
||||
try:
|
||||
r = requests.put(
|
||||
@@ -401,12 +402,26 @@ def seed() -> Dict[str, Any]:
|
||||
json={"user_metadata": {"user_type": "platform_admin"}},
|
||||
)
|
||||
if r.status_code in (200, 201):
|
||||
logger.info(" kcar → user_type: platform_admin ✓")
|
||||
logger.info(" kcar → auth user_metadata: platform_admin ✓")
|
||||
else:
|
||||
logger.warning(f" kcar user_metadata patch failed ({r.status_code}): {r.text[:120]}")
|
||||
except Exception as e:
|
||||
errors.append(f"kcar_user_type: {e}")
|
||||
logger.error(f" {e}")
|
||||
try:
|
||||
r = requests.patch(
|
||||
f"{url}/rest/v1/profiles",
|
||||
headers={**headers, "Prefer": "return=minimal"},
|
||||
params={"id": f"eq.{KCAR_ID}"},
|
||||
json={"school_id": None},
|
||||
)
|
||||
if r.status_code in (200, 204):
|
||||
logger.info(" kcar → profiles.school_id: null ✓")
|
||||
else:
|
||||
logger.warning(f" kcar profiles patch failed ({r.status_code}): {r.text[:120]}")
|
||||
except Exception as e:
|
||||
errors.append(f"kcar_profile: {e}")
|
||||
logger.error(f" {e}")
|
||||
|
||||
# ── Summary ───────────────────────────────────────────────────────────────
|
||||
results["success"] = len(errors) == 0
|
||||
|
||||
Reference in New Issue
Block a user