aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-11-14 06:57:58 +0800
committerAlex Browne <stephenalexbrowne@gmail.com>2018-12-05 06:24:48 +0800
commit2cbb82eb0498c539ea16afe4012bd69f154ad027 (patch)
treefca7ba0aa845560a4ab536fef893080b029874f2 /packages
parent96134003e1aa1903bdf051e39e7e244cc8684043 (diff)
downloaddexon-sol-tools-2cbb82eb0498c539ea16afe4012bd69f154ad027.tar.gz
dexon-sol-tools-2cbb82eb0498c539ea16afe4012bd69f154ad027.tar.zst
dexon-sol-tools-2cbb82eb0498c539ea16afe4012bd69f154ad027.zip
Update schema for sra_orders
Diffstat (limited to 'packages')
-rw-r--r--packages/pipeline/migrations/1542147915364-NewSraOrderTimestampFormat.ts48
-rw-r--r--packages/pipeline/src/entities/sra_order.ts7
2 files changed, 49 insertions, 6 deletions
diff --git a/packages/pipeline/migrations/1542147915364-NewSraOrderTimestampFormat.ts b/packages/pipeline/migrations/1542147915364-NewSraOrderTimestampFormat.ts
new file mode 100644
index 000000000..5a8f3fec8
--- /dev/null
+++ b/packages/pipeline/migrations/1542147915364-NewSraOrderTimestampFormat.ts
@@ -0,0 +1,48 @@
+import { MigrationInterface, QueryRunner, Table } from 'typeorm';
+
+export class NewSraOrderTimestampFormat1542147915364 implements MigrationInterface {
+ public async up(queryRunner: QueryRunner): Promise<any> {
+ await queryRunner.query(
+ `ALTER TABLE raw.sra_orders
+ DROP CONSTRAINT "PK_09bfb9980715329563bd53d667e",
+ ADD PRIMARY KEY (order_hash_hex, exchange_address, source_url);
+ `,
+ );
+
+ await queryRunner.query(
+ `CREATE TABLE raw.sra_orders_observed_timestamps (
+ order_hash_hex varchar NOT NULL,
+ exchange_address varchar NOT NULL,
+ source_url varchar NOT NULL,
+ observed_timestamp bigint NOT NULL,
+ FOREIGN KEY
+ (order_hash_hex, exchange_address, source_url)
+ REFERENCES raw.sra_orders (order_hash_hex, exchange_address, source_url),
+ PRIMARY KEY (order_hash_hex, exchange_address, source_url, observed_timestamp)
+ );`,
+ );
+
+ await queryRunner.query(
+ `ALTER TABLE raw.sra_orders
+ DROP COLUMN last_updated_timestamp,
+ DROP COLUMN first_seen_timestamp;`,
+ );
+ }
+
+ public async down(queryRunner: QueryRunner): Promise<any> {
+ await queryRunner.dropTable('raw.sra_orders_observed_timestamps');
+
+ await queryRunner.query(
+ `ALTER TABLE raw.sra_orders
+ ADD COLUMN last_updated_timestamp bigint NOT NULL DEFAULT 0,
+ ADD COLUMN first_seen_timestamp bigint NOT NULL DEFAULT 0;`,
+ );
+
+ await queryRunner.query(
+ `ALTER TABLE raw.sra_orders
+ DROP CONSTRAINT sra_orders_pkey,
+ ADD CONSTRAINT "PK_09bfb9980715329563bd53d667e" PRIMARY KEY ("exchange_address", "order_hash_hex");
+ `,
+ );
+ }
+}
diff --git a/packages/pipeline/src/entities/sra_order.ts b/packages/pipeline/src/entities/sra_order.ts
index e59161c81..4b7f652d3 100644
--- a/packages/pipeline/src/entities/sra_order.ts
+++ b/packages/pipeline/src/entities/sra_order.ts
@@ -8,13 +8,8 @@ export class SraOrder {
public exchangeAddress!: string;
@PrimaryColumn({ name: 'order_hash_hex' })
public orderHashHex!: string;
-
- @Column({ name: 'source_url' })
+ @PrimaryColumn({ name: 'source_url' })
public sourceUrl!: string;
- @Column({ name: 'last_updated_timestamp' })
- public lastUpdatedTimestamp!: number;
- @Column({ name: 'first_seen_timestamp' })
- public firstSeenTimestamp!: number;
@Column({ name: 'maker_address' })
public makerAddress!: string;