From 1036f76742f3742a6f4d90c4cb1a7d250851168a Mon Sep 17 00:00:00 2001 From: ttt161 Date: Fri, 10 Apr 2026 14:00:14 +0300 Subject: [PATCH 1/2] fix sequence migration --- .../sequence/1770994589112-copy-sequence.erl | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/apps/bender/priv/migrations/sequence/1770994589112-copy-sequence.erl b/apps/bender/priv/migrations/sequence/1770994589112-copy-sequence.erl index 0aae543..d0bba0b 100644 --- a/apps/bender/priv/migrations/sequence/1770994589112-copy-sequence.erl +++ b/apps/bender/priv/migrations/sequence/1770994589112-copy-sequence.erl @@ -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 @@ -31,3 +39,19 @@ perform_batch(Connection, Offset, Limit) -> ), perform_batch(Connection, Offset + erlang:length(Rows), Limit) end. + +value(ID, null) -> + logger:warning("migration. 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("migration. sequence ~p bad state: ~p", [ID, BadState]), + {error, bad_state} + catch + _Error:_Term:_Stack -> + logger:warning("migration. sequence ~p bad state: ~p", [ID, AuxState]), + {error, bad_state} + end. From d5529fadcc6ca1e9199b9e6b11d37fc925eeaf96 Mon Sep 17 00:00:00 2001 From: ttt161 Date: Fri, 10 Apr 2026 14:44:39 +0300 Subject: [PATCH 2/2] fix logs --- .../migrations/sequence/1770994589112-copy-sequence.erl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/bender/priv/migrations/sequence/1770994589112-copy-sequence.erl b/apps/bender/priv/migrations/sequence/1770994589112-copy-sequence.erl index d0bba0b..5599bcd 100644 --- a/apps/bender/priv/migrations/sequence/1770994589112-copy-sequence.erl +++ b/apps/bender/priv/migrations/sequence/1770994589112-copy-sequence.erl @@ -41,17 +41,17 @@ perform_batch(Connection, Offset, Limit) -> end. value(ID, null) -> - logger:warning("migration. sequence ~p state is null", [ID]), + 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("migration. sequence ~p bad state: ~p", [ID, BadState]), + logger:warning("migrations. sequence ~p bad state: ~p", [ID, BadState]), {error, bad_state} catch _Error:_Term:_Stack -> - logger:warning("migration. sequence ~p bad state: ~p", [ID, AuxState]), + logger:warning("migrations. sequence ~p bad state: ~p", [ID, AuxState]), {error, bad_state} end.