I should not be messing with the database directly, but sometimes
that's necessary, as vmm does not provide a means to rename
a domain — and if it would, then it'd have this problem too:
mailsys=> update domain_name set domainname = 'example.org'
where domainname = 'example.com' returning gid;
→ ERROR: There can only be one domain marked as primary.
The only way to fix this is by using OLD in the trigger, which
requires a separate trigger function for UPDATE than INSERT (as
INSERT queries don't make OLD available).
also sprach martin f krafft <madduck@debian.org> [2015-11-12 17:20 +1300]:
I think a possible solution would be the following at the top of the
trigger function:
IF TG_OP='UPDATE' AND NEW.gid=OLD.gid AND NEW.is_primary=OLD.is_primary THEN
RETURN NEW;
END IF;
Btw, this still does not protect against the case when an UPDATE
removes the only primary domain, making them all secondary.
If you give an indication, I can rewrite the whole function to
accomodate for that too.