Skip to content

Commit

Permalink
fix(store-sync): fix overflowing column types, bump postgres sync ver…
Browse files Browse the repository at this point in the history
…sion (#2270)

Co-authored-by: Kevin Ingersoll <[email protected]>
  • Loading branch information
yonadaa and holic authored Feb 20, 2024
1 parent d1753d0 commit 6c615b6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
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":
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":
case "int48":
// bigint = 8 bytes (https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-INT)
return asNumber(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 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";

0 comments on commit 6c615b6

Please sign in to comment.