fix app migrations to work with a blank db

http://manage.dimagi.com/default.asp?151013
this is the new stuff, the rest is just unindented