aboutsummaryrefslogtreecommitdiffstats
path: root/packages/pipeline/src
diff options
context:
space:
mode:
authorF. Eugene Aumson <feuGeneA@users.noreply.github.com>2019-02-09 02:21:41 +0800
committerGitHub <noreply@github.com>2019-02-09 02:21:41 +0800
commit629a8d632801c4861824b7d0423792d167b8564d (patch)
tree250ee59cfc90089990636aefa9948f74d1fc6e06 /packages/pipeline/src
parentffdaec9f9fa68c500ceabf6565640ba6549a9fba (diff)
downloaddexon-0x-contracts-629a8d632801c4861824b7d0423792d167b8564d.tar
dexon-0x-contracts-629a8d632801c4861824b7d0423792d167b8564d.tar.gz
dexon-0x-contracts-629a8d632801c4861824b7d0423792d167b8564d.tar.bz2
dexon-0x-contracts-629a8d632801c4861824b7d0423792d167b8564d.tar.lz
dexon-0x-contracts-629a8d632801c4861824b7d0423792d167b8564d.tar.xz
dexon-0x-contracts-629a8d632801c4861824b7d0423792d167b8564d.tar.zst
dexon-0x-contracts-629a8d632801c4861824b7d0423792d167b8564d.zip
Add migration to fix exchange events primary keys (#1593)
* Add migration to fix exchange events primary key * correct comment: "foreign key" -> "primary key" * Refine hack to handle only the expected error * Add tx hash to erc20 approval events primary key
Diffstat (limited to 'packages/pipeline/src')
-rw-r--r--packages/pipeline/src/entities/erc20_approval_event.ts2
-rw-r--r--packages/pipeline/src/entities/exchange_cancel_event.ts2
-rw-r--r--packages/pipeline/src/entities/exchange_cancel_up_to_event.ts2
-rw-r--r--packages/pipeline/src/entities/exchange_fill_event.ts2
-rw-r--r--packages/pipeline/src/scripts/pull_exchange_events.ts12
5 files changed, 13 insertions, 7 deletions
diff --git a/packages/pipeline/src/entities/erc20_approval_event.ts b/packages/pipeline/src/entities/erc20_approval_event.ts
index 69cdfcb0b..ee5e621d2 100644
--- a/packages/pipeline/src/entities/erc20_approval_event.ts
+++ b/packages/pipeline/src/entities/erc20_approval_event.ts
@@ -15,7 +15,7 @@ export class ERC20ApprovalEvent {
@Column({ name: 'raw_data' })
public rawData!: string;
- @Column({ name: 'transaction_hash' })
+ @PrimaryColumn({ name: 'transaction_hash' })
public transactionHash!: string;
@Column({ name: 'owner_address' })
public ownerAddress!: string;
diff --git a/packages/pipeline/src/entities/exchange_cancel_event.ts b/packages/pipeline/src/entities/exchange_cancel_event.ts
index 38f99c903..a86194920 100644
--- a/packages/pipeline/src/entities/exchange_cancel_event.ts
+++ b/packages/pipeline/src/entities/exchange_cancel_event.ts
@@ -15,7 +15,7 @@ export class ExchangeCancelEvent {
@Column({ name: 'raw_data' })
public rawData!: string;
- @Column({ name: 'transaction_hash' })
+ @PrimaryColumn({ name: 'transaction_hash' })
public transactionHash!: string;
@Column({ name: 'maker_address' })
public makerAddress!: string;
diff --git a/packages/pipeline/src/entities/exchange_cancel_up_to_event.ts b/packages/pipeline/src/entities/exchange_cancel_up_to_event.ts
index 27580305e..f24aea23a 100644
--- a/packages/pipeline/src/entities/exchange_cancel_up_to_event.ts
+++ b/packages/pipeline/src/entities/exchange_cancel_up_to_event.ts
@@ -15,7 +15,7 @@ export class ExchangeCancelUpToEvent {
@Column({ name: 'raw_data' })
public rawData!: string;
- @Column({ name: 'transaction_hash' })
+ @PrimaryColumn({ name: 'transaction_hash' })
public transactionHash!: string;
@Column({ name: 'maker_address' })
public makerAddress!: string;
diff --git a/packages/pipeline/src/entities/exchange_fill_event.ts b/packages/pipeline/src/entities/exchange_fill_event.ts
index 9b7727615..52111711e 100644
--- a/packages/pipeline/src/entities/exchange_fill_event.ts
+++ b/packages/pipeline/src/entities/exchange_fill_event.ts
@@ -16,7 +16,7 @@ export class ExchangeFillEvent {
@Column({ name: 'raw_data' })
public rawData!: string;
- @Column({ name: 'transaction_hash' })
+ @PrimaryColumn({ name: 'transaction_hash' })
public transactionHash!: string;
@Column({ name: 'maker_address' })
public makerAddress!: string;
diff --git a/packages/pipeline/src/scripts/pull_exchange_events.ts b/packages/pipeline/src/scripts/pull_exchange_events.ts
index f8ce4038d..c2c56da6b 100644
--- a/packages/pipeline/src/scripts/pull_exchange_events.ts
+++ b/packages/pipeline/src/scripts/pull_exchange_events.ts
@@ -112,15 +112,20 @@ async function saveIndividuallyWithFallbackAsync<T extends ExchangeEvent>(
events: T[],
): Promise<void> {
// Note(albrow): This is a temporary hack because `save` is not working as
- // documented and is causing a foreign key constraint violation. Hopefully
+ // documented and is causing a primary key constraint violation. Hopefully
// can remove later because this "poor man's upsert" implementation operates
// on one event at a time and is therefore much slower.
for (const event of events) {
try {
// First try an insert.
await repository.insert(event);
- } catch {
- // If it fails, assume it was a foreign key constraint error and try
+ } catch (err) {
+ if (err.message.includes('duplicate key value violates unique constraint')) {
+ logUtils.log("Ignore the preceeding INSERT failure; it's not unexpected");
+ } else {
+ throw err;
+ }
+ // If it fails, assume it was a primary key constraint error and try
// doing an update instead.
// Note(albrow): Unfortunately the `as any` hack here seems
// required. I can't figure out how to convince the type-checker
@@ -132,6 +137,7 @@ async function saveIndividuallyWithFallbackAsync<T extends ExchangeEvent>(
contractAddress: event.contractAddress,
blockNumber: event.blockNumber,
logIndex: event.logIndex,
+ transactionHash: event.transactionHash,
} as any,
event as any,
);