From 6c615b608e73d3bdabde3ad03823f1dce87f2ac6 Mon Sep 17 00:00:00 2001 From: yonada Date: Tue, 20 Feb 2024 15:44:23 +0000 Subject: [PATCH] fix(store-sync): fix overflowing column types, bump postgres sync version (#2270) Co-authored-by: Kevin Ingersoll --- .changeset/fifty-guests-rescue.md | 5 +++++ .../src/postgres-decoded/buildColumn.ts | 20 +++++++++---------- .../src/postgres-decoded/buildTable.test.ts | 4 ++-- .../createStorageAdapter.test.ts | 2 +- .../src/postgres/createStorageAdapter.test.ts | 2 +- packages/store-sync/src/postgres/version.ts | 2 +- 6 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 .changeset/fifty-guests-rescue.md diff --git a/.changeset/fifty-guests-rescue.md b/.changeset/fifty-guests-rescue.md new file mode 100644 index 0000000000..8e2c718762 --- /dev/null +++ b/.changeset/fifty-guests-rescue.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/store-sync": patch +--- + +Bumped the Postgres column size for `int32`, `uint32`, `int64`, and `uint64` types to avoid overflows diff --git a/packages/store-sync/src/postgres-decoded/buildColumn.ts b/packages/store-sync/src/postgres-decoded/buildColumn.ts index 4bdc14db1f..f72c27443e 100644 --- a/packages/store-sync/src/postgres-decoded/buildColumn.ts +++ b/packages/store-sync/src/postgres-decoded/buildColumn.ts @@ -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": @@ -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": @@ -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[]": @@ -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[]": diff --git a/packages/store-sync/src/postgres-decoded/buildTable.test.ts b/packages/store-sync/src/postgres-decoded/buildTable.test.ts index 9f2e75a057..f20f846392 100644 --- a/packages/store-sync/src/postgres-decoded/buildTable.test.ts +++ b/packages/store-sync/src/postgres-decoded/buildTable.test.ts @@ -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", }, } `); diff --git a/packages/store-sync/src/postgres-decoded/createStorageAdapter.test.ts b/packages/store-sync/src/postgres-decoded/createStorageAdapter.test.ts index 64f71e01c2..9a37fe7036 100644 --- a/packages/store-sync/src/postgres-decoded/createStorageAdapter.test.ts +++ b/packages/store-sync/src/postgres-decoded/createStorageAdapter.test.ts @@ -52,7 +52,7 @@ describe("createStorageAdapter", async () => { { "blockNumber": 20n, "chainId": 31337, - "version": "0.0.4", + "version": "0.0.5", }, ] `); diff --git a/packages/store-sync/src/postgres/createStorageAdapter.test.ts b/packages/store-sync/src/postgres/createStorageAdapter.test.ts index 9afc5b7a76..0e3249f005 100644 --- a/packages/store-sync/src/postgres/createStorageAdapter.test.ts +++ b/packages/store-sync/src/postgres/createStorageAdapter.test.ts @@ -50,7 +50,7 @@ describe("createStorageAdapter", async () => { { "blockNumber": 20n, "chainId": 31337, - "version": "0.0.4", + "version": "0.0.5", }, ] `); diff --git a/packages/store-sync/src/postgres/version.ts b/packages/store-sync/src/postgres/version.ts index 47a7432322..631eadd03d 100644 --- a/packages/store-sync/src/postgres/version.ts +++ b/packages/store-sync/src/postgres/version.ts @@ -1 +1 @@ -export const version = "0.0.4"; +export const version = "0.0.5";