Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
-- schema definition of comms when we migrated it from its own database to macrodb. updated all table names and enum names
-- to be prefixed with comms_. definition was generated by pg_dump so it is a little weird.
CREATE TYPE comms_channel_type AS ENUM ('public', 'organization', 'private', 'direct_message');
CREATE TYPE comms_participant_role AS ENUM ('owner', 'admin', 'member');
CREATE TABLE public.comms_activity
(
id uuid NOT NULL,
user_id text NOT NULL,
channel_id uuid NOT NULL,
created_at timestamp without time zone DEFAULT now() NOT NULL,
updated_at timestamp without time zone DEFAULT now() NOT NULL,
viewed_at timestamp without time zone,
interacted_at timestamp without time zone
);
--
-- Name: attachments; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.comms_attachments
(
id uuid NOT NULL,
message_id uuid NOT NULL,
entity_type character varying(32) NOT NULL,
entity_id character varying NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
channel_id uuid NOT NULL
);
--
-- Name: channel_participants; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.comms_channel_participants
(
channel_id uuid NOT NULL,
role public.comms_participant_role NOT NULL,
user_id text NOT NULL,
joined_at timestamp with time zone DEFAULT now() NOT NULL,
left_at timestamp with time zone
);
--
-- Name: channels; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.comms_channels
(
id uuid NOT NULL,
name character varying(255),
channel_type public.comms_channel_type NOT NULL,
org_id bigint,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
owner_id text NOT NULL,
CONSTRAINT valid_channel_name CHECK ((
((channel_type = 'direct_message'::public.comms_channel_type) AND (name IS NULL)) OR ((channel_type = ANY
(ARRAY ['public'::public.comms_channel_type, 'organization'::public.comms_channel_type])) AND
(name IS NOT NULL)) OR
(channel_type = 'private'::public.comms_channel_type))),
CONSTRAINT valid_org_channel CHECK ((
((channel_type = 'organization'::public.comms_channel_type) AND (org_id IS NOT NULL)) OR
((channel_type <> 'organization'::public.comms_channel_type) AND (org_id IS NULL))))
);
--
-- Name: entity_mentions; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.comms_entity_mentions
(
created_at timestamp with time zone DEFAULT now() NOT NULL,
entity_type character varying(32) NOT NULL,
entity_id character varying NOT NULL,
source_entity_type character varying(32) NOT NULL,
source_entity_id character varying NOT NULL,
id uuid DEFAULT gen_random_uuid() NOT NULL,
user_id character varying
);
--
-- Name: messages; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.comms_messages
(
id uuid NOT NULL,
channel_id uuid NOT NULL,
thread_id uuid,
sender_id text NOT NULL,
content text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
edited_at timestamp without time zone,
deleted_at timestamp without time zone
);
--
-- Name: reactions; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.comms_reactions
(
message_id uuid NOT NULL,
emoji character varying(32) NOT NULL,
user_id text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL
);
--
-- Name: activity activity_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.comms_activity
ADD CONSTRAINT comms_activity_pkey PRIMARY KEY (id);
--
-- Name: attachments attachments_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.comms_attachments
ADD CONSTRAINT comms_attachments_pkey PRIMARY KEY (id);
--
-- Name: channel_participants channel_participants_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.comms_channel_participants
ADD CONSTRAINT comms_channel_participants_pkey PRIMARY KEY (channel_id, user_id);
--
-- Name: channels channels_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.comms_channels
ADD CONSTRAINT comms_channels_pkey PRIMARY KEY (id);
--
-- Name: entity_mentions entity_mentions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.comms_entity_mentions
ADD CONSTRAINT comms_entity_mentions_pkey PRIMARY KEY (id);
--
-- Name: messages messages_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.comms_messages
ADD CONSTRAINT comms_messages_pkey PRIMARY KEY (id);
--
-- Name: reactions reactions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.comms_reactions
ADD CONSTRAINT comms_reactions_pkey PRIMARY KEY (message_id, emoji, user_id);
--
-- Name: activity unique_user_channel; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.comms_activity
ADD CONSTRAINT comms_unique_user_channel UNIQUE (user_id, channel_id);
--
-- Name: idx_activity_channel_id_user_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_activity_channel_id_user_id ON public.comms_activity USING btree (user_id, channel_id);
--
-- Name: idx_activity_channel_user; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_activity_channel_user ON public.comms_activity USING btree (channel_id, user_id);
--
-- Name: idx_activity_user_times; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_activity_user_times ON public.comms_activity USING btree (user_id, updated_at, created_at);
--
-- Name: idx_attachments_channel_created; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_attachments_channel_created ON public.comms_attachments USING btree (channel_id, created_at);
--
-- Name: idx_attachments_channel_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_attachments_channel_id ON public.comms_attachments USING btree (channel_id);
--
-- Name: idx_attachments_entity_created; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_attachments_entity_created ON public.comms_attachments USING btree (entity_type, entity_id, created_at DESC) INCLUDE (channel_id, message_id);
--
-- Name: idx_attachments_message_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_attachments_message_id ON public.comms_attachments USING btree (message_id);
--
-- Name: idx_channels_org_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_channels_org_id ON public.comms_channels USING btree (org_id) WHERE (channel_type = 'organization'::public.comms_channel_type);
--
-- Name: idx_cp_active_by_channel_user; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_cp_active_by_channel_user ON public.comms_channel_participants USING btree (channel_id, user_id) WHERE (left_at IS NULL);
--
-- Name: idx_entity_mentions_combination; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_entity_mentions_combination ON public.comms_entity_mentions USING btree (source_entity_type, source_entity_id, entity_type, entity_id);
--
-- Name: idx_entity_mentions_created_at; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_entity_mentions_created_at ON public.comms_entity_mentions USING btree (created_at DESC);
--
-- Name: idx_entity_mentions_entity_type_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_entity_mentions_entity_type_id ON public.comms_entity_mentions USING btree (entity_type, entity_id) INCLUDE (source_entity_type, source_entity_id);
--
-- Name: idx_entity_mentions_source; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_entity_mentions_source ON public.comms_entity_mentions USING btree (source_entity_type, source_entity_id);
--
-- Name: idx_entity_mentions_user_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_entity_mentions_user_id ON public.comms_entity_mentions USING btree (user_id) WHERE (user_id IS NOT NULL);
--
-- Name: idx_messages_active; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_messages_active ON public.comms_messages USING btree (id) WHERE (deleted_at IS NULL);
--
-- Name: idx_messages_channel_created_at_active; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_messages_channel_created_at_active ON public.comms_messages USING btree (channel_id, created_at DESC) WHERE (deleted_at IS NULL);
--
-- Name: idx_messages_channel_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_messages_channel_id ON public.comms_messages USING btree (channel_id);
--
-- Name: idx_messages_channel_timeline; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_messages_channel_timeline ON public.comms_messages USING btree (channel_id, created_at);
--
-- Name: idx_messages_created_at_active; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_messages_created_at_active ON public.comms_messages USING btree (created_at DESC) WHERE (deleted_at IS NULL);
--
-- Name: idx_messages_sender_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_messages_sender_id ON public.comms_messages USING btree (sender_id);
--
-- Name: idx_messages_thread_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_messages_thread_id ON public.comms_messages USING btree (thread_id) WHERE (thread_id IS NOT NULL);
--
-- Name: idx_reactions_message_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_comms_reactions_message_id ON public.comms_reactions USING btree (message_id);
--
-- Name: attachments attachments_channel_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.comms_attachments
ADD CONSTRAINT comms_attachments_channel_id_fkey FOREIGN KEY (channel_id) REFERENCES public.comms_channels (id) ON DELETE CASCADE;
--
-- Name: attachments attachments_message_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.comms_attachments
ADD CONSTRAINT comms_attachments_message_id_fkey FOREIGN KEY (message_id) REFERENCES public.comms_messages (id) ON DELETE CASCADE;
--
-- Name: channel_participants channel_participants_channel_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.comms_channel_participants
ADD CONSTRAINT comms_channel_participants_channel_id_fkey FOREIGN KEY (channel_id) REFERENCES public.comms_channels (id) ON DELETE CASCADE;
--
-- Name: messages messages_channel_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.comms_messages
ADD CONSTRAINT comms_messages_channel_id_fkey FOREIGN KEY (channel_id) REFERENCES public.comms_channels (id) ON DELETE CASCADE;
--
-- Name: messages messages_thread_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.comms_messages
ADD CONSTRAINT comms_messages_thread_id_fkey FOREIGN KEY (thread_id) REFERENCES public.comms_messages (id) ON DELETE CASCADE;
--
-- Name: reactions reactions_message_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.comms_reactions
ADD CONSTRAINT comms_reactions_message_id_fkey FOREIGN KEY (message_id) REFERENCES public.comms_messages (id) ON DELETE CASCADE;