async upgradeIfNeeded() {
    const botMasterTable = new BotMasterTable(this);
    const defaultValue = FirstManagedDbVersion;
    let savedVersion = defaultValue;
    try {
      savedVersion = await botMasterTable.getSetting(BotMasterTable.MASTER_SETTINGS.dbVersion, defaultValue);
    } catch (e) {
      this.context.log.w(botMasterTable.getTableName() + ' does not exist yet.' +
        ' Assuming we have version ' + FirstManagedDbVersion);
      savedVersion = defaultValue;
    }

    this.context.log.i('Saved DB version: ' + savedVersion + '; current DB version: ' + CurrentDbVersion);

    if (savedVersion > CurrentDbVersion) {
      throw new Error('Downgraing the database is not supported');
    }

    const startVersion = savedVersion;

    while (savedVersion < CurrentDbVersion) {
      this.context.log.w('Trying to upgrade the DB to version: ' + (savedVersion + 1));
      switch (savedVersion) {
        case 3:
          {
            const tablesKeys = Object.keys(Tables);
            const initResults = [];
            for (const key of tablesKeys) {
              const tableToProcess = new Tables[key](this);
              initResults.push(this.dbo.createCollection(tableToProcess.getTableName())
                .then(tableToProcess.dropIndexes()));
            }

            await Promise.all(initResults);
          }
          break;
        default:
          break;
      }
      savedVersion++;
      this.context.log.w('Successfully upgraded the DB to version: ' + savedVersion);
    }

    if (startVersion !== savedVersion) {
      await botMasterTable.setSetting(BotMasterTable.MASTER_SETTINGS.dbVersion, savedVersion);
    }
  }
/**
   * Compares the last saved version number of the DB model, and if it is below the current DB version -
   * performs the upgrade.
   * Throws error if trying to downgrade the DB (not supported).
   * @throws Error
   * @return {Promise} nothing
   */
Compares the last saved version number of the DB model, and if it is below the current DB version
performs the upgrade.
Throws error if trying to downgrade the DB (not supported).
@throws Error
@return {Promise} nothing
Compares the last saved version number of the DB model and if it is below the current DB version performs the upgrade . Throws error if trying to downgrade the DB ( not supported ) . @throws Error @return { Promise } nothing
async upgradeIfNeeded() {
    const botMasterTable = new BotMasterTable(this);
    const defaultValue = FirstManagedDbVersion;
    let savedVersion = defaultValue;
    try {
      savedVersion = await botMasterTable.getSetting(BotMasterTable.MASTER_SETTINGS.dbVersion, defaultValue);
    } catch (e) {
      this.context.log.w(botMasterTable.getTableName() + ' does not exist yet.' +
        ' Assuming we have version ' + FirstManagedDbVersion);
      savedVersion = defaultValue;
    }
    this.context.log.i('Saved DB version: ' + savedVersion + '; current DB version: ' + CurrentDbVersion);
    if (savedVersion > CurrentDbVersion) {
      throw new Error('Downgraing the database is not supported');
    }
    const startVersion = savedVersion;
    while (savedVersion < CurrentDbVersion) {
      this.context.log.w('Trying to upgrade the DB to version: ' + (savedVersion + 1));
      switch (savedVersion) {
        case 3:
          {
            const tablesKeys = Object.keys(Tables);
            const initResults = [];
            for (const key of tablesKeys) {
              const tableToProcess = new Tables[key](this);
              initResults.push(this.dbo.createCollection(tableToProcess.getTableName())
                .then(tableToProcess.dropIndexes()));
            }
            await Promise.all(initResults);
          }
          break;
        default:
          break;
      }
      savedVersion++;
      this.context.log.w('Successfully upgraded the DB to version: ' + savedVersion);
    }
    if (startVersion !== savedVersion) {
      await botMasterTable.setSetting(BotMasterTable.MASTER_SETTINGS.dbVersion, savedVersion);
    }
  }
async upgradeIfNeeded ( ) { const botMasterTable = new BotMasterTable ( this ) ; const defaultValue = FirstManagedDbVersion ; let savedVersion = defaultValue ; try { savedVersion = await botMasterTable . getSetting ( BotMasterTable . MASTER_SETTINGS . dbVersion , defaultValue ) ; } catch ( e ) { this . context . log . w ( botMasterTable . getTableName ( ) + ' does not exist yet.' + ' Assuming we have version ' + FirstManagedDbVersion ) ; savedVersion = defaultValue ; } this . context . log . i ( 'Saved DB version: ' + savedVersion + '; current DB version: ' + CurrentDbVersion ) ; if ( savedVersion > CurrentDbVersion ) { throw new Error ( 'Downgraing the database is not supported' ) ; } const startVersion = savedVersion ; while ( savedVersion < CurrentDbVersion ) { this . context . log . w ( 'Trying to upgrade the DB to version: ' + ( savedVersion + 1 ) ) ; switch ( savedVersion ) { case 3 : { const tablesKeys = Object . keys ( Tables ) ; const initResults = [ ] ; for ( const key of tablesKeys ) { const tableToProcess = new Tables [ key ] ( this ) ; initResults . push ( this . dbo . createCollection ( tableToProcess . getTableName ( ) ) . then ( tableToProcess . dropIndexes ( ) ) ) ; } await Promise . all ( initResults ) ; } break ; default : break ; } savedVersion ++ ; this . context . log . w ( 'Successfully upgraded the DB to version: ' + savedVersion ) ; } if ( startVersion !== savedVersion ) { await botMasterTable . setSetting ( BotMasterTable . MASTER_SETTINGS . dbVersion , savedVersion ) ; } }
Compares the last saved version number of the DB model, and if it is below the current DB version
 performs the upgrade.
Compares the last saved version number of the DB model and if it is below the current DB version performs the upgrade .