Skip to content

Commit 14839cc

Browse files
authored
schema linting (#240)
1 parent 4a418d0 commit 14839cc

File tree

6 files changed

+98
-100
lines changed

6 files changed

+98
-100
lines changed
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
create table "access_token" (
2-
request_id varchar primary key,
3-
-- TODO encrypt this (look into supabase vault)
4-
access_token varchar not null,
5-
code varchar,
6-
platform_account_id bigint,
7-
created_date timestamp with time zone default timezone('utc'::text, now()) not null,
8-
constraint access_token_code_check check (
9-
code is not null
10-
),
11-
constraint access_token_platform_account_id_fkey foreign key (platform_account_id)
2+
request_id varchar primary key,
3+
-- TODO encrypt this (look into supabase vault)
4+
access_token varchar not null,
5+
code varchar,
6+
platform_account_id bigint,
7+
created_date timestamp with time zone default timezone('utc'::text, now()) not null,
8+
constraint access_token_code_check check (
9+
code is not null
10+
),
11+
constraint access_token_platform_account_id_fkey foreign key (platform_account_id)
1212
references public."PlatformAccount" (id) on update cascade on delete set null
1313
);
1414

@@ -25,4 +25,4 @@ revoke trigger on table "public"."access_token" from "anon";
2525

2626
-- Ensure only necessary permissions remain for anon role
2727
grant select on table "public"."access_token" to "anon";
28-
grant insert on table "public"."access_token" to "anon";
28+
grant insert on table "public"."access_token" to "anon";

packages/database/supabase/schemas/account.sql

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ CREATE TABLE IF NOT EXISTS public."PlatformAccount" (
2323
'public.entity_id_seq'::regclass
2424
) NOT NULL PRIMARY KEY,
2525
name VARCHAR NOT NULL,
26-
platform public."Platform" NOT NULL,
26+
platform public."Platform" NOT NULL,
2727
account_local_id VARCHAR NOT NULL,
28-
write_permission BOOLEAN NOT NULL DEFAULT true,
29-
active BOOLEAN NOT NULL DEFAULT true,
30-
agent_type public."AgentType" NOT NULL DEFAULT 'person',
31-
metadata JSONB NOT NULL DEFAULT '{}',
32-
dg_account UUID,
33-
FOREIGN KEY(dg_account) REFERENCES auth.users (id) ON DELETE SET NULL ON UPDATE CASCADE
28+
write_permission BOOLEAN NOT NULL DEFAULT true,
29+
active BOOLEAN NOT NULL DEFAULT true,
30+
agent_type public."AgentType" NOT NULL DEFAULT 'person',
31+
metadata JSONB NOT NULL DEFAULT '{}',
32+
dg_account UUID,
33+
FOREIGN KEY (dg_account) REFERENCES auth.users (id) ON DELETE SET NULL ON UPDATE CASCADE
3434
);
3535

3636
ALTER TABLE public."PlatformAccount" OWNER TO "postgres";
@@ -45,12 +45,12 @@ GRANT ALL ON TABLE public."PlatformAccount" TO service_role;
4545

4646

4747
CREATE TABLE public."AgentIdentifier" (
48-
identifier_type public."AgentIdentifierType" NOT NULL,
49-
account_id BIGINT NOT NULL,
50-
value VARCHAR NOT NULL,
48+
identifier_type public."AgentIdentifierType" NOT NULL,
49+
account_id BIGINT NOT NULL,
50+
value VARCHAR NOT NULL,
5151
trusted BOOLEAN NOT NULL DEFAULT false,
5252
PRIMARY KEY (value, identifier_type, account_id),
53-
FOREIGN KEY(account_id) REFERENCES public."PlatformAccount" (id)
53+
FOREIGN KEY (account_id) REFERENCES public."PlatformAccount" (id)
5454
);
5555

5656
ALTER TABLE public."AgentIdentifier" OWNER TO "postgres";
@@ -97,4 +97,3 @@ ADD CONSTRAINT "SpaceAccess_space_id_fkey" FOREIGN KEY (
9797
GRANT ALL ON TABLE public."SpaceAccess" TO anon;
9898
GRANT ALL ON TABLE public."SpaceAccess" TO authenticated;
9999
GRANT ALL ON TABLE public."SpaceAccess" TO service_role;
100-

packages/database/supabase/schemas/concept.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ CREATE OR REPLACE FUNCTION extract_references(refs JSONB) RETURNS BIGINT [] LANG
1616
SELECT COALESCE(array_agg(i::bigint), '{}') FROM (SELECT DISTINCT jsonb_array_elements(jsonb_path_query_array(refs, '$.*[*]')) i) exrefs;
1717
$$;
1818

19-
CREATE OR REPLACE FUNCTION compute_arity_lit(lit_content JSONB) RETURNS smallint language sql IMMUTABLE AS $$
19+
CREATE OR REPLACE FUNCTION compute_arity_lit(lit_content JSONB) RETURNS smallint LANGUAGE sql IMMUTABLE AS $$
2020
SELECT COALESCE(jsonb_array_length(lit_content->'roles'), 0);
2121
$$;
2222

2323
SET check_function_bodies = false;
24-
CREATE OR REPLACE FUNCTION compute_arity_id(p_schema_id BIGINT) RETURNS smallint language sql IMMUTABLE AS $$
24+
CREATE OR REPLACE FUNCTION compute_arity_id(p_schema_id BIGINT) RETURNS smallint LANGUAGE sql IMMUTABLE AS $$
2525
SELECT COALESCE(jsonb_array_length(literal_content->'roles'), 0) FROM public."Concept" WHERE id=p_schema_id;
2626
$$;
2727
SET check_function_bodies = true;
2828

29-
CREATE OR REPLACE FUNCTION compute_arity_local(schema_id BIGINT, lit_content JSONB) RETURNS smallint language sql IMMUTABLE AS $$
29+
CREATE OR REPLACE FUNCTION compute_arity_local(schema_id BIGINT, lit_content JSONB) RETURNS smallint LANGUAGE sql IMMUTABLE AS $$
3030
SELECT CASE WHEN schema_id IS NULL THEN compute_arity_lit(lit_content) ELSE compute_arity_id(schema_id) END;
3131
$$;
3232

packages/database/supabase/schemas/content.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ BEGIN
228228
END;
229229
$$;
230230

231-
COMMENT ON FUNCTION public._local_document_to_db_document IS 'utility function so we have the option to use platform identifiers for document upsert' ;
231+
COMMENT ON FUNCTION public._local_document_to_db_documentIS 'utility function so we have the option to use platform identifiers for document upsert' ;
232232

233233
-- private function. Transform content with local (platform) references to content with db references
234234
CREATE OR REPLACE FUNCTION public._local_content_to_db_content (data public.content_local_input) RETURNS public."Content" LANGUAGE plpgsql STABLE AS $$
@@ -269,7 +269,7 @@ BEGIN
269269
END;
270270
$$ ;
271271

272-
COMMENT ON FUNCTION public._local_content_to_db_content IS 'utility function so we have the option to use platform identifiers for content upsert' ;
272+
COMMENT ON FUNCTION public._local_content_to_db_contentIS 'utility function so we have the option to use platform identifiers for content upsert' ;
273273

274274
-- The data should be a PlatformAccount
275275
-- PlatformAccount is upserted, based on platform and account_local_id. New (or old) ID is returned.
@@ -358,7 +358,7 @@ BEGIN
358358
END;
359359
$$ ;
360360

361-
COMMENT ON FUNCTION public.upsert_documents IS 'batch document upsert' ;
361+
COMMENT ON FUNCTION public.upsert_documentsIS 'batch document upsert' ;
362362

363363
CREATE OR REPLACE FUNCTION public.upsert_content_embedding (content_id bigint, model varchar, embedding_array float []) RETURNS VOID
364364
LANGUAGE plpgsql
@@ -378,7 +378,7 @@ BEGIN
378378
END
379379
$$ ;
380380

381-
COMMENT ON FUNCTION public.upsert_content_embedding IS 'single content embedding upsert' ;
381+
COMMENT ON FUNCTION public.upsert_content_embeddingIS 'single content embedding upsert' ;
382382

383383
-- The data should be an array of LocalContentDataInput
384384
-- Contents are upserted, based on space_id and local_id. New (or old) IDs are returned.
@@ -498,4 +498,4 @@ BEGIN
498498
END;
499499
$$ ;
500500

501-
COMMENT ON FUNCTION public.upsert_content IS 'batch content upsert' ;
501+
COMMENT ON FUNCTION public.upsert_contentIS 'batch content upsert' ;

packages/database/supabase/schemas/embedding.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,4 @@ ALTER FUNCTION public.match_embeddings_for_subset_nodes (
9898
"p_query_embedding" extensions.vector, "p_subset_roam_uids" Text [])
9999
OWNER TO "postgres" ;
100100

101-
RESET ALL;
101+
RESET ALL ;

0 commit comments

Comments
 (0)