Home > OS >  Rebalance tasks in postgresql
Rebalance tasks in postgresql

Time:03-03

I have a moderation table that stores which post is assigned to which moderator. I want to periodically rebalance this table. Rebalancing means that all available moderators should have roughly equal number of unmoderated posts assigned to them. Moderation table has following format.

 --------- ------------ -------------- 
| mod_id  | post_id    | is_moderated |
 --------- ------------ -------------- 

I am fairly new to postgresql. I am using it with django python. What is the best way to do this?

There are a set of mod_id values that should have roughly equal number of post_id assigned to them when is_moderatoed is false.

CodePudding user response:

If you want to make it in Database level, you can use Postgresql Trigger. There django implemented library - Django PgTrigger.

And there method for what you want. Keeping a field in-sync with another

Or in Django level you can do with with Django Signals.

  • Related