about summary refs log tree commit diff
path: root/finito-postgres
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2018-09-26T16·19+0200
committerVincent Ambo <mail@tazj.in>2018-09-26T16·19+0200
commitcbb58fa6c2d60a72a454ba3c130bbcb990488643 (patch)
tree66fd029365d73a03e06594ebf4ba127d86cf0971 /finito-postgres
parentfe97c712cc64582cdd33dda8845820e479f83a39 (diff)
feat(postgres): Add initial table schema for Finito tables
Diffstat (limited to 'finito-postgres')
-rw-r--r--finito-postgres/migrations/2018-09-26-160621_bootstrap_finito_schema/down.sql4
-rw-r--r--finito-postgres/migrations/2018-09-26-160621_bootstrap_finito_schema/up.sql37
2 files changed, 41 insertions, 0 deletions
diff --git a/finito-postgres/migrations/2018-09-26-160621_bootstrap_finito_schema/down.sql b/finito-postgres/migrations/2018-09-26-160621_bootstrap_finito_schema/down.sql
new file mode 100644
index 000000000000..9b56f9d35abe
--- /dev/null
+++ b/finito-postgres/migrations/2018-09-26-160621_bootstrap_finito_schema/down.sql
@@ -0,0 +1,4 @@
+DROP TABLE actions;
+DROP TYPE ActionStatus;
+DROP TABLE events;
+DROP TABLE machines;
diff --git a/finito-postgres/migrations/2018-09-26-160621_bootstrap_finito_schema/up.sql b/finito-postgres/migrations/2018-09-26-160621_bootstrap_finito_schema/up.sql
new file mode 100644
index 000000000000..0de1a9e3c6df
--- /dev/null
+++ b/finito-postgres/migrations/2018-09-26-160621_bootstrap_finito_schema/up.sql
@@ -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 JSONB
+);
+
+CREATE INDEX idx_actions_machines ON actions(fsm_id);
+CREATE INDEX idx_actions_events ON actions(event_id);