diff --git a/src/application.ts b/src/application.ts index f71b044f5..1a2bbe124 100644 --- a/src/application.ts +++ b/src/application.ts @@ -243,6 +243,7 @@ export class MyriadApiApplication extends BootMixin( if (options?.existingSchema === 'drop') return this.databaseSeeding(); await Promise.allSettled([ this.doMigrateComment(), + this.doMigrateCurrency(), this.doMigratePost(), this.doMigrateUser(), ]); @@ -641,6 +642,24 @@ export class MyriadApiApplication extends BootMixin( bar.stop(); } + async doMigrateCurrency(): Promise { + if (!this.doCollectionExists('currency')) return; + + const {currencyRepository, userCurrencyRepository} = + await this.repositories(); + const currencies = await currencyRepository.find({ + where: { + networkId: 'myriad', + }, + }); + const currencyIds = currencies.map(currency => currency.id); + + await userCurrencyRepository.deleteAll({ + currencyId: {nin: currencyIds}, + networkId: 'myriad', + }); + } + async repositories(): Promise { const accountSettingRepository = await this.getRepository( AccountSettingRepository,