Skip to content

Commit ad10de8

Browse files
committed
Change primary key for contracts abi cache
1 parent 2d50cda commit ad10de8

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

.changeset/flat-pots-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@3loop/transaction-decoder': patch
3+
---
4+
5+
Change primary key for sql cache table

packages/transaction-decoder/src/sql/abi-store.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,26 @@ export const make = (strategies: AbiStore['strategies']) =>
88
Effect.gen(function* () {
99
const sql = yield* SqlClient.SqlClient
1010

11-
const table = sql('_loop_decoder_contract_abi_')
11+
const table = sql('_loop_decoder_contract_abi_v2')
12+
const id = sql.onDialectOrElse({
13+
sqlite: () => sql`id INTEGER PRIMARY KEY AUTOINCREMENT,`,
14+
pg: () => sql`id SERIAL PRIMARY KEY,`,
15+
mysql: () => sql`id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id),`,
16+
orElse: () => sql``,
17+
})
1218

1319
// TODO; add timestamp to the table
1420
yield* sql`
1521
CREATE TABLE IF NOT EXISTS ${table} (
22+
${id}
1623
type TEXT NOT NULL,
1724
address TEXT,
1825
event TEXT,
1926
signature TEXT,
2027
chain INTEGER,
2128
abi TEXT,
2229
status TEXT NOT NULL,
23-
timestamp TEXT DEFAULT CURRENT_TIMESTAMP,
24-
PRIMARY KEY (address, chain)
30+
timestamp TEXT DEFAULT CURRENT_TIMESTAMP
2531
)
2632
`.pipe(
2733
Effect.tapError(Effect.logError),

0 commit comments

Comments
 (0)