-- Automatic retries for Monnify account creation when Monnify is temporarily unavailable.
ALTER TABLE customers
  ADD COLUMN account_attempts SMALLINT UNSIGNED NOT NULL DEFAULT 0 AFTER account_error,
  ADD COLUMN account_next_retry_at DATETIME NULL AFTER account_attempts,
  ADD KEY ix_customers_account_retry (account_status, account_next_retry_at);

-- Customers already waiting for an account (with a BVN/NIN on file) get retried right away.
UPDATE customers
  SET account_next_retry_at = UTC_TIMESTAMP()
  WHERE account_status <> 'active' AND kyc_encrypted IS NOT NULL;
