More robuset cache creation

During migration we can't be sure that save of AR objects will succeed
because they could have changed already. Therefore we register a rake
task to be executed after db:migrate finishes to calculate the cache. We
use Setting flag because some other migration may fail and cancel the
cache creation. If we ran migrations for second time registration
wouldn't happen. We also check this flag every time foreman is
started and calculate cache if needed.