Have migration to maker_address column working
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';
|
||||
|
||||
const TOKEN_ORDERBOOK_SNAPSHOT_TABLE = 'raw.token_orderbook_snapshots';
|
||||
const NEW_COLUMN_NAME = 'maker_address';
|
||||
|
||||
export class TokenOrderBookSnapshotsAddMakerAddress1550017139695 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
const snapshotTable = await queryRunner.getTable(TOKEN_ORDERBOOK_SNAPSHOT_TABLE);
|
||||
if (snapshotTable) {
|
||||
await queryRunner.addColumn(
|
||||
TOKEN_ORDERBOOK_SNAPSHOT_TABLE,
|
||||
new TableColumn({
|
||||
name: NEW_COLUMN_NAME,
|
||||
type: 'varchar',
|
||||
isPrimary: true,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
const snapshotTable = await queryRunner.getTable(TOKEN_ORDERBOOK_SNAPSHOT_TABLE);
|
||||
if (snapshotTable) {
|
||||
await queryRunner.dropColumn(snapshotTable, NEW_COLUMN_NAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';
|
||||
|
||||
const TOKEN_ORDERBOOK_SNAPSHOT_TABLE = 'raw.token_orderbook_snapshots';
|
||||
const NEW_COLUMN_NAME = 'maker_address';
|
||||
|
||||
export class TokenOrderBookSnapshotsAddMakerAddress1550163069315 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
const snapshotTable = await queryRunner.getTable(TOKEN_ORDERBOOK_SNAPSHOT_TABLE);
|
||||
if (snapshotTable) {
|
||||
const newColumn = new TableColumn({
|
||||
name: NEW_COLUMN_NAME,
|
||||
type: 'varchar',
|
||||
isNullable: true,
|
||||
});
|
||||
await queryRunner.addColumn(TOKEN_ORDERBOOK_SNAPSHOT_TABLE, newColumn);
|
||||
// backfill null values
|
||||
await queryRunner.query(`
|
||||
UPDATE ${TOKEN_ORDERBOOK_SNAPSHOT_TABLE}
|
||||
SET ${NEW_COLUMN_NAME}='unknown'
|
||||
WHERE ${NEW_COLUMN_NAME} is NULL;
|
||||
`);
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE ${TOKEN_ORDERBOOK_SNAPSHOT_TABLE}
|
||||
DROP CONSTRAINT "token_orderbook_snapshots_pkey",
|
||||
ADD PRIMARY KEY (observed_timestamp, source, order_type, price, base_asset_symbol, quote_asset_symbol, maker_address);
|
||||
`);
|
||||
}
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
const snapshotTable = await queryRunner.getTable(TOKEN_ORDERBOOK_SNAPSHOT_TABLE);
|
||||
if (snapshotTable) {
|
||||
await queryRunner.dropColumn(snapshotTable, NEW_COLUMN_NAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,14 +15,14 @@ export class TokenOrderbookSnapshot {
|
||||
public price!: BigNumber;
|
||||
@PrimaryColumn({ name: 'base_asset_symbol' })
|
||||
public baseAssetSymbol!: string;
|
||||
@PrimaryColumn({ name: 'quote_asset_symbol' })
|
||||
public quoteAssetSymbol!: string;
|
||||
@PrimaryColumn({ type: String, name: 'maker_address', default: 'unknown' })
|
||||
public makerAddress!: string | null;
|
||||
public makerAddress!: string;
|
||||
@Column({ nullable: true, type: String, name: 'base_asset_address' })
|
||||
public baseAssetAddress!: string | null;
|
||||
@Column({ name: 'base_volume', type: 'numeric', transformer: bigNumberTransformer })
|
||||
public baseVolume!: BigNumber;
|
||||
@PrimaryColumn({ name: 'quote_asset_symbol' })
|
||||
public quoteAssetSymbol!: string;
|
||||
@Column({ nullable: true, type: String, name: 'quote_asset_address' })
|
||||
public quoteAssetAddress!: string | null;
|
||||
@Column({ name: 'quote_volume', type: 'numeric', transformer: bigNumberTransformer })
|
||||
|
||||
@@ -20,7 +20,7 @@ const tokenOrderbookSnapshot: TokenOrderbookSnapshot = {
|
||||
quoteAssetSymbol: 'ABC',
|
||||
quoteAssetAddress: '0x00923b9a074762b93650716333b3e1473a15048e',
|
||||
quoteVolume: new BigNumber(12.3234234),
|
||||
makerAddress: null,
|
||||
makerAddress: 'unknown',
|
||||
};
|
||||
|
||||
describe('TokenOrderbookSnapshot entity', () => {
|
||||
|
||||
Reference in New Issue
Block a user