Skip to content

Commit

Permalink
Merge pull request #2 from onno-vos-dev/fix-dialyzer-issues
Browse files Browse the repository at this point in the history
Fix Dialyzer issues and add step to CI to check Dialyzer
  • Loading branch information
MikhailKalashnikov authored Aug 14, 2022
2 parents 7b66bcd + c2b32f5 commit f8f4a61
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ jobs:
run: make compile
- name: Xref
run: make xref
- name: Dialyzer
run: make dialyzer
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ compile:
xref:
@$(REBAR) xref

dialyzer:
@$(REBAR) dialyzer

clean:
@$(REBAR) clean

Expand Down
12 changes: 6 additions & 6 deletions include/epgl_int.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@

-record(relation_column, {
flags :: integer(),
name :: binary(),
data_type_id :: integer(),
atttypmod :: integer()
name :: binary() | undefined,
data_type_id :: integer() | undefined,
atttypmod :: integer() | undefined
}).

-record(relation_msg, {
id :: integer(),
namespace :: binary(),
name :: binary(),
replica_identity :: integer(),
replica_identity :: integer() | undefined,
num_columns :: integer(),
columns :: [#relation_column{}]
}).
Expand All @@ -49,15 +49,15 @@

-record(column_value, {
kind :: column_value_kind(),
value :: binary()
value :: binary() | null | unchanged
}).

-record(row_msg, {
msg_type :: row_msg_type(),
relation_id :: integer(),
num_columns :: integer(),
columns :: [#column_value{}],
old_columns :: [#column_value{}],
old_columns :: [#column_value{}] | undefined,
tuple_type :: tuple_type()
}).

Expand Down
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{deps, [
{epgsql, {git, "https://github.com/epgsql/epgsql.git", {tag, "4.3.0"}}}
{epgsql, {git, "https://github.com/epgsql/epgsql.git", {tag, "4.6.1"}}}
]}.

{eunit_opts, [verbose]}.
Expand Down
2 changes: 1 addition & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[{<<"epgsql">>,
{git,"https://github.com/epgsql/epgsql.git",
{ref,"cd3144d88f476b0425ea42319a3f6a8a22c13edf"}},
{ref,"aea48e2d4e282c9be8acf27e105fd153328221fa"}},
0}].
6 changes: 4 additions & 2 deletions src/epgl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
{username, Username :: string()} |
{password, Password :: string()}.

-export_type([connect_option/0]).
-type db_args() :: [connect_option()].

-export_type([connect_option/0, db_args/0]).

-spec start_subscriber(
SubscriberId :: atom(),
Expand Down Expand Up @@ -98,7 +100,7 @@ get_table_initial_state(Connection, TableName, SnapshotName) ->
Connection :: pid(),
ReplicationSets :: string(),
SnapshotName :: string(),
TablesOrder :: #{TableName :: binary() => Ord :: integer()}) ->
TablesOrder :: #{TableName :: binary() => Ord :: integer()} | undefined) ->
ok | {error, Reason :: term()}.
init_replication_set(Connection, ReplicationSets, SnapshotName, TablesOrder) ->
gen_server:call(Connection, {init_replication_set, ReplicationSets, SnapshotName, TablesOrder}, infinity).
Expand Down
6 changes: 3 additions & 3 deletions src/epgl_pglogical_decoder.erl
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ decode_tuple_fields(<<>>, _NumOfFields, Acc) ->
decode_tuple_fields(Rest, 0, Acc) ->
{lists:reverse(Acc), Rest};
decode_tuple_fields(<<?TUPLE_VALUE_KIND_NULL:8, Rest/binary>>, NumOfFields, Acc) ->
decode_tuple_fields(Rest, NumOfFields - 1,
decode_tuple_fields(Rest, NumOfFields - 1,
[#column_value{kind = decode_tuple_value_kind(?TUPLE_VALUE_KIND_NULL), value = null} | Acc]);
decode_tuple_fields(<<?TUPLE_VALUE_KIND_UNCHANGED:8, Rest/binary>>, NumOfFields, Acc) ->
decode_tuple_fields(Rest, NumOfFields - 1,
decode_tuple_fields(Rest, NumOfFields - 1,
[#column_value{kind = decode_tuple_value_kind(?TUPLE_VALUE_KIND_UNCHANGED), value = unchanged} | Acc]);
decode_tuple_fields(<<Kind:8, Length:32, Data:Length/bytes, Rest/binary>>, NumOfFields, Acc) ->
Value =
Expand Down Expand Up @@ -184,4 +184,4 @@ decode_tuple_value_kind(?TUPLE_VALUE_KIND_NULL) -> null;
decode_tuple_value_kind(?TUPLE_VALUE_KIND_UNCHANGED) -> unchanged;
decode_tuple_value_kind(?TUPLE_VALUE_KIND_TEXT) -> text;
decode_tuple_value_kind(?TUPLE_VALUE_KIND_BINARY) -> binary;
decode_tuple_value_kind(?TUPLE_VALUE_KIND_INTERNAL_BINARY) -> internal_binary.
decode_tuple_value_kind(?TUPLE_VALUE_KIND_INTERNAL_BINARY) -> internal_binary.
3 changes: 1 addition & 2 deletions src/epgl_pgoutput_decoder.erl
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ decode_tuple_type(?TUPLE_TYPE_OLD) -> old.

decode_msg_type(?MESSAGE_TYPE_INSERT) -> insert;
decode_msg_type(?MESSAGE_TYPE_UPDATE) -> update;
decode_msg_type(?MESSAGE_TYPE_DELETE) -> delete;
decode_msg_type(?MESSAGE_TYPE_TRUNCATE) -> truncate.
decode_msg_type(?MESSAGE_TYPE_DELETE) -> delete.

decode_tuple_value_kind(?TUPLE_VALUE_KIND_NULL) -> null;
decode_tuple_value_kind(?TUPLE_VALUE_KIND_UNCHANGED) -> unchanged;
Expand Down
13 changes: 6 additions & 7 deletions src/epgl_subscriber.erl
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
Rows :: [#row{}]) -> ok.

-record(state, {
db_connect_opts :: epgl:connect_option(),
conn :: pid(),
conn_normal :: pid(),
db_connect_opts :: epgl:db_args(),
conn :: pid() | undefined,
conn_normal :: pid() | undefined,
callbacks :: map(),
metadata = #{} :: map(),
rows = [] :: list(),
replication_slot :: string(),
replication_set :: string(),
replication_slot :: string() | undefined,
replication_set :: string() | undefined,
last_processed_lsn :: integer(),
check_lsn_mode :: skip | log | off,
max_reconnect_attempts :: integer() | infinite,
Expand Down Expand Up @@ -616,5 +616,4 @@ add_callback_data([Callback | Rest], CallbackData, RowData, TableName, ColumnsNa

get_option(auto_cast, Options) -> maps:get(auto_cast, Options, true);
get_option(binary_mode, Options) -> maps:get(binary_mode, Options, false);
get_option(reload_columns_on_metadata_msg, Options) -> maps:get(reload_columns_on_metadata_msg, Options, false);
get_option(Key, Options) -> maps:get(Key, Options, undefined).
get_option(reload_columns_on_metadata_msg, Options) -> maps:get(reload_columns_on_metadata_msg, Options, false).

0 comments on commit f8f4a61

Please sign in to comment.