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

fix(store-sync): fix overflowing column types, bump postgres sync version #2270

Merged
merged 9 commits into from
Feb 20, 2024
Merged
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
5 changes: 5 additions & 0 deletions .changeset/fifty-guests-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store-sync": patch
---

Bumped the Postgres column size for `int32`, `uint32`, `int64`, and `uint64` types to avoid overflows
20 changes: 10 additions & 10 deletions packages/store-sync/src/postgres-decoded/buildColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,28 @@ export function buildColumn(name: string, schemaAbiType: SchemaAbiType) {

case "uint8":
case "uint16":
case "uint24":
case "int8":
case "int16":
case "uint24":
case "uint32":
yonadaa marked this conversation as resolved.
Show resolved Hide resolved
case "int24":
case "int32":
// integer = 4 bytes (https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-INT)
return asNumber(name, "integer");

case "uint32":
case "uint40":
case "uint48":
case "int32":
case "int40":
Copy link
Member

Choose a reason for hiding this comment

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

can't comment below but does int48 need to be bumped to the next size up too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can't comment below

What does that mean sorry? Anyway I don't think so, int48 is already a postgres bigint here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We chatted IRL and we mixed up the JavaScript and Postgres column types.

but maybe uint64 and int64 need to move down because they may not fit within the bigint column type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@holic it definitely doesn't fit - uint64 is 8 bytes unsigned, postgres bigint is 8 bytes signed:

https://www.postgresql.org/docs/current/datatype-numeric.html

case "int48":
// bigint = 8 bytes (https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-INT)
return asNumber(name, "bigint");

case "uint56":
yonadaa marked this conversation as resolved.
Show resolved Hide resolved
case "uint64":
case "int56":
case "int64":
// bigint = 8 bytes (https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-INT)
return asBigInt(name, "bigint");

case "uint64":
case "uint72":
case "uint80":
case "uint88":
Expand All @@ -58,6 +57,7 @@ export function buildColumn(name: string, schemaAbiType: SchemaAbiType) {
case "uint240":
case "uint248":
case "uint256":
case "int64":
case "int72":
case "int80":
case "int88":
Expand Down Expand Up @@ -126,29 +126,28 @@ export function buildColumn(name: string, schemaAbiType: SchemaAbiType) {

case "uint8[]":
case "uint16[]":
case "uint24[]":
case "int8[]":
case "int16[]":
case "uint24[]":
case "uint32[]":
case "int24[]":
case "int32[]":
// integer = 4 bytes (https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-INT)
return asNumberArray(name, "integer[]");

case "uint32[]":
case "uint40[]":
case "uint48[]":
case "int32[]":
case "int40[]":
case "int48[]":
// bigint = 8 bytes (https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-INT)
return asNumberArray(name, "bigint[]");

case "uint56[]":
case "uint64[]":
case "int56[]":
case "int64[]":
// bigint = 8 bytes (https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-INT)
return asBigIntArray(name, "bigint[]");

case "uint64[]":
case "uint72[]":
case "uint80[]":
case "uint88[]":
Expand All @@ -173,6 +172,7 @@ export function buildColumn(name: string, schemaAbiType: SchemaAbiType) {
case "uint240[]":
case "uint248[]":
case "uint256[]":
case "int64[]":
case "int72[]":
case "int80[]":
case "int88[]":
Expand Down
4 changes: 2 additions & 2 deletions packages/store-sync/src/postgres-decoded/buildTable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ describe("buildTable", () => {
"dataType": "custom",
"name": "x",
"notNull": true,
"sqlName": "integer",
"sqlName": "bigint",
},
"y": {
"dataType": "custom",
"name": "y",
"notNull": true,
"sqlName": "integer",
"sqlName": "bigint",
},
}
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe("createStorageAdapter", async () => {
{
"blockNumber": 20n,
"chainId": 31337,
"version": "0.0.4",
"version": "0.0.5",
},
]
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe("createStorageAdapter", async () => {
{
"blockNumber": 20n,
"chainId": 31337,
"version": "0.0.4",
"version": "0.0.5",
},
]
`);
Expand Down
2 changes: 1 addition & 1 deletion packages/store-sync/src/postgres/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = "0.0.4";
export const version = "0.0.5";
Loading