You are right - precompiling assets started before database migration. Adding your code above to the before_bundle_exec hook worked. Thanks a lot for your help!
I had to modify it slightly to get it executed properly. My hook for multi site looks like this now:
before_bundle_exec:
- file:
path: $home/config/multisite.yml
contents: |
# (your multisite.yml config here)
- exec: cd /var/www/discourse && sudo -E -u discourse bundle install --deployment --verbose --without test --without development
- exec: cd /var/www/discourse && sudo -E -u discourse bundle exec rake multisite:migrate
Should I consider this as a one time workaround or can this two exec stay forever in my template file?