Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/database/schema.puml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class "Account" [[{A user account on a platform}]] {
{field} id : integer
{field} write_permission : boolean
{field} active : boolean
{field} account_local_id : string
}
class "Space" [[{A space on a platform representing a community engaged in a conversation}]] {
{field} id : integer
Expand Down Expand Up @@ -104,7 +105,7 @@ class "AutomatedAgent" [[{An automated agent}]] {
{field} id(i) : integer
{field} type(i) : EntityType
}
"Account" --> "1" "Agent" : "person"
"Account" --> "1" "Agent" : "agent"
"Agent" ^-- "Person"
"Agent" ^-- "AutomatedAgent"
@enduml
2 changes: 1 addition & 1 deletion packages/database/schema.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 52 additions & 6 deletions packages/database/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ classes:
email:
required: true
# TODO: known skills, i.e. what processes can they confirm.
unique_keys:
person_email:
unique_key_slots:
- email
person_orcid:
unique_key_slots:
- orcid
AutomatedAgent:
description: An automated agent
is_a: Agent
Expand All @@ -132,22 +139,28 @@ classes:
ifabsent: false
version:
range: string

unique_keys:
automated_agent_name_version:
unique_key_slots:
- name
- version
Platform:
description: A data platform where discourse happens
slots:
- id
- name
attributes:
url:
required: true
- url
unique_keys:
platform_url:
unique_key_slots:
- url
Account:
description: A user account on a platform
slots:
- id
- platform
attributes:
person:
agent:
range: Agent
required: true
write_permission:
Expand All @@ -157,6 +170,14 @@ classes:
range: boolean
required: true
ifabsent: true
account_local_id:
required: true
description: The identity of the person in this space
unique_keys:
account_platform_and_local_id:
unique_key_slots:
- platform
- account_local_id
Space:
description: A space on a platform representing a community engaged in a conversation
slots:
Expand All @@ -167,6 +188,10 @@ classes:
platform:
range: Platform
required: true
unique_keys:
space_url:
unique_key_slots:
- url
SpaceAccess:
description: An access control entry for a space
slots:
Expand Down Expand Up @@ -205,6 +230,12 @@ classes:
part_of:
description: This content is part of a larger content unit
range: Content
unique_keys:
content_space_and_local_id:
unique_key_slots:
- space
- source_local_id

# ContentDerivation:
# description: A derivation relation between content units
# attributes:
Expand All @@ -226,15 +257,24 @@ classes:
- id
- space
- source_local_id
- url
- created
- metadata
- last_modified
- author
- contributors
attributes:
url:
range: string
contents:
range: blob
unique_keys:
document_space_and_local_id:
unique_key_slots:
- space
- source_local_id
document_url:
unique_key_slots:
- url
# Article:
# description: an article
# is_a: Document
Expand Down Expand Up @@ -303,6 +343,11 @@ classes:
# Damn, concept schema is a concept, is it not?
# Now, if a concept has a complex structwre based on a complex content...
# AH, it should be based on occurences.
unique_keys:
concept_space_and_name:
unique_key_slots:
- space
- name

ConceptSchema:
is_a: Concept
Expand Down Expand Up @@ -379,6 +424,7 @@ slots:
range: string
url:
range: string
required: true
platform:
range: Platform
required: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
-- Space

CREATE UNIQUE INDEX IF NOT EXISTS platform_url_idx ON public."Platform" USING btree (url);

ALTER TABLE public."Space" ALTER COLUMN url SET NOT NULL;

CREATE UNIQUE INDEX IF NOT EXISTS space_url_idx ON public."Space" USING btree (url);

-- Agents

ALTER TABLE public."AutomatedAgent" ALTER COLUMN version SET NOT NULL;

CREATE UNIQUE INDEX IF NOT EXISTS automated_agent_name_version_idx ON public."AutomatedAgent" USING btree (name, version);

CREATE UNIQUE INDEX IF NOT EXISTS person_email_idx ON public."Person" USING btree (email);
CREATE UNIQUE INDEX IF NOT EXISTS person_orcid_idx ON public."Person" USING btree (orcid);

-- Account

ALTER TABLE public."Account" RENAME COLUMN "person_id" TO "agent_id";

ALTER TABLE public."Account" RENAME CONSTRAINT "Account_person_id_fkey" TO "Account_agent_id_fkey";

ALTER TABLE public."Account" ADD COLUMN account_local_id character varying;

UPDATE public."Account" SET account_local_id = (SELECT email FROM public."Person" AS p WHERE p.id = agent_id);

ALTER TABLE public."Account" ALTER COLUMN "account_local_id" SET NOT NULL;

CREATE UNIQUE INDEX IF NOT EXISTS account_platform_and_local_id_idx ON public."Account" USING btree (platform_id, account_local_id);

-- Document and Content

CREATE UNIQUE INDEX IF NOT EXISTS document_space_and_local_id_idx ON public."Document" USING btree (space_id, source_local_id) WHERE (space_id IS NOT NULL);
CREATE UNIQUE INDEX IF NOT EXISTS document_url_idx ON public."Document" USING btree (url);

DROP INDEX IF EXISTS public."Content_space_and_id";

CREATE UNIQUE INDEX IF NOT EXISTS content_space_and_local_id_idx ON public."Content" USING btree (space_id, source_local_id) WHERE (space_id IS NOT NULL);

-- Concept

ALTER TABLE public."Concept" ALTER COLUMN "space_id" set not null;

CREATE UNIQUE INDEX IF NOT EXISTS concept_space_and_name_idx ON public."Concept" USING btree (space_id, name);


-- SpaceAccess

ALTER TABLE public."SpaceAccess" DROP CONSTRAINT "SpaceAccess_account_id_space_id_key";

ALTER TABLE public."SpaceAccess" DROP CONSTRAINT "SpaceAccess_pkey";

ALTER TABLE public."SpaceAccess" DROP COLUMN "id";
ALTER TABLE public."SpaceAccess" ALTER COLUMN "space_id" set not null;

CREATE UNIQUE INDEX IF NOT EXISTS "SpaceAccess_pkey" ON public."SpaceAccess" USING btree (space_id, account_id);

ALTER TABLE public."SpaceAccess" add constraint "SpaceAccess_pkey" PRIMARY KEY using index "SpaceAccess_pkey";

COMMENT ON COLUMN public."SpaceAccess".account_id IS 'The identity of the account in this space';
19 changes: 7 additions & 12 deletions packages/database/supabase/schemas/account.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ CREATE TABLE IF NOT EXISTS public."Account" (
'public.entity_id_seq'::regclass
) NOT NULL,
platform_id bigint NOT NULL,
person_id bigint NOT NULL,
agent_id bigint NOT NULL,
account_local_id varchar NOT NULL,
write_permission boolean NOT NULL,
active boolean DEFAULT true NOT NULL
);
Expand All @@ -14,8 +15,8 @@ COMMENT ON TABLE public."Account" IS 'A user account on a platform';


ALTER TABLE ONLY public."Account"
ADD CONSTRAINT "Account_person_id_fkey" FOREIGN KEY (
person_id
ADD CONSTRAINT "Account_agent_id_fkey" FOREIGN KEY (
agent_id
) REFERENCES public."Agent" (id) ON UPDATE CASCADE ON DELETE CASCADE;

ALTER TABLE ONLY public."Account"
Expand All @@ -28,23 +29,16 @@ ADD CONSTRAINT "Account_platform_id_fkey" FOREIGN KEY (
ALTER TABLE ONLY public."Account"
ADD CONSTRAINT "Account_pkey" PRIMARY KEY (id);

CREATE UNIQUE INDEX account_platform_and_local_id_idx ON public."Account" USING btree (platform_id, account_local_id);

CREATE TABLE IF NOT EXISTS public."SpaceAccess" (
id bigint DEFAULT nextval(
'public.entity_id_seq'::regclass
) NOT NULL,
space_id bigint,
account_id bigint NOT NULL,
editor boolean NOT NULL
);

ALTER TABLE ONLY public."SpaceAccess"
ADD CONSTRAINT "SpaceAccess_account_id_space_id_key" UNIQUE (
account_id, space_id
);

ALTER TABLE ONLY public."SpaceAccess"
ADD CONSTRAINT "SpaceAccess_pkey" PRIMARY KEY (id);
ADD CONSTRAINT "SpaceAccess_pkey" PRIMARY KEY (space_id, account_id);


ALTER TABLE public."SpaceAccess" OWNER TO "postgres";
Expand All @@ -53,6 +47,7 @@ COMMENT ON TABLE public."SpaceAccess" IS 'An access control entry for a space';

COMMENT ON COLUMN public."SpaceAccess".space_id IS 'The space in which the content is located';

COMMENT ON COLUMN public."SpaceAccess".account_id IS 'The identity of the account in this space';

ALTER TABLE ONLY public."SpaceAccess"
ADD CONSTRAINT "SpaceAccess_account_id_fkey" FOREIGN KEY (
Expand Down
5 changes: 4 additions & 1 deletion packages/database/supabase/schemas/agent.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ CREATE TABLE IF NOT EXISTS public."AutomatedAgent" (
name character varying NOT NULL,
metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
deterministic boolean DEFAULT false,
version character varying
version character varying NOT NULL
);

ALTER TABLE ONLY public."AutomatedAgent"
Expand All @@ -29,6 +29,7 @@ ADD CONSTRAINT automated_agent_id_fkey FOREIGN KEY (
id
) REFERENCES public."Agent" (id) ON UPDATE CASCADE ON DELETE CASCADE;

CREATE UNIQUE INDEX automated_agent_name_version_idx ON public."AutomatedAgent" USING btree (name, version);

ALTER TABLE public."AutomatedAgent" OWNER TO "postgres";

Expand All @@ -49,6 +50,8 @@ ADD CONSTRAINT person_id_fkey FOREIGN KEY (
id
) REFERENCES public."Agent" (id) ON UPDATE CASCADE ON DELETE CASCADE;

CREATE UNIQUE INDEX person_email_idx ON public."Person" USING btree (email);
CREATE UNIQUE INDEX person_orcid_idx ON public."Person" USING btree (orcid);

ALTER TABLE public."Person" OWNER TO "postgres";

Expand Down
4 changes: 3 additions & 1 deletion packages/database/supabase/schemas/concept.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CREATE TABLE IF NOT EXISTS public."Concept" (
author_id bigint,
created timestamp without time zone NOT NULL,
last_modified timestamp without time zone NOT NULL,
space_id bigint,
space_id bigint NOT NULL,
arity smallint DEFAULT 0 NOT NULL,
schema_id bigint,
content jsonb DEFAULT '{}'::jsonb NOT NULL,
Expand Down Expand Up @@ -64,6 +64,8 @@ CREATE UNIQUE INDEX "Concept_represented_by" ON public."Concept" (
represented_by_id
);

CREATE UNIQUE INDEX concept_space_and_name_idx ON public."Concept" (space_id, name);


ALTER TABLE ONLY public."Concept"
ADD CONSTRAINT "Concept_author_id_fkey" FOREIGN KEY (
Expand Down
9 changes: 7 additions & 2 deletions packages/database/supabase/schemas/content.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ ADD CONSTRAINT "Document_space_id_fkey" FOREIGN KEY (
id
) ON UPDATE CASCADE ON DELETE CASCADE;

CREATE UNIQUE INDEX document_space_and_local_id_idx ON public."Document" USING btree (space_id, source_local_id)
NULLS DISTINCT WHERE space_id IS NOT NULL;

CREATE UNIQUE INDEX document_url_idx ON public."Document" USING btree (url);

ALTER TABLE public."Document" OWNER TO "postgres";

COMMENT ON COLUMN public."Document".space_id IS 'The space in which the content is located';
Expand Down Expand Up @@ -114,9 +119,9 @@ CREATE INDEX "Content_part_of" ON public."Content" USING btree (

CREATE INDEX "Content_space" ON public."Content" USING btree (space_id);

CREATE UNIQUE INDEX "Content_space_and_id" ON public."Content" USING btree (
CREATE UNIQUE INDEX content_space_and_local_id_idx ON public."Content" USING btree (
space_id, source_local_id
) WHERE (source_local_id IS NOT NULL);
) NULLS DISTINCT WHERE (space_id IS NOT NULL);

CREATE INDEX "Content_text" ON public."Content" USING pgroonga (text);

Expand Down
23 changes: 13 additions & 10 deletions packages/database/supabase/schemas/space.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ CREATE TABLE IF NOT EXISTS public."Platform" (
url character varying NOT NULL
);

ALTER TABLE public."Platform" OWNER TO "postgres";
ALTER TABLE ONLY public."Platform"
ADD CONSTRAINT "Platform_pkey" PRIMARY KEY (id);

CREATE UNIQUE INDEX platform_url_idx ON public."Platform" USING btree (url);

COMMENT ON TABLE public."Platform" IS
'A data platform where discourse happens';
Expand All @@ -15,29 +18,29 @@ CREATE TABLE IF NOT EXISTS public."Space" (
id bigint DEFAULT nextval(
'public."entity_id_seq"'::regclass
) NOT NULL,
url character varying,
url character varying NOT NULL,
name character varying NOT NULL,
platform_id bigint NOT NULL
);

ALTER TABLE public."Space" OWNER TO "postgres";

COMMENT ON TABLE public."Space" IS
'A space on a platform representing a community engaged in a conversation';

ALTER TABLE ONLY public."Platform"
ADD CONSTRAINT "Platform_pkey" PRIMARY KEY (id);

ALTER TABLE ONLY public."Space"
ADD CONSTRAINT "Space_pkey" PRIMARY KEY (id);

CREATE UNIQUE INDEX space_url_idx ON public."Space" USING btree (url);

ALTER TABLE ONLY public."Space"
ADD CONSTRAINT "Space_platform_id_fkey" FOREIGN KEY (
platform_id
) REFERENCES public."Platform" (
id
) ON UPDATE CASCADE ON DELETE CASCADE;

COMMENT ON TABLE public."Space" IS
'A space on a platform representing a community engaged in a conversation';

ALTER TABLE public."Platform" OWNER TO "postgres";
ALTER TABLE public."Space" OWNER TO "postgres";

GRANT ALL ON TABLE public."Platform" TO anon;
GRANT ALL ON TABLE public."Platform" TO authenticated;
GRANT ALL ON TABLE public."Platform" TO service_role;
Expand Down