Skip to content

Commit

Permalink
Adds migration to create Celo Wrap/Unrwap table for consistency.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrés Elizondo committed Dec 15, 2023
1 parent be1de3f commit fe11294
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions migrations/celo/1702673081360-CreateWrapUnwrapNativeEventsTable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { MigrationInterface, QueryRunner, getConnection } from 'typeorm';

export class CreateCeloWrapNativeEventsTable1702673081360 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
const connection = getConnection();
const { schema } = connection.options as any;
await queryRunner.query(`
CREATE TABLE ${schema}.wrap_native_events (
observed_timestamp int8 NOT NULL,
contract_address varchar NOT NULL,
transaction_hash varchar NOT NULL,
transaction_index int8 NOT NULL,
log_index int8 NOT NULL,
block_hash varchar NOT NULL,
block_number int8 NOT NULL,
dst varchar NOT NULL,
wad numeric NOT NULL,
PRIMARY KEY (transaction_hash, log_index)
);
CREATE INDEX wrap_native_events_block_number_index ON ${schema}.wrap_native_events USING btree (block_number);
CREATE INDEX wrap_native_events_transaction_hash_index ON ${schema}.wrap_native_events USING btree (transaction_hash);
CREATE TABLE ${schema}.unwrap_native_events (
observed_timestamp int8 NOT NULL,
contract_address varchar NOT NULL,
transaction_hash varchar NOT NULL,
transaction_index int8 NOT NULL,
log_index int8 NOT NULL,
block_hash varchar NOT NULL,
block_number int8 NOT NULL,
src varchar NOT NULL,
wad numeric NOT NULL,
PRIMARY KEY (transaction_hash, log_index)
);
CREATE INDEX unwrap_native_events_block_number_index ON ${schema}.unwrap_native_events USING btree (block_number);
CREATE INDEX unwrap_native_events_transaction_hash_index ON ${schema}.unwrap_native_events USING btree (transaction_hash);
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
const connection = getConnection();
const { schema } = connection.options as any;
await queryRunner.query(`DROP TABLE ${schema}.wrap_native_events;`);
await queryRunner.query(`DROP TABLE ${schema}.unwrap_native_events;`);
}
}

0 comments on commit fe11294

Please sign in to comment.