Skip to content

Here’s a clean, ready-to-use PR description you can paste: --- ## 🛠️ Fix database initialization and custom BigInt type handling#256

Open
ThomasHumper wants to merge 3 commits into
TheDeveloperDen:masterfrom
ThomasHumper:master
Open

Here’s a clean, ready-to-use PR description you can paste: --- ## 🛠️ Fix database initialization and custom BigInt type handling#256
ThomasHumper wants to merge 3 commits into
TheDeveloperDen:masterfrom
ThomasHumper:master

Conversation

@ThomasHumper
Copy link
Copy Markdown

🛠️ Fix database initialization and custom BigInt type handling

Summary

This PR fixes multiple bugs and unsafe behaviors in the database initialization layer and the custom RealBigInt Sequelize data type. It improves runtime stability, correctness of Sequelize usage, and cross-dialect compatibility (Postgres + SQLite).


🚨 Fixes

Database initialization (initStorage)

  • Fixed incorrect Sequelize typing (AbstractDialect misuse removed)

  • Corrected dialect typing to use Sequelize-supported Dialect

  • Fixed unsafe port parsing (string → number)

  • Improved environment handling for DB host detection

  • Added proper error handling for:

    • authenticate()
    • sync()
  • Fixed unsafe model association binding order (now guarded)

  • Improved logging for DB lifecycle failures


BigInt DataType (RealBigInt)

  • Fixed incorrect instanceof BigInt usage (replaced with typeof === "bigint")

  • Fixed invalid Sequelize ValidationErrorItem usage

  • Added proper null/undefined handling in escape()

  • Fixed SQL escaping to prevent malformed queries

  • Improved sanitize() to safely convert:

    • string → bigint
    • number → bigint
    • boolean → bigint (explicit conversion)
  • Fixed unsafe error message construction

  • Hardened dialect support detection with optional chaining

  • Improved fallback behavior for non-native BigInt dialects (SQLite)


🧠 Behavioral Improvements

  • Safer cross-database compatibility (Postgres + SQLite)
  • More predictable BigInt serialization format (123n fallback encoding)
  • Prevents runtime crashes from invalid DB values
  • Improves logging clarity for slow queries and DB errors

⚠️ Breaking Changes

None (fully backward compatible at runtime)


✅ Testing Checklist

  • App boots with Postgres
  • App boots with SQLite (in-memory)
  • BigInt fields store and retrieve correctly
  • No validation crashes on invalid DB values
  • Associations correctly load on startup

📌 Notes

This refactor aligns Sequelize usage with supported APIs and removes unsafe assumptions about BigInt handling across dialects.


If you want, I can also write:

  • a shorter “squash commit style” PR description
  • or a GitHub-ready changelog entry (CHANGELOG.md)

@bristermitten
Copy link
Copy Markdown
Member

hi @ThomasHumper thanks for the PR! i have some issues with this. did you test it?

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