Fix discord_id type mismatch between model (CharField) and migration (BIGINT) #78

Open
opened 2026-03-27 04:06:52 +00:00 by cal · 1 comment
Owner

Problem

CustomCommandCreator.discord_id is declared as CharField(max_length=20, unique=True) in the model (db_engine.py line 2227) but the migration created it as BIGINT UNIQUE NOT NULL.

The ORM sends values as quoted strings while the column is integer. PostgreSQL will implicitly cast, but this prevents index usage and is a data consistency risk.

Fix

Align the model and migration — either change the model to BigIntegerField or alter the column to VARCHAR(20). Discord snowflake IDs are commonly stored as strings to avoid JavaScript precision issues.

Severity

Medium — index bypass and data consistency risk.

## Problem `CustomCommandCreator.discord_id` is declared as `CharField(max_length=20, unique=True)` in the model (`db_engine.py` line 2227) but the migration created it as `BIGINT UNIQUE NOT NULL`. The ORM sends values as quoted strings while the column is integer. PostgreSQL will implicitly cast, but this prevents index usage and is a data consistency risk. ## Fix Align the model and migration — either change the model to `BigIntegerField` or alter the column to `VARCHAR(20)`. Discord snowflake IDs are commonly stored as strings to avoid JavaScript precision issues. ## Severity Medium — index bypass and data consistency risk.
Claude added the
ai-working
label 2026-03-27 06:01:16 +00:00
Claude removed the
ai-working
label 2026-03-27 06:04:06 +00:00
Collaborator

PR #88 opens the fix: #88

Two targeted changes:

  1. app/db_engine.pyCharField(max_length=20)BigIntegerField to match the BIGINT column from the migration
  2. app/routers_v3/custom_commands.py — removed str(discord_id) cast in get_creator_by_discord_id() that was working around the type mismatch

No migration needed — the DB column is already BIGINT; only the ORM model was wrong.

PR #88 opens the fix: https://git.manticorum.com/cal/major-domo-database/pulls/88 Two targeted changes: 1. `app/db_engine.py` — `CharField(max_length=20)` → `BigIntegerField` to match the `BIGINT` column from the migration 2. `app/routers_v3/custom_commands.py` — removed `str(discord_id)` cast in `get_creator_by_discord_id()` that was working around the type mismatch No migration needed — the DB column is already `BIGINT`; only the ORM model was wrong.
Claude added the
ai-pr-opened
label 2026-03-27 06:04:14 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/major-domo-database#78
No description provided.