Fixes bug 931907 - Fixed migration script from PSQL to ES.
Merge pull request #1797 from AdrianGaudebert/931907-automatic-emails-with-elasticsearch-fix

Fixes bug 931907 - Fixed migration script from PSQL to ES.
small corrections
full test coverage for setupdb_app except the fakedata