code: def add_domain(db, organization, domain, is_top_domain=False, overwrite=False):
      
      with db.connect() as session:
          org = find_organization(session, organization)
  
          if not org:
              raise NotFoundError(entity=organization)
  
          dom = find_domain(session, domain)
  
          if dom and not overwrite:
              raise AlreadyExistsError(entity='Domain', eid=dom.domain)
          elif dom:
              delete_domain_db(session, dom)
  
          try:
              add_domain_db(session, org, domain,
                            is_top_domain=is_top_domain)
          except ValueError as e:
              raise InvalidValueError(e)
docs: Add a domain to the registry.
  
      This function adds a new domain to the given organization.
      The organization must exists on the registry prior to insert the new
      domain. Otherwise, it will raise a 'NotFoundError' exception. Moreover,
      if the given domain is already in the registry an 'AlreadyExistsError'
      exception will be raised.
  
      The new domain can be also set as a top domain. That is useful to avoid
      the insertion of sub-domains that belong to the same organization (i.e
      eu.example.com, us.example.com).
  
      Remember that a domain can only be assigned to one (and only one)
      organization.
  
      When the given domain already exist on the registry, you can use
      'overwrite' parameter to update its information. For instance, shift
      the domain to another organization or to update the top domain flag.
      Take into account that both fields will be updated at the same time.
  
      :param db: database manager
      :param organization: name of the organization
      :param domain: domain to add to the registry
      :param is_top_domain: set this domain as a top domain
      :param overwrite: force to reassign the domain to the given organization
          and to update top domain field
  
      :raises InvalidValueError: raised when domain is None or an empty string or
          is_top_domain does not have a boolean value
      :raises NotFoundError: raised when the given organization is not found
          in the registry
      :raises AlreadyExistsError: raised when the domain already exists
          in the registry