feat(tazjin/finito): Check in my old Rust state-machine library

I dug through my archives for this and found a version that, while
unfortunately not the latest implementation, is close enough to the
real thing to show off what Finito did.

This is a Postgres-backed state-machine library for complex
application logic. I wrote this originally for a work purpose in a
previous life, but have always wanted to apply it elsewhere, too.

git-subtree-dir: users/tazjin/finito
git-subtree-mainline: 0380841eb1
git-subtree-split: b748117225
Change-Id: I0de02d6258568447a14870f1a533812a67127763
This commit is contained in:
Vincent Ambo 2020-06-30 04:35:01 +01:00
commit 9e7b81391d
13 changed files with 1279 additions and 0 deletions

View file

@ -0,0 +1,4 @@
DROP TABLE actions;
DROP TYPE ActionStatus;
DROP TABLE events;
DROP TABLE machines;

View file

@ -0,0 +1,37 @@
-- Creates the initial schema required by finito-postgres.
CREATE TABLE machines (
id UUID PRIMARY KEY,
created TIMESTAMPTZ NOT NULL DEFAULT NOW(),
fsm TEXT NOT NULL,
state JSONB NOT NULL
);
CREATE TABLE events (
id UUID PRIMARY KEY,
created TIMESTAMPTZ NOT NULL DEFAULT NOW(),
fsm TEXT NOT NULL,
fsm_id UUID NOT NULL REFERENCES machines(id),
event JSONB NOT NULL
);
CREATE INDEX idx_events_machines ON events(fsm_id);
CREATE TYPE ActionStatus AS ENUM (
'Pending',
'Completed',
'Failed'
);
CREATE TABLE actions (
id UUID PRIMARY KEY,
created TIMESTAMPTZ NOT NULL DEFAULT NOW(),
fsm TEXT NOT NULL,
fsm_id UUID NOT NULL REFERENCES machines(id),
event_id UUID NOT NULL REFERENCES events(id),
content JSONB NOT NULL,
status ActionStatus NOT NULL,
error TEXT
);
CREATE INDEX idx_actions_machines ON actions(fsm_id);
CREATE INDEX idx_actions_events ON actions(event_id);