Skip to content

Commit c992b60

Browse files
Merge pull request #31 from ponychicken/patch-2
Don't print error message if there is no extra triggers
2 parents 0f874f2 + 8553daa commit c992b60

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

lib/ecto_watch/watcher_trigger_validator.ex

+27-16
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,40 @@ defmodule EctoWatch.WatcherTriggerValidator do
3737
Enum.each(extra_found_triggers, &drop_trigger(repo_mod, &1))
3838
Enum.each(extra_found_functions, &drop_function(repo_mod, &1))
3939
else
40-
Logger.error("""
41-
Found the following extra EctoWatch triggers:
40+
if MapSet.size(extra_found_triggers) > 0 do
41+
log_extra_triggers(extra_found_triggers)
42+
end
43+
if MapSet.size(extra_found_functions) > 0 do
44+
log_extra_functions(extra_found_functions)
45+
end
46+
end
47+
end)
4248

43-
#{Enum.map_join(extra_found_triggers, "\n", fn trigger_details -> "\"#{trigger_details.name}\" in the table \"#{trigger_details.table_schema}\".\"#{trigger_details.table_name}\"" end)}
49+
:ok
50+
end
4451

45-
...but they were not specified in the watcher options.
52+
defp log_extra_triggers(extra_found_triggers) do
53+
Logger.error("""
54+
Found the following extra EctoWatch triggers:
4655
47-
To cleanup unspecified triggers and functions, run your app with the `ECTO_WATCH_CLEANUP`
48-
environment variable set to the value `cleanup`
49-
""")
56+
#{Enum.map_join(extra_found_triggers, "\n", fn trigger_details -> "\"#{trigger_details.name}\" in the table \"#{trigger_details.table_schema}\".\"#{trigger_details.table_name}\"" end)}
5057
51-
Logger.error("""
52-
Found the following extra EctoWatch functions:
58+
...but they were not specified in the watcher options.
5359
54-
#{Enum.map_join(extra_found_functions, "\n", fn function_details -> "\"#{function_details.name}\" in the schema \"#{function_details.schema}\"" end)}
60+
To cleanup unspecified triggers and functions, run your app with the `ECTO_WATCH_CLEANUP`
61+
environment variable set to the value `cleanup`
62+
""")
63+
end
5564

56-
To cleanup unspecified triggers and functions, run your app with the `ECTO_WATCH_CLEANUP`
57-
environment variable set to the value `cleanup`
58-
""")
59-
end
60-
end)
65+
defp log_extra_functions(extra_found_functions) do
66+
Logger.error("""
67+
Found the following extra EctoWatch functions:
6168
62-
:ok
69+
#{Enum.map_join(extra_found_functions, "\n", fn function_details -> "\"#{function_details.name}\" in the schema \"#{function_details.schema}\"" end)}
70+
71+
To cleanup unspecified triggers and functions, run your app with the `ECTO_WATCH_CLEANUP`
72+
environment variable set to the value `cleanup`
73+
""")
6374
end
6475

6576
defp triggers_by_repo_mod do

0 commit comments

Comments
 (0)