Add stack management

  * Function to update stack application
  * Store stack version in database
Could you comment this function. It's not trivial and requires too much thinking to be understood.