'Checks the database version and upgrade if it is not the latest version.'

@blocking_call_on_reactor_thread
@inlineCallbacks
def upgrade_database_to_current_version(self):

    try:
        from Tribler.Core.leveldbstore import LevelDbStore
        torrent_store = LevelDbStore(self.session.config.get_torrent_store_dir())
        torrent_migrator = TorrentMigrator65(self.session.config.get_torrent_collecting_dir(), self.session.config.get_state_dir(), torrent_store=torrent_store, status_update_func=self.update_status)
        (yield torrent_migrator.start_migrate())
        db_migrator = DBUpgrader(self.session, self.db, torrent_store=torrent_store, status_update_func=self.update_status)
        (yield db_migrator.start_migrate())
        self.update_status('Recovering    unregistered    torrents...')
        (yield db_migrator.reimport_torrents())
        (yield torrent_store.close())
        del torrent_store
        self.failed = False
        self.is_done = True
    except Exception as e:
        self._logger.exception(u'failed    to    upgrade:    %s', e)
