tvl-depot/finito-postgres/migrations/2018-09-26-160621_bootstrap_finito_schema/up.sql
Vincent Ambo 45afa18846 feat(postgres): Compatibility with new associated error type
Changes the implementation of action execution to deal with the
returned associated errors.

The only sensible constraint on those errors that I could think of for
now is `Debug`, meaning that errors are now persisted as debug
messages.

This is not as nice to work with for a future implementation of
retryable actions as the equivalent in Haskell, but maybe an idea
shows up underway. The main issue is that most of the common error
types will not be implementing Serde traits, so serialization to/from
the same error type is difficult.

Adding an implementation constraint for JSON serialisation on error
types (i.e. `S::Error: Serialize + Deserialize`) would probably cause
headaches for users, especially if they are trying to use an
out-of-the-box error type or an error type wrapping foreign errors.

Det ska'kke være lett ...
2018-09-26 23:19:34 +02:00

37 lines
910 B
SQL

-- 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);