docs: def republish_module_trigger(plpy, td):
      """Trigger called from postgres database when republishing a module.
  
      When a module is republished, the versions of the collections that it is
      part of will need to be updated (a minor update).
  
  
      e.g. there is a collection c1 v2.1, which contains module m1 v3
  
      m1 is updated, we have a new row in the modules table with m1 v4
  
      this trigger will create increment the minor version of c1, so we'll have
      c1 v2.2
  
      we need to create a collection tree for c1 v2.2 which is exactly the same
      as c1 v2.1, but with m1 v4 instead of m1 v3, and c1 v2.2 instead of c1 v2.2
      """
      # Is this an insert from legacy? Legacy always supplies the version.
      is_legacy_publication = td['new']['version'] is not None
      if not is_legacy_publication:
          # Bail out, because this trigger only applies to legacy publications.
          return "OK"
  
      plpy.log('Trigger fired on %s' % (td['new']['moduleid'],))
  
      modified = republish_module(td, plpy)
      plpy.log('modified: {}'.format(modified))
      plpy.log('insert values:\n{}\n'.format('\n'.join([
          '{}: {}'.format(key, value)
          for key, value in td['new'].items()])))
  
      return modified