Skip to content

Commit

Permalink
Change primary key for contracts abi cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferossgp committed Dec 3, 2024
1 parent 2d50cda commit ad10de8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-pots-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@3loop/transaction-decoder': patch
---

Change primary key for sql cache table
12 changes: 9 additions & 3 deletions packages/transaction-decoder/src/sql/abi-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,26 @@ export const make = (strategies: AbiStore['strategies']) =>
Effect.gen(function* () {
const sql = yield* SqlClient.SqlClient

const table = sql('_loop_decoder_contract_abi_')
const table = sql('_loop_decoder_contract_abi_v2')
const id = sql.onDialectOrElse({
sqlite: () => sql`id INTEGER PRIMARY KEY AUTOINCREMENT,`,
pg: () => sql`id SERIAL PRIMARY KEY,`,
mysql: () => sql`id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id),`,
orElse: () => sql``,
})

// TODO; add timestamp to the table
yield* sql`
CREATE TABLE IF NOT EXISTS ${table} (
${id}
type TEXT NOT NULL,
address TEXT,
event TEXT,
signature TEXT,
chain INTEGER,
abi TEXT,
status TEXT NOT NULL,
timestamp TEXT DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (address, chain)
timestamp TEXT DEFAULT CURRENT_TIMESTAMP
)
`.pipe(
Effect.tapError(Effect.logError),
Expand Down

0 comments on commit ad10de8

Please sign in to comment.