I’ve a requirement to ensure that every company has an owner. Example database model with requirements @db<>fiddle.
I’ve tried following ideas:
before update or deletetrigger: look at the graph and try to guess what happens after execution. It doesn’t work, because it’s executed immediately.
after update or deleteconstraint DEFERRABLE INITIALLY DEFERRED trigger: how check count of ceos’ if
staffis deleted too? Or how to allow, if company is deleted with staff and role? And it isn’t easy to test with pgtap.
Any further ideas? Thanks!