cheerfulstoic / ecto_watch

EctoWatch allows you to easily get notifications about database changes directly from PostgreSQL.
168 stars 5 forks source link

Clean up unused triggers #4

Closed venkatd closed 1 week ago

venkatd commented 1 month ago

I don't know the best approach here, but if I test out EctoWatch on a specific schema, then remove it from the list, the trigger still remains.

I had to manually run a DROP TRIGGER function.

For performance reasons, it would be best to remove unused triggers.

Thoughts on the best way to handle this?

Perhaps a Logger.warn to detect unused triggers/functions with the ew_ prefix?

cheerfulstoic commented 1 month ago

Yeah, that's fair... 🤔 It's something that I had on my mind but avoided in the first draft because it felt a bit complicated.

I could even see just removing the unused triggers on startup instead of just logging. That might get people into trouble if they start having multiple nodes pointing to the same database and having different watchers setup (so each node might delete the other node's watchers). But if people ever want to get that advanced then there could probably be something like a automatically_delete_triggers: false option (where the default is true) 🤔

I can take a look at the auto-removing tomorrow and see how complicated it is 👍

cheerfulstoic commented 1 week ago

I introduced the ability to do this in the latest versions, so check it out (heads up to @rogelio2k )

Be sure to check out the library's new HexDocs which include upgrade guides for some recent breaking changes!

cheerfulstoic commented 1 week ago

Quick note on that also: by default ecto_watch will log unused triggers and functions. You'll need to use set the ECTO_WATCH_CLEANUP environment variable to cleanup to actually do the cleanup (though I suggest just seeing what the logs say first)