Implementing State Machines in PostgreSQL

1 · Felix Geisendörfer · July 27, 2017, midnight
Finite-state machine (FSM) is a wonderful model of computation that has many practical applications. One of my favorites is turning business logic into simple FSMs. For example consider the following requirements for an order management system: Orders must not ship before they are paid. Orders can be canceled, but only if they haven't shipped yet. An order that has already been paid, needs to be refunded after canceling. Informally, turning such a list of requirements into an FSM is simply the...