Skip to content

Commit 69b662e

Browse files
committed
docs: mark issue #16 as complete
The index already existed in the database (created by the original migration) but wasn't marked in the model. This has been fixed to prevent confusion with alembic autogenerate.
1 parent 6c984a5 commit 69b662e

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

SECURITY-REVIEW.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,19 @@
271271

272272
### 16. Missing Database Index on Foreign Key
273273

274+
> [!NOTE]
275+
> **Done**: The index already existed in the database (created by the original
276+
> migration) but wasn't marked in the model. Added `index=True` to match the
277+
> actual database schema. See PR #816.
278+
274279
**Location**: `app/models/api_key.py:22`
275280

276-
- **Issue**: `user_id` foreign key lacks index. Queries filtering by user_id
277-
(like `get_user_api_keys_`) will do full table scans as API key count grows.
278-
- **Impact**: Performance degradation over time, slow queries.
279-
- **Fix**: Add `index=True` to `user_id` field:
281+
- **Issue**: `user_id` foreign key lacks index in the model definition. The
282+
index was created by the migration but not reflected in the model, causing
283+
a mismatch that could confuse `alembic autogenerate`.
284+
- **Impact**: Model/database schema mismatch; the index exists in the database
285+
but wasn't explicit in the code.
286+
- **Fix**: Add `index=True` to `user_id` field to match the database schema.
280287

281288
```python
282289
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), index=True)

0 commit comments

Comments
 (0)