1- -- 001_initial_dbos_schema.up.sql
2-
3- -- Create the dbos schema
4- CREATE SCHEMA IF NOT EXISTS dbos;
5-
61-- Enable uuid extension for generating UUIDs
72CREATE EXTENSION IF NOT EXISTS " uuid-ossp" ;
83
9- -- Create workflow_status table
10- CREATE TABLE IF NOT EXISTS dbos .workflow_status (
4+ CREATE TABLE dbos .workflow_status (
115 workflow_uuid TEXT PRIMARY KEY ,
126 status TEXT ,
137 name TEXT ,
148 authenticated_user TEXT ,
159 assumed_role TEXT ,
1610 authenticated_roles TEXT ,
11+ request TEXT ,
1712 output TEXT ,
1813 error TEXT ,
1914 executor_id TEXT ,
@@ -27,34 +22,21 @@ CREATE TABLE IF NOT EXISTS dbos.workflow_status (
2722 queue_name TEXT ,
2823 workflow_timeout_ms BIGINT ,
2924 workflow_deadline_epoch_ms BIGINT ,
25+ inputs TEXT ,
3026 started_at_epoch_ms BIGINT ,
3127 deduplication_id TEXT ,
32- inputs TEXT ,
3328 priority INTEGER NOT NULL DEFAULT 0
3429);
3530
36- -- Create indexes for workflow_status
37- CREATE INDEX IF NOT EXISTS workflow_status_created_at_index ON dbos .workflow_status (created_at);
38- CREATE INDEX IF NOT EXISTS workflow_status_executor_id_index ON dbos .workflow_status (executor_id);
39- CREATE INDEX IF NOT EXISTS workflow_status_status_index ON dbos .workflow_status (status);
31+ CREATE INDEX workflow_status_created_at_index ON dbos .workflow_status (created_at);
32+ CREATE INDEX workflow_status_executor_id_index ON dbos .workflow_status (executor_id);
33+ CREATE INDEX workflow_status_status_index ON dbos .workflow_status (status);
4034
41- -- Create unique constraint for queue_name and deduplication_id
42- DO $$
43- BEGIN
44- IF NOT EXISTS (
45- SELECT 1 FROM information_schema .table_constraints
46- WHERE constraint_name = ' uq_workflow_status_queue_name_dedup_id'
47- AND table_name = ' workflow_status'
48- AND table_schema = ' dbos'
49- ) THEN
50- ALTER TABLE dbos .workflow_status
51- ADD CONSTRAINT uq_workflow_status_queue_name_dedup_id
52- UNIQUE (queue_name, deduplication_id);
53- END IF;
54- END $$;
35+ ALTER TABLE dbos .workflow_status
36+ ADD CONSTRAINT uq_workflow_status_queue_name_dedup_id
37+ UNIQUE (queue_name, deduplication_id);
5538
56- -- Create operation_outputs table
57- CREATE TABLE IF NOT EXISTS dbos .operation_outputs (
39+ CREATE TABLE dbos .operation_outputs (
5840 workflow_uuid TEXT NOT NULL ,
5941 function_id INTEGER NOT NULL ,
6042 function_name TEXT NOT NULL DEFAULT ' ' ,
@@ -66,7 +48,7 @@ CREATE TABLE IF NOT EXISTS dbos.operation_outputs (
6648 ON UPDATE CASCADE ON DELETE CASCADE
6749);
6850
69- CREATE TABLE IF NOT EXISTS dbos .notifications (
51+ CREATE TABLE dbos .notifications (
7052 destination_uuid TEXT NOT NULL ,
7153 topic TEXT ,
7254 message TEXT NOT NULL ,
@@ -75,8 +57,7 @@ CREATE TABLE IF NOT EXISTS dbos.notifications (
7557 FOREIGN KEY (destination_uuid) REFERENCES dbos .workflow_status (workflow_uuid)
7658 ON UPDATE CASCADE ON DELETE CASCADE
7759);
78- -- Create index for notifications
79- CREATE INDEX IF NOT EXISTS idx_workflow_topic ON dbos .notifications (destination_uuid, topic);
60+ CREATE INDEX idx_workflow_topic ON dbos .notifications (destination_uuid, topic);
8061
8162-- Create notification function
8263CREATE OR REPLACE FUNCTION dbos .notifications_function() RETURNS TRIGGER AS $$
8970$$ LANGUAGE plpgsql;
9071
9172-- Create notification trigger
92- DO $$
93- BEGIN
94- IF NOT EXISTS (
95- SELECT 1 FROM information_schema .triggers
96- WHERE trigger_name = ' dbos_notifications_trigger'
97- AND event_object_table = ' notifications'
98- AND event_object_schema = ' dbos'
99- ) THEN
100- CREATE TRIGGER dbos_notifications_trigger
101- AFTER INSERT ON dbos .notifications
102- FOR EACH ROW EXECUTE FUNCTION dbos .notifications_function ();
103- END IF;
104- END $$;
73+ CREATE TRIGGER dbos_notifications_trigger
74+ AFTER INSERT ON dbos .notifications
75+ FOR EACH ROW EXECUTE FUNCTION dbos .notifications_function ();
10576
106- -- Create workflow_events table
107- CREATE TABLE IF NOT EXISTS dbos .workflow_events (
77+ CREATE TABLE dbos .workflow_events (
10878 workflow_uuid TEXT NOT NULL ,
10979 key TEXT NOT NULL ,
11080 value TEXT NOT NULL ,
@@ -124,16 +94,26 @@ END;
12494$$ LANGUAGE plpgsql;
12595
12696-- Create events trigger
127- DO $$
128- BEGIN
129- IF NOT EXISTS (
130- SELECT 1 FROM information_schema .triggers
131- WHERE trigger_name = ' dbos_workflow_events_trigger'
132- AND event_object_table = ' workflow_events'
133- AND event_object_schema = ' dbos'
134- ) THEN
135- CREATE TRIGGER dbos_workflow_events_trigger
136- AFTER INSERT ON dbos .workflow_events
137- FOR EACH ROW EXECUTE FUNCTION dbos .workflow_events_function ();
138- END IF;
139- END $$;
97+ CREATE TRIGGER dbos_workflow_events_trigger
98+ AFTER INSERT ON dbos .workflow_events
99+ FOR EACH ROW EXECUTE FUNCTION dbos .workflow_events_function ();
100+
101+ CREATE TABLE dbos .streams (
102+ workflow_uuid TEXT NOT NULL ,
103+ key TEXT NOT NULL ,
104+ value TEXT NOT NULL ,
105+ " offset" INTEGER NOT NULL ,
106+ PRIMARY KEY (workflow_uuid, key, " offset" ),
107+ FOREIGN KEY (workflow_uuid) REFERENCES dbos .workflow_status (workflow_uuid)
108+ ON UPDATE CASCADE ON DELETE CASCADE
109+ );
110+
111+ CREATE TABLE dbos .event_dispatch_kv (
112+ service_name TEXT NOT NULL ,
113+ workflow_fn_name TEXT NOT NULL ,
114+ key TEXT NOT NULL ,
115+ value TEXT ,
116+ update_seq NUMERIC (38 ,0 ),
117+ update_time NUMERIC (38 ,15 ),
118+ PRIMARY KEY (service_name, workflow_fn_name, key)
119+ );
0 commit comments