Skip to content

Commit

Permalink
fix: add missing keys from pubsub tables (#1191)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas authored Apr 8, 2024
1 parent 0a94ac6 commit a5ac318
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions backend/controller/sql/schema/001_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand Down Expand Up @@ -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
(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand Down

0 comments on commit a5ac318

Please sign in to comment.