anchor.diff:       {set, PortServersK, NewPSDefaults},
        {set, McdKey, NewMcdConfig},
        {set, JTKey, {NewJsonTemplateConfig}}].
  -
  -search_sub_key(Config, Key, Subkey) ->
  -    case ns_config:search(Config, Key) of
  -        false ->
  -            false;
  -        {value, List} ->
  -            case lists:keyfind(Subkey, 1, List) of
  -                false ->
  -                    false;
  -                {Subkey, X} ->
  -                    X
  -            end
  -    end.
  -
  -upgrade_if_equals(Config, DefaultConfig, Key, Subkey, Value) ->
  -    Upgrade = case search_sub_key(Config, Key, Subkey) of
  -                  false ->
  -                      true;
  -                  X ->
  -                      X =:= Value
  -              end,
  -    case Upgrade of
  -        true ->
  -            {_, UpgradeValue} = lists:keyfind(Key, 1, DefaultConfig),
  -            [{set, Key, UpgradeValue}];
  -        false ->
  -            []
  -    end.
  -
  -do_upgrade_config_from_2_0_to_2_2_0(Config, DefaultConfig, DataDir) ->
  -    OldDataDir = filename:join(DataDir, "data"),
  -
  -    OldVersionPwFile = filename:join(OldDataDir, ?ISASL_PW),
  -    OldVersionNsLog = filename:join(OldDataDir, ?NS_LOG),
  -
  -    MayBePwFile = upgrade_if_equals(Config, DefaultConfig, {node, node(), isasl}, path,
  -                                    OldVersionPwFile),
  -    MayBeNsLog = upgrade_if_equals(Config, DefaultConfig, {node, node(), ns_log}, filename,
  -                                   OldVersionNsLog),
  -
  -    MayBePwFile ++ MayBeNsLog.
  -
  -delete_file(Filename) ->
  -    case file:delete(Filename) of
  -        {error,enoent} ->
  -            ok;
  -        ok ->
  -            ok;
  -        Err ->
  -            ?log_error("Cannot delete file ~p. Error: ~p", [Filename, Err]),
  -            Err
  -    end.
  -
  -rename_file(Source, Dest) ->
  -    case file:rename(Source, Dest) of
  -        {error,enoent} ->
  -            ok;
  -        ok ->
  -            ok;
  -        Err ->
  -            ?log_error("Cannot rename file from ~p to ~p. Error: ~p", [Source, Dest, Err]),
  -            Err
  -    end.
  -
  -do_upgrade_files_from_2_0_to_2_2_0(DataDir) ->
  -    OldDataDir = filename:join(DataDir, "data"),
  -
  -    %% this file will be regenerated, so just delete it
  -    %% from the old location if it is there
  -    OldVersionPwFile = filename:join(OldDataDir, ?ISASL_PW),
  -    delete_file(OldVersionPwFile),
  -
  -    OldVersionNsLog = filename:join(OldDataDir, ?NS_LOG),
  -    NsLog = filename:join(DataDir, ?NS_LOG),
  -
  -    case filelib:is_file(NsLog) of
  -        true ->
  -            delete_file(OldVersionNsLog);
  -        false ->
  -            rename_file(OldVersionNsLog, NsLog)
  -    end.
  -
  -upgrade_1_7_1_to_1_7_2_test() ->
  -    DefaultCfg = [{rest, [{port, 8091}]},
  -                  {{node, node(), rest},
  -                   [{port, 8091},
  -                    {port_meta, global}]}],
  -
  -    OldCfg0 = [{nodes_wanted, [node()]},
  -               {{node, node(), rest}, [{port, 9000}]}],
  -    Ref0 = [{set, rest, [{port, 9000}]},
  -            {set, {node, node(), rest},
  -             [{port, 9000},
  -              {port_meta, global}]}],
  -
  -    Res0 = do_upgrade_config_from_1_7_1_to_1_7_2([OldCfg0], DefaultCfg),
  -    ?assertEqual(lists:sort(Ref0), lists:sort(Res0)),
  -
  -
  -    OldCfg1 = [],
  -    Ref1 = [{set, rest, [{port, 8091}]},
  -            {set, {node, node(), rest},
  -             [{port, 8091},
  -              {port_meta, global}]}],
  -
  -    Res1 = do_upgrade_config_from_1_7_1_to_1_7_2([OldCfg1], DefaultCfg),
  -    ?assertEqual(lists:sort(Ref1), lists:sort(Res1)),
  -
  -    OldCfg2 = [{nodes_wanted, [node(), other_node]},
  -               {{node, node(), rest}, [{port, 9000}]},
  -               {{node, other_node, rest}, [{port, 9001}]}],
  -    Ref2 = [{set, rest, [{port, 8091}]},
  -            {set, {node, node(), rest},
  -             [{port, 9000}, {port_meta, local}]}],
  -
  -    Res2 = do_upgrade_config_from_1_7_1_to_1_7_2([OldCfg2], DefaultCfg),
  -    ?assertEqual(lists:sort(Ref2), lists:sort(Res2)),
  -
  -    OldCfg3 = [{nodes_wanted, [node(), other_node]},
  -               {{node, node(), rest}, [{port, 9000}]},
  -               {{node, other_node, rest}, [{port, 9000}]}],
  -    Ref3 = [{set, rest, [{port, 9000}]},
  -            {set, {node, node(), rest},
  -             [{port, 9000},
  -              {port_meta, global}]}],
  -
  -    Res3 = do_upgrade_config_from_1_7_1_to_1_7_2([OldCfg3], DefaultCfg),
  -    ?assertEqual(lists:sort(Ref3), lists:sort(Res3)),
  -
  -    OldCfg4 = [{nodes_wanted, [node(), other_node]},
  -               {rest, [{port, 9000}]},
  -               {{node, node(), rest}, [{port, 9000}]},
  -               {{node, other_node, rest},
  -                [{port, 9000}, {port_meta, global}]}],
  -    Ref4 = [{set, rest, [{port, 9000}]},
  -            {set, {node, node(), rest},
  -             [{port, 9000},
  -              {port_meta, global}]}],
  -
  -    Res4 = do_upgrade_config_from_1_7_1_to_1_7_2([OldCfg4], DefaultCfg),
  -    ?assertEqual(lists:sort(Ref4), lists:sort(Res4)).
  -
  -upgrade_1_7_2_to_1_8_0_test() ->
  -    DefaultCfg = [{{node, node(), port_servers},
  -                   [{moxi, "/opt/couchbase/bin/moxi something"},
  -                    {memcached, "/opt/couchbase/bin/memcached something"}]}],
  -
  -    OldCfg0 = [{nodes_wanted, [node()]},
  -               {{node, node(), rest}, [{port, 9000}]},
  -               {port_servers, [{moxi, "moxi something"},
  -                               {memcached, "memcached something"}]}],
  -    Res0 = do_upgrade_config_from_1_7_2_to_1_8_0([OldCfg0], DefaultCfg),
  -    ?assertEqual([{set, {node, node(), port_servers},
  -                   [{moxi, "/opt/couchbase/bin/moxi something"},
  -                    {memcached, "/opt/couchbase/bin/memcached something"}]}],
  -                   lists:sort(Res0)),
  -
  -    OldCfg1 = [{{node,node(),memcached},
  -                [{dbdir,"/opt/membase/var/lib/membase/data"},
  -                 {port,11210},
  -                 {bucket_engine,"/opt/membase/lib/memcached/bucket_engine.so"},
  -                 {engines,
  -                  [{membase,
  -                    [{engine,"/opt/membase/lib/memcached/ep.so"},
  -                     {initfile,"/opt/membase/etc/membase/init.sql"},
  -                     {static_config_string,"foo"}]},
  -                   {memcached,
  -                    [{engine,"/opt/membase/lib/memcached/default_engine.so"},
  -                     {static_config_string,"bar"}]}]},
  -                 {verbosity,[]}]},
  -               {otp,[{cookie,shouldnotbechanged}]},
  -               {directory,"/opt/membase/var/lib/membase/config"},
  -               {port_servers, [{moxi, "/opt/membase/bin/moxi something"},
  -                               {memcached,
  -                                "/opt/membase/bin/memcached something"}]}],
  -    RefCfg1 = [{set, {node,node(),memcached},
  -                [{dbdir,"/opt/membase/var/lib/membase/data"},
  -                 {port,11210},
  -                 {bucket_engine,"/opt/couchbase/lib/memcached/bucket_engine.so"},
  -                 {engines,
  -                  [{membase,
  -                    [{engine,"/opt/couchbase/lib/memcached/ep.so"},
  -                     {initfile,"/opt/couchbase/etc/membase/init.sql"},
  -                     {static_config_string,"foo"}]},
  -                   {memcached,
  -                    [{engine,"/opt/couchbase/lib/memcached/default_engine.so"},
  -                     {static_config_string,"bar"}]}]},
  -                 {verbosity,[]}]},
  -               {set, {node, node(), port_servers},
  -                [{moxi, "/opt/couchbase/bin/moxi something"},
  -                 {memcached, "/opt/couchbase/bin/memcached something"}]}],
  -    Res1 = do_upgrade_config_from_1_7_2_to_1_8_0([OldCfg1], DefaultCfg),
  -    ?assertEqual(lists:sort(RefCfg1), lists:sort(Res1)),
  -
  -    OldCfg2 = [{nodes_wanted, [node()]},
  -               {{node, node(), rest}, [{port, 9000}]}],
  -    Res2 = do_upgrade_config_from_1_7_2_to_1_8_0([OldCfg2], DefaultCfg),
  -    ?assertEqual([{set, {node, node(), port_servers},
  -                   [{moxi, "/opt/couchbase/bin/moxi something"},
  -                    {memcached, "/opt/couchbase/bin/memcached something"}]}],
  -                 lists:sort(Res2)),
  -    ok.
  -
  -update_binaries_cfg_pathes_and_add_dedicated_port_test() ->
  -    DefaultCfg = [{{node, node(), port_servers}, default_port_servers},
  -                  {{node, node(), isasl}, default_isasl},
  -                  {{node, node(), ns_log}, ns_log_default},
  -                  {something_else, else_something},
  -                  {{node, node(), memcached},
  -                   [{dedicated_port, 1234},
  -                    {port, 1235},
  -                    {other_crap, crap},
  -                    {bucket_engine, new_bucketen_cfg},
  -                    {engines, new_engines_cfg}]}],
  -    OldCfg1 = [[{memcached, [{bucket_engine, old_bucketen_cfg},
  -                             {some_field, field_some},
  -                             {engines, old_engines_cfg}]}]],
  -    RV = lists:sort(update_binaries_cfg_pathes_and_add_dedicated_port(OldCfg1, DefaultCfg)),
  -    ?assertEqual(lists:sort(
  -                   [{set, {node, node(), port_servers}, default_port_servers},
  -                    {set, {node, node(), isasl}, default_isasl},
  -                    {set, {node, node(), ns_log}, ns_log_default},
  -                    {set, {node, node(), memcached}, [{dedicated_port, 1234},
  -                                                      {bucket_engine, new_bucketen_cfg},
  -                                                      {engines, new_engines_cfg},
  -                                                      {some_field, field_some}]}]),
  -                 RV),
  -    ok.
  -
  -upgrade_1_8_1_to_2_0_test() ->
  -    Cfg = [[{{node, node(), capi_port}, something},
  -            {remote_clusters, foobar},
  -            {{node, node(), memcached}, [{engines, old_engines},
  -                                         {something, something}]},
  -            {{node, node(), port_servers}, old_port_servers}]],
  -    DefaultCfg = [{{node, node(), capi_port}, somethingelse},
  -                  {remote_clusters, foobar_2},
  -                  {autocompaction, compaction_something},
  -                  {{node, node(), compaction_daemon}, compaction_daemon_settings},
  -                  {{node, node(), memcached},
  -                   [{log_path, log_path},
  -                    {log_prefix, log_prefix},
  -                    {log_generations, log_generations},
  -                    {log_rotation_period, log_rotation_period},
  -                    {engines, new_engines},
  -                    {something_else, something_else}]},
  -                  {{node, node(), port_servers}, new_port_servers}],
  -    Result = do_upgrade_config_from_1_8_1_to_2_0(Cfg, DefaultCfg),
  -    ?assertEqual([{set, autocompaction, compaction_something},
  -                  {set, {node, node(), compaction_daemon}, compaction_daemon_settings},
  -                  {set, {node, node(), memcached},
  -                   [{log_path, log_path},
  -                    {log_prefix, log_prefix},
  -                    {log_generations, log_generations},
  -                    {log_rotation_period, log_rotation_period},
  -                    {engines, new_engines},
  -                    {something, something}]},
  -                  {set, {node, node(), port_servers}, new_port_servers}],
  -                 Result),
  -    Cfg2 = [[{remote_clusters, foobar},
  -             {{node, node(), compaction_daemon}, compaction_daemon_existing},
  -             {{node, node(), memcached}, [{something, something}]}]],
  -    Result2 = do_upgrade_config_from_1_8_1_to_2_0(Cfg2, DefaultCfg),
  -    ?assertEqual([{set, {node, node(), capi_port}, somethingelse},
  -                  {set, autocompaction, compaction_something},
  -                  {set, {node, node(), memcached},
  -                   [{log_path, log_path},
  -                    {log_prefix, log_prefix},
  -                    {log_generations, log_generations},
  -                    {log_rotation_period, log_rotation_period},
  -                    {engines, new_engines},
  -                    {something, something}]},
  -                  {set, {node, node(), port_servers}, new_port_servers}],
  -                 Result2).
  -
  -upgrade_2_0_to_2_2_0_test() ->
  -    DataDir = "/data/n_0",
  -    OldDataDir = filename:join(DataDir, "data"),
  -    DefaultCfg = [{{node, node(), ns_log}, default_ns_log},
  -                  {{node, node(), isasl}, default_isasl}],
  -    Cfg1 = [[{{node, node(), ns_log}, [{filename, filename:join("/somewhere/else", ?NS_LOG)}]},
  -             {{node, node(), isasl}, [{path, filename:join("/somewhere/else", ?ISASL_PW)}]}
  -            ]],
  -    Result1 = do_upgrade_config_from_2_0_to_2_2_0(Cfg1, DefaultCfg, DataDir),
  -    ?assertEqual([], Result1),
  -
  -    Cfg2 = [[{{node, node(), ns_log}, [{filename, filename:join(OldDataDir, ?NS_LOG)}]},
  -             {{node, node(), isasl}, [{path, filename:join(OldDataDir, ?ISASL_PW)}]}
  -            ]],
  -    Result2 = do_upgrade_config_from_2_0_to_2_2_0(Cfg2, DefaultCfg, DataDir),
  -    ?assertEqual([
  -                  {set, {node, node(), isasl}, default_isasl},
  -                  {set, {node, node(), ns_log}, default_ns_log}
  -                 ], Result2).
  -
  -upgrade_2_2_0_to_2_3_0_test() ->
  -    Key = {node, node(), memcached},
  -    Cfg = [[{Key,
  -           [{log_generations, 10},
  -            {log_cyclesize, 1024*1024*100}]}]],
  -    UpgradedCfg = upgrade_config_from_2_2_0_to_2_3_0(Cfg),
  -    ?assertMatch([{set, Key,
  -                   [{log_generations, 20},
  -                    {log_cyclesize, 1024*1024*10},
  -                    {admin_pass, _}]}], UpgradedCfg).
   
   upgrade_2_3_0_to_3_0_test() ->
       Cfg = [[{some_key, some_value},
  
positive.code:              upgrade_config_from_3_0_2_to_3_0_99(Config)];
          {value, {3,0,99}} ->
              [{set, {node, node(), config_version}, {4,0}} |
               upgrade_config_from_3_0_99_to_4_0(Config)]
      end.
  
  upgrade_config_from_1_7_to_1_7_1() ->
      ?log_info("Upgrading config from 1.7 to 1.7.1"),
      DefaultConfig = default(),
      do_upgrade_config_from_1_7_to_1_7_1(DefaultConfig).
  
  do_upgrade_config_from_1_7_to_1_7_1(DefaultConfig) ->
      {email_alerts, Alerts} = lists:keyfind(email_alerts, 1, DefaultConfig),
      {auto_failover_cfg, AutoFailover} = lists:keyfind(auto_failover_cfg, 1, DefaultConfig),
      [{set, email_alerts, Alerts},
       {set, auto_failover_cfg, AutoFailover}].
  
  upgrade_config_from_1_7_1_to_1_7_2(Config) ->
      ?log_info("Upgrading config from 1.7.1 to 1.7.2"),
      DefaultConfig = default(),
      do_upgrade_config_from_1_7_1_to_1_7_2(Config, DefaultConfig).
  
  do_upgrade_config_from_1_7_1_to_1_7_2(Config, DefaultConfig) ->
      RestConfig = case ns_config:search_node(Config, rest) of
                       false -> [];
                       {value, RestConfigX} -> RestConfigX
                   end,
  
      NeedRestUpgrade = lists:keysearch(port_meta, 1, RestConfig) =:= false,
      case NeedRestUpgrade of
          true -> do_upgrade_rest_port_config_from_1_7_1_to_1_7_2(Config, DefaultConfig);
          _ -> []
      end.
  
  do_upgrade_rest_port_config_from_1_7_1_to_1_7_2(Config, DefaultConfig) ->
      Node = node(),
      NodesWanted = case ns_config:search(Config, nodes_wanted) of
                        {value, Nodes} -> lists:usort(Nodes);
                        false -> []
                    end,
  
      RestPorts = lists:map(
                    fun (N) ->
                            misc:node_rest_port(Config, N)
                    end,
                    NodesWanted),
  
      {rest, DefaultRest} = lists:keyfind(rest, 1, DefaultConfig),
      {{node, Node, rest}, DefaultNodeRest} =
          lists:keyfind({node, node(), rest}, 1, DefaultConfig),
  
      {RestChangeValue, NodeRestChangeValue} =
          case lists:usort(RestPorts) of
              [] ->
                  ?log_debug("Setting global and node rest port to default"),
                  {DefaultRest, DefaultNodeRest};
              [Port] ->
                  ?log_debug("Setting global and per-node rest port to ~p", [Port]),
                  {[{port, Port}], [{port, Port}, {port_meta, global}]};
              _ ->
                  ?log_debug("Setting global rest port to default "
                             "but keeping per node value "),
                  OurPort = ns_config:search_node_prop(Node, Config, rest, port),
                  {DefaultRest, [{port, OurPort}, {port_meta, local}]}
          end,
  
      RestChange = [{set, rest, RestChangeValue}],
      NodeRestChange = [{set, {node, Node, rest}, NodeRestChangeValue}],
  
      RestChange ++ NodeRestChange.
  
  upgrade_config_from_1_7_2_to_1_8_0(Config) ->
      ?log_info("Upgrading config from 1.7.2 to 1.8.0"),
      DefaultConfig = default(),
      do_upgrade_config_from_1_7_2_to_1_8_0(Config, DefaultConfig).
  
  do_upgrade_config_from_1_7_2_to_1_8_0(Config, DefaultConfig) ->
      ReplaceAllPrefixes =
          fun (V) ->
                  V2 = prefix_replace("/opt/membase/bin/",
                                      "/opt/couchbase/bin/", V),
                  V3 = prefix_replace("/opt/membase/lib/",
                                      "/opt/couchbase/lib/", V2),
                  prefix_replace("/opt/membase/etc/", "/opt/couchbase/etc/", V3)
          end,
  
      %% Note that port_servers value does not contain prefixes that we *don't*
      %% want to replace. This means that we can just take the value from
      %% default config.
      %%
      %% Additionally this enables moxi rest_port fix for the nodes being
      %% updated from previous versions.
      Key = {node, node(), port_servers},
      {Key, DefaultPortServers} = lists:keyfind(Key, 1, DefaultConfig),
      Results = [{set, Key, DefaultPortServers}],
  
      lists:foldl(
        fun ({_K, false}, Acc) -> Acc;
            ({K, {value, V}}, Acc) ->
                V1 = ReplaceAllPrefixes(V),
                case V =:= V1 of
                    true -> Acc;
                    false -> [{set, K, V1} | Acc]
                end
        end,
        Results,
        [{{node, node(), memcached}, ns_config:search_node(Config, memcached)}]).
  
  upgrade_config_from_1_8_0_to_1_8_1(Config) ->
      ?log_info("Upgrading config from 1.8.0 to 1.8.1"),
  
      DefaultConfig = default(),
      do_upgrade_config_from_1_8_0_to_1_8_1(Config, DefaultConfig).
  
  do_upgrade_config_from_1_8_0_to_1_8_1(Config, DefaultConfig) ->
      update_binaries_cfg_pathes_and_add_dedicated_port(Config, DefaultConfig).
  
  update_binaries_cfg_pathes_and_add_dedicated_port(Config, DefaultConfig) ->
      FullReplacements =
          [{set, FullK, V} || {{node, N, K} = FullK, V} <- DefaultConfig,
                          N =:= node(),
                          lists:member(K, [port_servers, isasl, ns_log])],
      McdKey = {node, node(), memcached},
      {value, McdConfig} = ns_config:search_node(Config, memcached),
      StrippedMcdConfig = [Pair || {K, _} = Pair <- McdConfig,
                                   not lists:member(K, [bucket_engine, engines])],
      DedicatedPort = ns_config:search_node_prop(node(), [DefaultConfig], memcached, dedicated_port),
      true = (DedicatedPort =/= undefined),
      {_, DefaultMcdConfig} = lists:keyfind(McdKey, 1, DefaultConfig),
      {_,_} = BucketEnginePair = lists:keyfind(bucket_engine, 1, DefaultMcdConfig),
      {_,_} = EnginesPair = lists:keyfind(engines, 1, DefaultMcdConfig),
      [{set, McdKey, [{dedicated_port, DedicatedPort},
                      BucketEnginePair,
                      EnginesPair
                      | StrippedMcdConfig]}
       | FullReplacements].
  
  upgrade_config_from_1_8_1_to_2_0(Config) ->
      ?log_info("Upgrading config from 1.8.1 to 2.0", []),
      DefaultConfig = default(),
      do_upgrade_config_from_1_8_1_to_2_0(Config, DefaultConfig).
  
  do_upgrade_config_from_1_8_1_to_2_0(Config, DefaultConfig) ->
      MaybeCapiPort = case ns_config:search(Config, {node, node(), capi_port}) of
                          false ->
                              {_, DefaultCapiPort} = lists:keyfind({node, node(), capi_port}, 1, DefaultConfig),
                              [{set, {node, node(), capi_port}, DefaultCapiPort}];
                          _ ->
                              []
                      end,
      MaybeAutoCompaction = case ns_config:search(Config, autocompaction) of
                                {value, _} -> [];
                                false ->
                                    {_, AutoCompactionV} = lists:keyfind(autocompaction, 1, DefaultConfig),
                                    [{set, autocompaction, AutoCompactionV}]
                            end,
      MaybeRemoteClusters = case ns_config:search(Config, remote_clusters) of
                                {value, _} -> [];
                                false ->
                                    {_, RemoteClustersV} = lists:keyfind(remote_clusters, 1, DefaultConfig),
                                    [{set, remote_clusters, RemoteClustersV}]
                            end,
  
      MaybeCompactionDaemon = case ns_config:search(Config, {node, node(), compaction_daemon}) of
                                  {value, _} ->
                                      [];
                                  false ->
                                      {_, CompactionDaemonSettings} = lists:keyfind({node, node(), compaction_daemon},
                                                                                    1, DefaultConfig),
                                      [{set, {node, node(), compaction_daemon}, CompactionDaemonSettings}]
                              end,
  
      MaybeCapiPort ++
          MaybeAutoCompaction ++
          MaybeRemoteClusters ++
          MaybeCompactionDaemon ++
          maybe_upgrade_engines_add_mccouch_port_log_params(Config, DefaultConfig).
  
  maybe_upgrade_engines_add_mccouch_port_log_params(Config, DefaultConfig) ->
      McdKey = {node, node(), memcached},
  
      {value, McdConfig} = ns_config:search(Config, McdKey),
      {value, DefaultMcdConfig} = ns_config:search([DefaultConfig], McdKey),
  
      NewOrUpdatedParams =
          lists:filter(
            fun ({Key, _Value}) ->
                    lists:member(Key, [log_path, log_prefix, log_generations,
                                       log_cyclesize, log_sleeptime,
                                       log_rotation_period,
                                       engines])
            end, DefaultMcdConfig),
  
      StrippedMcdConfig =
          lists:filter(
            fun ({Key, _Value}) ->
                    not lists:keymember(Key, 1, NewOrUpdatedParams)
            end, McdConfig),
  
      PortServersKey = {node, node(), port_servers},
      {value, DefaultPortServers} = ns_config:search([DefaultConfig], PortServersKey),
  
      [{set, McdKey, NewOrUpdatedParams ++ StrippedMcdConfig},
       {set, PortServersKey, DefaultPortServers}].
  
  upgrade_config_from_2_0_to_2_2_0(Config) ->
      ?log_info("Upgrading config from 2.0 to 2.2.0", []),
      DefaultConfig = default(),
      DataDir = get_data_dir(),
      do_upgrade_files_from_2_0_to_2_2_0(DataDir),
      do_upgrade_config_from_2_0_to_2_2_0(Config, DefaultConfig, DataDir).
  
  upgrade_config_from_2_2_0_to_2_3_0(Config) ->
      ?log_info("Upgrading config from 2.2.0 to 2.3.0"),
      {value, MemcachedConfig} = ns_config:search(Config, {node, node(), memcached}),
      MemcachedConfig1 = lists:keystore(log_generations, 1, MemcachedConfig,
                                        {log_generations, 20}),
      MemcachedConfig2 = lists:keystore(log_cyclesize, 1, MemcachedConfig1,
                                        {log_cyclesize, 1024*1024*10}),
  
      UUID = binary_to_list(couch_uuids:random()),
      MemcachedConfig3 = lists:keystore(admin_pass, 1, MemcachedConfig2,
                                        {admin_pass, UUID}),
  
      [{set, {node, node(), memcached}, MemcachedConfig3}].
  
  upgrade_config_from_2_3_0_to_3_0(Config) ->
      ?log_info("Upgrading config from 2.3.0 to 3.0"),
  
negative.code:                 {[], [{log_path, Path}]}
          end,
  
      [{{node, node(), config_version}, get_current_version()},
       {directory, path_config:component_path(data, "config")},
       {{node, node(), is_enterprise}, IsEnterprise},
       {{node, node(), ldap_enabled}, LdapEnabled},
       {index_aware_rebalance_disabled, false},
  