anchor.diff:  %% @end
   %%--------------------------------------------------------------------
   -spec terminate(term(), gen_changes_state()) -> ok.
  -terminate(Reason, _State) ->
  +terminate(Reason, #{db_gateways := Gateways}) ->
       ?warning("~p terminating with reason ~p~n", [?MODULE, Reason]),
  +    Gateways = maps:values(Gateways),
  +    lists:foreach(
  +        fun(#{server := Pid}) ->
  +            Pid ! stop
  +        end, Gateways),
  +
       ok.
   
   
  
positive.code:     end.
  
  force_save(#model_config{bucket = Bucket} = _ModelConfig, #document{key = Key, rev = {Start, Ids} = Revs, value = Value}) ->
      case byte_size(term_to_binary(Value)) > 512 * 1024 of
          true -> error(term_to_big);
          false -> ok
      end,
  
      {Props} = to_json_term(Value),
      Doc = {[{<<"_revisions">>, {[{<<"ids">>, Ids}, {<<"start">>, Start}]}}, {<<"_rev">>, rev_info_to_rev(Revs)}, {<<"_id">>, to_driver_key(Bucket, Key)} | Props]},
  
negative.code: rev_info_to_rev({Num, [_Hash | _] = Revs}) when is_integer(Num) ->
      rev_info_to_rev({integer_to_binary(Num), Revs});
  rev_info_to_rev({NumBin, [Hash | _]}) when is_binary(NumBin) ->
      <<NumBin/binary, "-", Hash/binary>>.
  
  
  %%--------------------------------------------------------------------
  %% @private
  %% @doc
  %% Ensure that given term does not exceed maximum document's value size.
  %% @end
  %%--------------------------------------------------------------------
  -spec assert_value_size(Value :: term()) -> ok | no_return().
  assert_value_size(Value) ->
      case byte_size(term_to_binary(Value)) > ?MAX_VALUE_SIZE of
          true -> error(term_to_big);
          false -> ok
      end.