22CREATE EXTENSION IF NOT EXISTS " uuid-ossp" ;
33
44-- Create the schema if it doesn't exist
5- CREATE SCHEMA IF NOT EXISTS {{.Schema}} ;
5+ CREATE SCHEMA IF NOT EXISTS %s ;
66
7- CREATE TABLE {{.Schema}} .workflow_status (
7+ CREATE TABLE % s .workflow_status (
88 workflow_uuid TEXT PRIMARY KEY ,
99 status TEXT ,
1010 name TEXT ,
@@ -31,39 +31,39 @@ CREATE TABLE {{.Schema}}.workflow_status (
3131 priority INTEGER NOT NULL DEFAULT 0
3232);
3333
34- CREATE INDEX workflow_status_created_at_index ON {{.Schema}} .workflow_status (created_at);
35- CREATE INDEX workflow_status_executor_id_index ON {{.Schema}} .workflow_status (executor_id);
36- CREATE INDEX workflow_status_status_index ON {{.Schema}} .workflow_status (status);
34+ CREATE INDEX workflow_status_created_at_index ON % s .workflow_status (created_at);
35+ CREATE INDEX workflow_status_executor_id_index ON % s .workflow_status (executor_id);
36+ CREATE INDEX workflow_status_status_index ON % s .workflow_status (status);
3737
38- ALTER TABLE {{.Schema}} .workflow_status
38+ ALTER TABLE % s .workflow_status
3939ADD CONSTRAINT uq_workflow_status_queue_name_dedup_id
4040UNIQUE (queue_name, deduplication_id);
4141
42- CREATE TABLE {{.Schema}} .operation_outputs (
42+ CREATE TABLE % s .operation_outputs (
4343 workflow_uuid TEXT NOT NULL ,
4444 function_id INTEGER NOT NULL ,
4545 function_name TEXT NOT NULL DEFAULT ' ' ,
4646 output TEXT ,
4747 error TEXT ,
4848 child_workflow_id TEXT ,
4949 PRIMARY KEY (workflow_uuid, function_id),
50- FOREIGN KEY (workflow_uuid) REFERENCES {{.Schema}} .workflow_status(workflow_uuid)
50+ FOREIGN KEY (workflow_uuid) REFERENCES % s .workflow_status (workflow_uuid)
5151 ON UPDATE CASCADE ON DELETE CASCADE
5252);
5353
54- CREATE TABLE {{.Schema}} .notifications (
54+ CREATE TABLE % s .notifications (
5555 destination_uuid TEXT NOT NULL ,
5656 topic TEXT ,
5757 message TEXT NOT NULL ,
5858 created_at_epoch_ms BIGINT NOT NULL DEFAULT (EXTRACT(epoch FROM now()) * 1000 ::numeric )::bigint ,
5959 message_uuid TEXT NOT NULL DEFAULT gen_random_uuid(), -- Built-in function
60- FOREIGN KEY (destination_uuid) REFERENCES {{.Schema}} .workflow_status(workflow_uuid)
60+ FOREIGN KEY (destination_uuid) REFERENCES % s .workflow_status (workflow_uuid)
6161 ON UPDATE CASCADE ON DELETE CASCADE
6262);
63- CREATE INDEX idx_workflow_topic ON {{.Schema}} .notifications (destination_uuid, topic);
63+ CREATE INDEX idx_workflow_topic ON % s .notifications (destination_uuid, topic);
6464
6565-- Create notification function
66- CREATE OR REPLACE FUNCTION {{.Schema}} .notifications_function() RETURNS TRIGGER AS $$
66+ CREATE OR REPLACE FUNCTION % s .notifications_function () RETURNS TRIGGER AS $$
6767DECLARE
6868 payload text := NEW .destination_uuid || ' ::' || NEW .topic ;
6969BEGIN
@@ -74,20 +74,20 @@ $$ LANGUAGE plpgsql;
7474
7575-- Create notification trigger
7676CREATE TRIGGER dbos_notifications_trigger
77- AFTER INSERT ON {{.Schema}} .notifications
78- FOR EACH ROW EXECUTE FUNCTION {{.Schema}} .notifications_function();
77+ AFTER INSERT ON % s .notifications
78+ FOR EACH ROW EXECUTE FUNCTION % s .notifications_function ();
7979
80- CREATE TABLE {{.Schema}} .workflow_events (
80+ CREATE TABLE % s .workflow_events (
8181 workflow_uuid TEXT NOT NULL ,
8282 key TEXT NOT NULL ,
8383 value TEXT NOT NULL ,
8484 PRIMARY KEY (workflow_uuid, key),
85- FOREIGN KEY (workflow_uuid) REFERENCES {{.Schema}} .workflow_status(workflow_uuid)
85+ FOREIGN KEY (workflow_uuid) REFERENCES % s .workflow_status (workflow_uuid)
8686 ON UPDATE CASCADE ON DELETE CASCADE
8787);
8888
8989-- Create events function
90- CREATE OR REPLACE FUNCTION {{.Schema}} .workflow_events_function() RETURNS TRIGGER AS $$
90+ CREATE OR REPLACE FUNCTION % s .workflow_events_function () RETURNS TRIGGER AS $$
9191DECLARE
9292 payload text := NEW .workflow_uuid || ' ::' || NEW .key ;
9393BEGIN
@@ -98,20 +98,20 @@ $$ LANGUAGE plpgsql;
9898
9999-- Create events trigger
100100CREATE TRIGGER dbos_workflow_events_trigger
101- AFTER INSERT ON {{.Schema}} .workflow_events
102- FOR EACH ROW EXECUTE FUNCTION {{.Schema}} .workflow_events_function();
101+ AFTER INSERT ON % s .workflow_events
102+ FOR EACH ROW EXECUTE FUNCTION % s .workflow_events_function ();
103103
104- CREATE TABLE {{.Schema}} .streams (
104+ CREATE TABLE % s .streams (
105105 workflow_uuid TEXT NOT NULL ,
106106 key TEXT NOT NULL ,
107107 value TEXT NOT NULL ,
108108 " offset" INTEGER NOT NULL ,
109109 PRIMARY KEY (workflow_uuid, key, " offset" ),
110- FOREIGN KEY (workflow_uuid) REFERENCES {{.Schema}} .workflow_status(workflow_uuid)
110+ FOREIGN KEY (workflow_uuid) REFERENCES % s .workflow_status (workflow_uuid)
111111 ON UPDATE CASCADE ON DELETE CASCADE
112112);
113113
114- CREATE TABLE {{.Schema}} .event_dispatch_kv (
114+ CREATE TABLE % s .event_dispatch_kv (
115115 service_name TEXT NOT NULL ,
116116 workflow_fn_name TEXT NOT NULL ,
117117 key TEXT NOT NULL ,
0 commit comments