BEGIN;

ALTER TABLE usage_periods
  ADD COLUMN IF NOT EXISTS bonus_units INTEGER NOT NULL DEFAULT 0;

UPDATE usage_periods
SET bonus_units = bonus_units + ABS(used_units),
    used_units = 0
WHERE used_units < 0;

COMMIT;
