Skip to content

fix: use epoch ms for PostgreSQL bigint columns in quota_state#171

Merged
mcowger merged 1 commit intomainfrom
claude/issue-166-20260416-0017
Apr 16, 2026
Merged

fix: use epoch ms for PostgreSQL bigint columns in quota_state#171
mcowger merged 1 commit intomainfrom
claude/issue-166-20260416-0017

Conversation

@mcowger
Copy link
Copy Markdown
Owner

@mcowger mcowger commented Apr 16, 2026

Fixes #166

The quota_state table uses bigint columns for last_updated and window_start in PostgreSQL, but quota-enforcer.ts was passing Date objects instead of epoch millisecond numbers. This caused PostgresError: "column is of type bigint but expression is of type timestamp with time zone".

Fix by using toDbTimestampMs() for writes and fromDbTimestamp() for reads to properly handle the type difference between PostgreSQL (number) and SQLite (Date).

Generated with Claude Code

The quota_state table uses bigint columns for last_updated and window_start
in PostgreSQL, but quota-enforcer.ts was passing Date objects instead of
epoch millisecond numbers. This caused PostgresError: "column is of type
bigint but expression is of type timestamp with time zone".

Fix by:
- Using toDbTimestampMs() for writes, which returns number for PostgreSQL
  and Date for SQLite (matching each schema's expected type)
- Using fromDbTimestamp() helper for reads, which handles PostgreSQL
  returning epoch ms numbers vs SQLite returning Date objects
- Removed all unsafe `as Date` casts on database-returned values

Fixes #166

Co-authored-by: Matt Cowger <mcowger@users.noreply.github.com>
@mcowger mcowger merged commit e1ee1fe into main Apr 16, 2026
1 check failed
github-actions bot pushed a commit that referenced this pull request Apr 16, 2026
fix: use epoch ms for PostgreSQL bigint columns in quota_state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Errors after recent updates

1 participant