Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ perform_batch(Connection, Offset, Limit) ->
{ok, _, Rows} ->
Values = lists:foldl(
fun
({ID, AuxState}, "") ->
#{value := Value} = binary_to_term(AuxState),
" ('" ++ unicode:characters_to_list(ID) ++ "', " ++ integer_to_list(Value) ++ ") ";
({ID, AuxState}, "" = Acc) ->
case value(ID, AuxState) of
{ok, Value} ->
" ('" ++ unicode:characters_to_list(ID) ++ "', " ++ integer_to_list(Value) ++ ") ";
{error, _} ->
Acc
end;
({ID, AuxState}, Acc) ->
#{value := Value} = binary_to_term(AuxState),
" ('" ++ unicode:characters_to_list(ID) ++ "', " ++ integer_to_list(Value) ++ "), " ++ Acc
case value(ID, AuxState) of
{ok, Value} ->
" ('" ++ unicode:characters_to_list(ID) ++ "', " ++ integer_to_list(Value) ++ "), " ++ Acc;
{error, _} ->
Acc
end
end,
"",
Rows
Expand All @@ -31,3 +39,19 @@ perform_batch(Connection, Offset, Limit) ->
),
perform_batch(Connection, Offset + erlang:length(Rows), Limit)
end.

value(ID, null) ->
logger:warning("migrations. sequence ~p state is null", [ID]),
{error, state_is_null};
value(ID, AuxState) when is_binary(AuxState) ->
try binary_to_term(AuxState) of
#{value := Value} ->
{ok, Value};
BadState ->
logger:warning("migrations. sequence ~p bad state: ~p", [ID, BadState]),
{error, bad_state}
catch
_Error:_Term:_Stack ->
logger:warning("migrations. sequence ~p bad state: ~p", [ID, AuxState]),
{error, bad_state}
end.
Loading