def migrate(dry_run=False): investments = InvestmentAgreement.query().fetch(1000) # type: list[InvestmentAgreement] updates = {} for investment in investments: new_status = INVESTMENT_TODO_MAPPING[investment.status] if investment.app_user not in updates or updates[investment.app_user] < new_status: updates[investment.app_user] = INVESTMENT_TODO_MAPPING[investment.status] if dry_run: return updates for app_user, step in updates.iteritems(): email, app_id = get_app_user_tuple(app_user) deferred.defer(update_investor_progress, email.email(), app_id, step)
def fix_investments(): investments = InvestmentAgreement.query().filter( InvestmentAgreement.status > InvestmentAgreement.STATUS_CANCELED) to_put = [] to_fix = [] for agreement in investments: # type: InvestmentAgreement if not agreement.token_count: if not agreement.iyo_see_id: _set_token_count(agreement) to_put.append(agreement) elif agreement.currency != 'BTC': to_fix.append(agreement.id) ndb.put_multi(to_put) logging.warn('These investment agreements need manual migration: %s', to_fix)
def _get_investment_agreements(): return InvestmentAgreement.query()