Re:Designing state machines
by adipasquale on Monday June 26, 2017 @10:38AM
(#14637122)
If you mean modeling the state graph itself, it's usually not modeled in the db but only in the code. It could indeed be interesting to store the graph itself if it evolves often, or at least a version number.
If you were speaking about storing the instances lifecycles, a simple model using a RDBS is to store one row per transition event in a separate table. This is what the papertrail[1] gem does for example.
"Enterprise" applications such as ERPs or CRMs often have fairly complex workflow features where everything is in the underlying database - both high level workflow/state-machine definitions and compiled code.
You can use user defined aggregates in postgres to model state machines. I'm using this technique quite successfully and have been meaning to write a blog post about it.
Re:Designing state machines
by sandGorgon on Wednesday June 28, 2017 @05:46AM
(#14652844)
could you talk a bit more about this ?
i was looking at https://sqlsunday.com/2014/05/25/directed-acyclic-graphs-vs-... https://www.qcode.co.uk/post/73 to learn how others have done it
I have been thinking of using Postgresql CTE to do this. When a cycle occurs, I just create a new step to the dB.
Anyone from CRM startups who have interesting learnings here ?