Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flav/int to bigint migration #9065

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions connectors/src/resources/storage/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import assert from "node:assert";

import { isDevelopment } from "@dust-tt/types";
import assert from "assert";
import types, { builtins } from "pg-types";
import { Sequelize } from "sequelize";

Expand Down
15 changes: 15 additions & 0 deletions front/lib/resources/storage/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { isDevelopment } from "@dust-tt/types";
import assert from "assert";
import types, { builtins } from "pg-types";
import { Sequelize } from "sequelize";

import { dbConfig } from "@app/lib/resources/storage/config";
Expand All @@ -8,6 +10,19 @@ const acquireAttempts = new WeakMap();

const { DB_LOGGING_ENABLED = false } = process.env;

// Parse PostgreSQL BIGINT (INT8) values into JavaScript numbers, but only if they
// fall within JavaScript's safe integer range (-(2^53 - 1) to 2^53 - 1). This
// prevents silent precision loss when handling large integers from the database.
// Throws an assertion error if a BIGINT value exceeds JavaScript's safe integer
// limits.
types.setTypeParser(builtins.INT8, function (val) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will extract to a dedicated PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipped here.

assert(
Number.isSafeInteger(Number(val)),
`Found a value stored as a BIGINT that is not a safe integer: ${val}`
);
return Number(val);
});

function sequelizeLogger(message: string) {
console.log(message.replace("Executing (default): ", ""));
}
Expand Down
Loading
Loading