diff --git a/backend/controller/sql/schema/001_init.sql b/backend/controller/sql/schema/001_init.sql index 66238ae7fe..de06503fe9 100644 --- a/backend/controller/sql/schema/001_init.sql +++ b/backend/controller/sql/schema/001_init.sql @@ -43,9 +43,7 @@ CREATE TABLE modules -- Proto-encoded module schema. CREATE DOMAIN module_schema_pb AS BYTEA; -CREATE DOMAIN runner_key AS varchar; -CREATE DOMAIN controller_key AS varchar; -CREATE DOMAIN deployment_key AS varchar; +CREATE DOMAIN deployment_key AS VARCHAR; CREATE TABLE deployments ( @@ -106,6 +104,8 @@ CREATE TYPE runner_state AS ENUM ( 'dead' ); +CREATE DOMAIN runner_key AS VARCHAR; + -- Runners are processes that are available to run modules. CREATE TABLE runners ( @@ -216,6 +216,8 @@ CREATE TYPE controller_state AS ENUM ( 'dead' ); +CREATE DOMAIN controller_key AS VARCHAR; + CREATE TABLE controller ( id BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, @@ -263,9 +265,12 @@ CREATE INDEX events_custom_key_2_idx ON events (custom_key_2); CREATE INDEX events_custom_key_3_idx ON events (custom_key_3); CREATE INDEX events_custom_key_4_idx ON events (custom_key_4); +CREATE DOMAIN topic_key AS VARCHAR; + -- Topics are a way to asynchronously publish data between modules. CREATE TABLE topics ( id BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + "key" topic_key UNIQUE NOT NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT (NOW() AT TIME ZONE 'utc'), -- Each topic is associated with an owning module. @@ -302,11 +307,14 @@ CREATE TRIGGER topic_events_notify_event FOR EACH ROW EXECUTE PROCEDURE notify_event(); +CREATE DOMAIN subscription_key AS VARCHAR; + -- A subscription to a topic. -- -- Multiple subscribers can consume from a single subscription. CREATE TABLE topic_subscriptions ( id BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + "key" subscription_key UNIQUE NOT NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT (NOW() AT TIME ZONE 'utc'), topic_id BIGINT NOT NULL REFERENCES topics(id) ON DELETE CASCADE, @@ -318,11 +326,14 @@ CREATE TABLE topic_subscriptions ( cursor BIGINT NOT NULL REFERENCES topic_events(id) ON DELETE CASCADE ); +CREATE DOMAIN subscriber_key AS VARCHAR; + -- A subscriber to a topic. -- -- A subscriber is a 1:1 mapping between a subscription and a sink. CREATE TABLE topic_subscribers ( id BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + "key" subscriber_key UNIQUE NOT NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT (NOW() AT TIME ZONE 'utc'), topic_subscriptions_id BIGINT NOT NULL REFERENCES topic_subscriptions(id),