Earlier quoted context omitted.
You implement any custom logic in PostgreSQL mechanisms (permissions, triggers, constraints, views, stored procedures etc).
...and be locked in for life, joy.
"The argument that you don't want to write any code that locks you to a database is some stunning lack of awareness, as you decide to lock yourself into the tsunami of unpredictability that is web frameworks to ward off the evil of being locked into a 20 year database product built on some pretty sound theoretical foundations."