Skip to content

Commit

Permalink
add unique denom, explorer_id in asset table
Browse files Browse the repository at this point in the history
  • Loading branch information
duonghb53 committed Nov 11, 2024
1 parent 8574f1f commit 6fad66c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/asset/repositories/assets.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class AssetsRepository extends Repository<Asset> {
.insert()
.into(Asset)
.values(listAsset)
.orUpdate(['total_supply', 'type'], ['denom'])
.orUpdate(['total_supply', 'type'], ['denom', 'explorer_id'])
.orIgnore()
.execute();
}
Expand Down
23 changes: 23 additions & 0 deletions src/migrations/1731292627732-add-unique-explorer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class addUniqueExplorer1731292627732 implements MigrationInterface {
name = 'addUniqueExplorer1731292627732';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DROP INDEX \`IDX_dfaa8912e3a864dae14becfe74\` ON \`asset\``,
);
await queryRunner.query(
`CREATE UNIQUE INDEX \`IDX_caab7846c80a2a9f5ed9d515d8\` ON \`asset\` (\`denom\`, \`explorer_id\`)`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DROP INDEX \`IDX_caab7846c80a2a9f5ed9d515d8\` ON \`asset\``,
);
await queryRunner.query(
`CREATE UNIQUE INDEX \`IDX_dfaa8912e3a864dae14becfe74\` ON \`asset\` (\`denom\`)`,
);
}
}
2 changes: 1 addition & 1 deletion src/shared/entities/asset.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { TokenHolderStatistic } from './token-holder-statistic.entity';
import { Explorer } from './explorer.entity';

@Entity('asset')
@Unique(['denom'])
@Unique(['denom', 'explorer'])
export class Asset extends BaseEntityIncrementId {
@Column({ name: 'coin_id', nullable: true, default: '' })
coinId: string;
Expand Down

0 comments on commit 6fad66c

Please sign in to comment.