Skip to content

Commit f2c5ab5

Browse files
thelostone-mchussedev
authored andcommitted
add unique constraint
1 parent e928220 commit f2c5ab5

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/database/migrate.ts

+6
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ export async function migrateDataFetcher<T>(db: Kysely<T>, schemaName: string) {
384384
.createTable("ipfs_data")
385385
.addColumn("cid", "text")
386386
.addColumn("data", "jsonb")
387+
.addUniqueConstraint("unique_cid", ["cid"])
387388
.execute();
388389
}
389390

@@ -401,6 +402,11 @@ export async function migratePriceFetcher<T>(
401402
.addColumn("priceInUSD", "real")
402403
.addColumn("timestamp", "timestamptz")
403404
.addColumn("blockNumber", BIGINT_TYPE)
405+
.addUniqueConstraint("unique_chainId_tokenAddress_blockNumber", [
406+
"chainId",
407+
"tokenAddress",
408+
"blockNumber",
409+
])
404410
.execute();
405411

406412
await db.schema

src/prices/provider.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,18 @@ export function createPriceProvider(
219219
);
220220

221221
if (!existingPrice) {
222-
await db.applyChange({
223-
type: "InsertManyPrices",
224-
prices: [newPrice],
225-
});
222+
try {
223+
await db.applyChange({
224+
type: "InsertManyPrices",
225+
prices: [newPrice],
226+
});
227+
} catch (e) {
228+
logger.error({
229+
msg: "Failed to insert price",
230+
error: e,
231+
price: newPrice,
232+
});
233+
}
226234
}
227235

228236
return { ...newPrice, tokenDecimals: token.decimals };

0 commit comments

Comments
 (0)