Adding a non interactive command line option for empty database mode,
together with some refactoring(cherry picked from commit 9fa4371c320fbe9f3acdfb9e7a8bd0e066002a46)