Skip to content

Commit

Permalink
change db default to number type
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryfan01234 committed Aug 28, 2024
1 parent d5f035f commit c9e4411
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ describe('Wallet store', () => {
await WalletTable.upsert({
...defaultWallet2,
isWhitelistAffiliate: true,
totalVolume: '100',
totalVolume: '100.1',
});
wallet = await WalletTable.findById(defaultWallet2.address);

expect(wallet).toEqual(expect.objectContaining({
...defaultWallet2,
isWhitelistAffiliate: true,
totalVolume: '100',
totalVolume: '100.1',
}));
});

Expand Down Expand Up @@ -78,8 +78,8 @@ describe('Wallet store', () => {
it('Successfully finds wallets by whitelist flag', async () => {
await Promise.all([
WalletTable.create(defaultWallet3),
WalletTable.create(defaultWallet2)
])
WalletTable.create(defaultWallet2),
]);

const wallets: WalletFromDatabase[] = await WalletTable.findAll(
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import * as Knex from "knex";

import * as Knex from 'knex';

export async function up(knex: Knex): Promise<void> {
return knex
.schema
.alterTable('wallets', (table) => {
table.decimal('totalVolume', null).defaultTo('0').notNullable();
table.decimal('totalVolume', null).defaultTo(0).notNullable();
table.boolean('isWhitelistAffiliate').defaultTo(false).notNullable();
});
}
Expand All @@ -18,5 +17,3 @@ export async function down(knex: Knex): Promise<void> {
table.dropColumn('isWhitelistAffiliate');
});
}


17 changes: 16 additions & 1 deletion indexer/packages/postgres/src/models/wallet-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,26 @@ export default class WalletModel extends BaseModel {
address: { type: 'string' },
totalTradingRewards: { type: 'string', pattern: NonNegativeNumericPattern },
totalVolume: { type: 'string', pattern: NonNegativeNumericPattern },
isWhitelistAffiliate: { type: 'boolean'},
isWhitelistAffiliate: { type: 'boolean' },
},
};
}

/**
* A mapping from column name to JSON conversion expected.
* See getSqlConversionForDydxModelTypes for valid conversions.
*
* TODO(IND-239): Ensure that jsonSchema() / sqlToJsonConversions() / model fields match.
*/
static get sqlToJsonConversions() {
return {
address: 'string',
totalTradingRewards: 'string',
totalVolume: 'string',
isWhitelistAffiliate: 'boolean',
};
}

QueryBuilderType!: UpsertQueryBuilder<this>;

address!: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1173,4 +1173,4 @@ describe('transfers-controller#V4', () => {
);
});
});
});
});

0 comments on commit c9e4411

Please sign in to comment.