Skip to content

Commit

Permalink
feat: add totalBalance to address entity
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Sep 3, 2019
1 parent a952152 commit 5746438
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export default class Address extends BaseEntity {
@Column()
pendingBalance: string = '0'

@Column()
totalBalance: string = '0'

public balance = (): string => {
return (BigInt(this.liveBalance) + BigInt(this.sentBalance)).toString()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export class extendBalance1562126909151 implements MigrationInterface {
}

public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.dropColumn('transaction', 'sentBalance')
await queryRunner.dropColumn('transaction', 'pendingBalance')
await queryRunner.dropColumn('address', 'sentBalance')
await queryRunner.dropColumn('address', 'pendingBalance')
await queryRunner.changeColumn('address', 'liveBalance', new TableColumn({
name: 'balance',
type: 'varchar',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {MigrationInterface, QueryRunner, TableColumn} from "typeorm";

export class AddTotalBalance1567485550388 implements MigrationInterface {

public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.addColumn('address', new TableColumn({
name: 'totalBalance',
type: 'varchar',
default: '0',
}))
}

public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.dropColumn('address', 'totalBalance')
}

}
3 changes: 2 additions & 1 deletion packages/neuron-wallet/src/database/address/ormconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Address from './entities/address'

import { AddAddress1561461669542 } from './migrations/1561461669542-AddAddress'
import { extendBalance1562126909151 } from './migrations/1562126909151-extendBalance'
import { AddTotalBalance1567485550388 } from './migrations/1567485550388-AddTotalBalance'

const dbPath = path.join(env.fileBasePath, 'address.sqlite')

Expand All @@ -20,7 +21,7 @@ const connectOptions = (): SqliteConnectionOptions => {
type: 'sqlite',
database,
entities: [Address],
migrations: [AddAddress1561461669542, extendBalance1562126909151],
migrations: [AddAddress1561461669542, extendBalance1562126909151, AddTotalBalance1567485550388],
synchronize: false,
migrationsRun: true,
logging: ['error'],
Expand Down

0 comments on commit 5746438

Please sign in to comment.