The frontend needs to know if the current user is an admin so it can show/hide the Admin nav link and protect admin routes client-side. Bean: nuzlocke-tracker-5svj chore: Update beans
44 lines
1.2 KiB
Markdown
44 lines
1.2 KiB
Markdown
---
|
|
# nuzlocke-tracker-dwah
|
|
title: Add is_admin column to users table
|
|
status: completed
|
|
type: task
|
|
priority: normal
|
|
created_at: 2026-03-21T10:06:19Z
|
|
updated_at: 2026-03-21T10:10:38Z
|
|
parent: nuzlocke-tracker-ce4o
|
|
---
|
|
|
|
Add an `is_admin` boolean column (default `false`) to the `users` table via an Alembic migration.
|
|
|
|
## Checklist
|
|
|
|
- [x] Create Alembic migration adding `is_admin: Mapped[bool]` column with `server_default="false"`
|
|
- [x] Update `User` model in `backend/src/app/models/user.py`
|
|
- [x] Run migration and verify column exists
|
|
- [x] Seed a test admin user (or document how to set `is_admin=true` via SQL)
|
|
|
|
## Files to change
|
|
|
|
- `backend/src/app/models/user.py` — add `is_admin` field
|
|
- `backend/src/app/alembic/versions/` — new migration
|
|
|
|
## Summary of Changes
|
|
|
|
Added `is_admin` boolean column to the `users` table:
|
|
|
|
- **Migration**: `p7e8f9a0b1c2_add_is_admin_to_users.py` adds the column with `server_default='false'`
|
|
- **Model**: Updated `User` model with `is_admin: Mapped[bool]` field
|
|
|
|
### Setting admin via SQL
|
|
|
|
To promote a user to admin:
|
|
```sql
|
|
UPDATE users SET is_admin = true WHERE email = 'admin@example.com';
|
|
```
|
|
|
|
Or by user ID:
|
|
```sql
|
|
UPDATE users SET is_admin = true WHERE id = '<uuid>';
|
|
```
|