Fixed #3055 Correctly detect db_version; fixed gateway setting rewriting