Skip to content

fix(postgres): return BIGINT columns as numbers - #39

Merged
Musiker15 merged 2 commits into
MSK-Scripts:mainfrom
Uncharted-Roleplay:fix/postgres-bigint
Oct 23, 2026
Merged

Musiker15 merged 2 commits into
MSK-Scripts:mainfrom
Uncharted-Roleplay:fix/postgres-bigint

Conversation

@shane615

Copy link
Copy Markdown
Contributor

Description

pg returns BIGINT (int8) as a string; SQLite and mysql2 return a number. All timestamps (created_at, closed_at, last_activity, …) are BIGINT, so on PostgreSQL they reach the code as text. generateTranscript() does new Date(ticketInfo.created_at), which gives an Invalid Date for a numeric string, so every close fails to build a transcript:

[performClose] Transcript generation error: RangeError: Invalid time value
    at formatDate (src/utils/transcript.js)

Nothing goes to the log channel and nothing is stored. The fix gives the PostgreSQL pool a type parser that returns int8 as a number (that pool only, pg defaults untouched). Every BIGINT column is a millisecond timestamp or a row id, far below Number.MAX_SAFE_INTEGER; Discord ids are VARCHAR, so there's no precision risk. NUMERIC results (AVG) keep the existing num() coercion.

Related Issue

None; found while testing #32–#34 live on PostgreSQL 16.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

How Was This Tested?

  • Node.js 24.20.0, npm test: all pass, plus tests/postgres-int8.test.js (fails without the fix, needs no database server).
  • Live on PostgreSQL 16: before the fix every close logged the error above; afterwards transcripts are posted to the log channel and stored. Checked read-only against the live database that ids, timestamps and COUNT(*) come back as numbers.

Checklist

  • Code follows the project's conventions
  • No new dependencies
  • No new user-facing strings
  • No schema change
  • Works without MSK_API_KEY
  • Verified on a test server
  • CHANGELOG.md entry under [Unreleased]
  • Conventional Commits

https://claude.ai/code/session_01HZPZxD3edzJNFFsiWsHYY1

@Musiker15

Copy link
Copy Markdown
Member

Thanks, this one is clean too. The type parser only applies to our pool, and the counter-check works: the test fails without the fix.

#32 is merged now, so there's a conflict with main. I wanted to resolve that for you, but your fork belongs to an organization and GitHub doesn't let maintainers push to those. Could you rebase onto main? Two spots:

pool = new Pool({ connectionTimeoutMillis: 10_000, ...descriptor.options, max: 10, types: typeParsers });

Keep the pool.on('error', ...) listener from #32 below it. Your test still passes with that, since the fake pool already has on(). I'll merge #38 first, so after that you may get one more small changelog conflict here.

@shane615
shane615 force-pushed the fix/postgres-bigint branch from ccdda45 to b392478 Compare October 23, 2026 21:08
@shane615

Copy link
Copy Markdown
Contributor Author

Rebased onto main: types: typeParsers is in #32's Pool line with the pool.on('error', …) listener kept below it, and the changelog entry is at the end of ### Fixed. Tests pass. I'll rebase again if the changelog conflicts after #38.

@Musiker15

Copy link
Copy Markdown
Member

Thanks for the quick rebase, the Pool line looks exactly right. #38 is merged now, so there's one more small conflict in CHANGELOG.md. Could you rebase once more and put your entry after the #38 one at the end of ### Fixed? I'll merge it right after.

pg returns int8 as a string, SQLite and mysql2 return a number. The
timestamps (created_at, closed_at, ...) therefore reached the transcript
as strings, new Date('1792781224429') is an Invalid Date, and every
transcript failed with 'RangeError: Invalid time value': nothing in the
log channel, nothing stored for /history. The pool now parses int8 as a
number; all BIGINT columns are ms timestamps or row ids, Discord ids are
VARCHAR. Found in the live test.

Claude-Session: https://claude.ai/code/session_01HZPZxD3edzJNFFsiWsHYY1
@shane615

Copy link
Copy Markdown
Contributor Author

Rebased again; the entry now follows the #38 one at the end of ### Fixed. Tests pass.

@shane615
shane615 force-pushed the fix/postgres-bigint branch from b392478 to 2d7c4b8 Compare October 23, 2026 21:29
@Musiker15
Musiker15 merged commit 5fb4cec into MSK-Scripts:main Oct 23, 2026
5 checks passed
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.

2 participants