From 51561e687911e6ca56e7d5e3fde51e1f0193aa72 Mon Sep 17 00:00:00 2001 From: Michael Gartner Date: Sun, 8 Jun 2025 23:16:08 -0600 Subject: [PATCH 1/5] Add access-token table schema to database types and update config for schema path --- packages/database/supabase/config.toml | 1 + .../20250609051037_create_access_table.sql | 68 ++ .../supabase/schemas/access_token.sql | 15 + packages/database/types.gen.ts | 897 +++++++++--------- 4 files changed, 544 insertions(+), 437 deletions(-) create mode 100644 packages/database/supabase/migrations/20250609051037_create_access_table.sql create mode 100644 packages/database/supabase/schemas/access_token.sql diff --git a/packages/database/supabase/config.toml b/packages/database/supabase/config.toml index 6b31d3108..c23ed85be 100644 --- a/packages/database/supabase/config.toml +++ b/packages/database/supabase/config.toml @@ -59,6 +59,7 @@ schema_paths = [ './schemas/contributor.sql', './schemas/sync.sql', './schemas/upload_temp.sql', + './schemas/access_token.sql', ] [db.seed] diff --git a/packages/database/supabase/migrations/20250609051037_create_access_table.sql b/packages/database/supabase/migrations/20250609051037_create_access_table.sql new file mode 100644 index 000000000..bb1fd2b14 --- /dev/null +++ b/packages/database/supabase/migrations/20250609051037_create_access_table.sql @@ -0,0 +1,68 @@ +create table "public"."access-token" ( + "id" bigint generated always as identity not null, + "access-token" text not null, + "code" text, + "state" text, + "created_date" timestamp with time zone not null default timezone('utc'::text, now()) +); + + +CREATE UNIQUE INDEX "access-token_pkey" ON public."access-token" USING btree (id); + +CREATE UNIQUE INDEX access_token_access_token_idx ON public."access-token" USING btree ("access-token"); + +CREATE INDEX access_token_code_idx ON public."access-token" USING btree (code); + +CREATE INDEX access_token_created_date_idx ON public."access-token" USING btree (created_date DESC); + +CREATE INDEX access_token_state_idx ON public."access-token" USING btree (state); + +alter table "public"."access-token" add constraint "access-token_pkey" PRIMARY KEY using index "access-token_pkey"; + +alter table "public"."access-token" add constraint "access_token_code_state_check" CHECK (((code IS NOT NULL) OR (state IS NOT NULL))) not valid; + +alter table "public"."access-token" validate constraint "access_token_code_state_check"; + +grant delete on table "public"."access-token" to "anon"; + +grant insert on table "public"."access-token" to "anon"; + +grant references on table "public"."access-token" to "anon"; + +grant select on table "public"."access-token" to "anon"; + +grant trigger on table "public"."access-token" to "anon"; + +grant truncate on table "public"."access-token" to "anon"; + +grant update on table "public"."access-token" to "anon"; + +grant delete on table "public"."access-token" to "authenticated"; + +grant insert on table "public"."access-token" to "authenticated"; + +grant references on table "public"."access-token" to "authenticated"; + +grant select on table "public"."access-token" to "authenticated"; + +grant trigger on table "public"."access-token" to "authenticated"; + +grant truncate on table "public"."access-token" to "authenticated"; + +grant update on table "public"."access-token" to "authenticated"; + +grant delete on table "public"."access-token" to "service_role"; + +grant insert on table "public"."access-token" to "service_role"; + +grant references on table "public"."access-token" to "service_role"; + +grant select on table "public"."access-token" to "service_role"; + +grant trigger on table "public"."access-token" to "service_role"; + +grant truncate on table "public"."access-token" to "service_role"; + +grant update on table "public"."access-token" to "service_role"; + + diff --git a/packages/database/supabase/schemas/access_token.sql b/packages/database/supabase/schemas/access_token.sql new file mode 100644 index 000000000..01c5e3c48 --- /dev/null +++ b/packages/database/supabase/schemas/access_token.sql @@ -0,0 +1,15 @@ +create table "access-token" ( + id bigint primary key generated always as identity, + "access-token" text not null, + code text, + state text, + created_date timestamp with time zone default timezone('utc'::text, now()) not null, + constraint access_token_code_state_check check ( + (code is not null) or (state is not null) + ) +); + +create unique index access_token_access_token_idx on "access-token" ("access-token"); +create index access_token_code_idx on "access-token" (code); +create index access_token_state_idx on "access-token" (state); +create index access_token_created_date_idx on "access-token" (created_date desc); \ No newline at end of file diff --git a/packages/database/types.gen.ts b/packages/database/types.gen.ts index c433dad00..e3e50ab70 100644 --- a/packages/database/types.gen.ts +++ b/packages/database/types.gen.ts @@ -4,528 +4,552 @@ export type Json = | boolean | null | { [key: string]: Json | undefined } - | Json[] + | Json[]; export type Database = { public: { Tables: { + "access-token": { + Row: { + "access-token": string; + code: string | null; + created_date: string; + id: number; + state: string | null; + }; + Insert: { + "access-token": string; + code?: string | null; + created_date?: string; + id?: never; + state?: string | null; + }; + Update: { + "access-token"?: string; + code?: string | null; + created_date?: string; + id?: never; + state?: string | null; + }; + Relationships: []; + }; AgentIdentifier: { Row: { - account_id: number - identifier_type: Database["public"]["Enums"]["AgentIdentifierType"] - trusted: boolean - value: string - } + account_id: number; + identifier_type: Database["public"]["Enums"]["AgentIdentifierType"]; + trusted: boolean; + value: string; + }; Insert: { - account_id: number - identifier_type: Database["public"]["Enums"]["AgentIdentifierType"] - trusted?: boolean - value: string - } + account_id: number; + identifier_type: Database["public"]["Enums"]["AgentIdentifierType"]; + trusted?: boolean; + value: string; + }; Update: { - account_id?: number - identifier_type?: Database["public"]["Enums"]["AgentIdentifierType"] - trusted?: boolean - value?: string - } + account_id?: number; + identifier_type?: Database["public"]["Enums"]["AgentIdentifierType"]; + trusted?: boolean; + value?: string; + }; Relationships: [ { - foreignKeyName: "AgentIdentifier_account_id_fkey" - columns: ["account_id"] - isOneToOne: false - referencedRelation: "PlatformAccount" - referencedColumns: ["id"] + foreignKeyName: "AgentIdentifier_account_id_fkey"; + columns: ["account_id"]; + isOneToOne: false; + referencedRelation: "PlatformAccount"; + referencedColumns: ["id"]; }, - ] - } + ]; + }; Concept: { Row: { - arity: number - author_id: number | null - content: Json - created: string - description: string | null - epistemic_status: Database["public"]["Enums"]["EpistemicStatus"] - id: number - is_schema: boolean - last_modified: string - name: string - represented_by_id: number | null - schema_id: number | null - space_id: number - } + arity: number; + author_id: number | null; + content: Json; + created: string; + description: string | null; + epistemic_status: Database["public"]["Enums"]["EpistemicStatus"]; + id: number; + is_schema: boolean; + last_modified: string; + name: string; + represented_by_id: number | null; + schema_id: number | null; + space_id: number; + }; Insert: { - arity?: number - author_id?: number | null - content?: Json - created: string - description?: string | null - epistemic_status?: Database["public"]["Enums"]["EpistemicStatus"] - id?: number - is_schema?: boolean - last_modified: string - name: string - represented_by_id?: number | null - schema_id?: number | null - space_id: number - } + arity?: number; + author_id?: number | null; + content?: Json; + created: string; + description?: string | null; + epistemic_status?: Database["public"]["Enums"]["EpistemicStatus"]; + id?: number; + is_schema?: boolean; + last_modified: string; + name: string; + represented_by_id?: number | null; + schema_id?: number | null; + space_id: number; + }; Update: { - arity?: number - author_id?: number | null - content?: Json - created?: string - description?: string | null - epistemic_status?: Database["public"]["Enums"]["EpistemicStatus"] - id?: number - is_schema?: boolean - last_modified?: string - name?: string - represented_by_id?: number | null - schema_id?: number | null - space_id?: number - } + arity?: number; + author_id?: number | null; + content?: Json; + created?: string; + description?: string | null; + epistemic_status?: Database["public"]["Enums"]["EpistemicStatus"]; + id?: number; + is_schema?: boolean; + last_modified?: string; + name?: string; + represented_by_id?: number | null; + schema_id?: number | null; + space_id?: number; + }; Relationships: [ { - foreignKeyName: "Concept_author_id_fkey" - columns: ["author_id"] - isOneToOne: false - referencedRelation: "PlatformAccount" - referencedColumns: ["id"] + foreignKeyName: "Concept_author_id_fkey"; + columns: ["author_id"]; + isOneToOne: false; + referencedRelation: "PlatformAccount"; + referencedColumns: ["id"]; }, { - foreignKeyName: "Concept_represented_by_id_fkey" - columns: ["represented_by_id"] - isOneToOne: false - referencedRelation: "Content" - referencedColumns: ["id"] + foreignKeyName: "Concept_represented_by_id_fkey"; + columns: ["represented_by_id"]; + isOneToOne: false; + referencedRelation: "Content"; + referencedColumns: ["id"]; }, { - foreignKeyName: "Concept_schema_id_fkey" - columns: ["schema_id"] - isOneToOne: false - referencedRelation: "Concept" - referencedColumns: ["id"] + foreignKeyName: "Concept_schema_id_fkey"; + columns: ["schema_id"]; + isOneToOne: false; + referencedRelation: "Concept"; + referencedColumns: ["id"]; }, { - foreignKeyName: "Concept_space_id_fkey" - columns: ["space_id"] - isOneToOne: false - referencedRelation: "Space" - referencedColumns: ["id"] + foreignKeyName: "Concept_space_id_fkey"; + columns: ["space_id"]; + isOneToOne: false; + referencedRelation: "Space"; + referencedColumns: ["id"]; }, - ] - } + ]; + }; concept_contributors: { Row: { - concept_id: number - contributor_id: number - } + concept_id: number; + contributor_id: number; + }; Insert: { - concept_id: number - contributor_id: number - } + concept_id: number; + contributor_id: number; + }; Update: { - concept_id?: number - contributor_id?: number - } + concept_id?: number; + contributor_id?: number; + }; Relationships: [ { - foreignKeyName: "concept_contributors_concept_id_fkey" - columns: ["concept_id"] - isOneToOne: false - referencedRelation: "Concept" - referencedColumns: ["id"] + foreignKeyName: "concept_contributors_concept_id_fkey"; + columns: ["concept_id"]; + isOneToOne: false; + referencedRelation: "Concept"; + referencedColumns: ["id"]; }, { - foreignKeyName: "concept_contributors_contributor_id_fkey" - columns: ["contributor_id"] - isOneToOne: false - referencedRelation: "PlatformAccount" - referencedColumns: ["id"] + foreignKeyName: "concept_contributors_contributor_id_fkey"; + columns: ["contributor_id"]; + isOneToOne: false; + referencedRelation: "PlatformAccount"; + referencedColumns: ["id"]; }, - ] - } + ]; + }; Content: { Row: { - author_id: number | null - created: string - creator_id: number | null - document_id: number - id: number - last_modified: string - metadata: Json - part_of_id: number | null - scale: Database["public"]["Enums"]["Scale"] - source_local_id: string | null - space_id: number | null - text: string - } + author_id: number | null; + created: string; + creator_id: number | null; + document_id: number; + id: number; + last_modified: string; + metadata: Json; + part_of_id: number | null; + scale: Database["public"]["Enums"]["Scale"]; + source_local_id: string | null; + space_id: number | null; + text: string; + }; Insert: { - author_id?: number | null - created: string - creator_id?: number | null - document_id: number - id?: number - last_modified: string - metadata?: Json - part_of_id?: number | null - scale: Database["public"]["Enums"]["Scale"] - source_local_id?: string | null - space_id?: number | null - text: string - } + author_id?: number | null; + created: string; + creator_id?: number | null; + document_id: number; + id?: number; + last_modified: string; + metadata?: Json; + part_of_id?: number | null; + scale: Database["public"]["Enums"]["Scale"]; + source_local_id?: string | null; + space_id?: number | null; + text: string; + }; Update: { - author_id?: number | null - created?: string - creator_id?: number | null - document_id?: number - id?: number - last_modified?: string - metadata?: Json - part_of_id?: number | null - scale?: Database["public"]["Enums"]["Scale"] - source_local_id?: string | null - space_id?: number | null - text?: string - } + author_id?: number | null; + created?: string; + creator_id?: number | null; + document_id?: number; + id?: number; + last_modified?: string; + metadata?: Json; + part_of_id?: number | null; + scale?: Database["public"]["Enums"]["Scale"]; + source_local_id?: string | null; + space_id?: number | null; + text?: string; + }; Relationships: [ { - foreignKeyName: "Content_author_id_fkey" - columns: ["author_id"] - isOneToOne: false - referencedRelation: "PlatformAccount" - referencedColumns: ["id"] + foreignKeyName: "Content_author_id_fkey"; + columns: ["author_id"]; + isOneToOne: false; + referencedRelation: "PlatformAccount"; + referencedColumns: ["id"]; }, { - foreignKeyName: "Content_creator_id_fkey" - columns: ["creator_id"] - isOneToOne: false - referencedRelation: "PlatformAccount" - referencedColumns: ["id"] + foreignKeyName: "Content_creator_id_fkey"; + columns: ["creator_id"]; + isOneToOne: false; + referencedRelation: "PlatformAccount"; + referencedColumns: ["id"]; }, { - foreignKeyName: "Content_document_id_fkey" - columns: ["document_id"] - isOneToOne: false - referencedRelation: "Document" - referencedColumns: ["id"] + foreignKeyName: "Content_document_id_fkey"; + columns: ["document_id"]; + isOneToOne: false; + referencedRelation: "Document"; + referencedColumns: ["id"]; }, { - foreignKeyName: "Content_part_of_id_fkey" - columns: ["part_of_id"] - isOneToOne: false - referencedRelation: "Content" - referencedColumns: ["id"] + foreignKeyName: "Content_part_of_id_fkey"; + columns: ["part_of_id"]; + isOneToOne: false; + referencedRelation: "Content"; + referencedColumns: ["id"]; }, { - foreignKeyName: "Content_space_id_fkey" - columns: ["space_id"] - isOneToOne: false - referencedRelation: "Space" - referencedColumns: ["id"] + foreignKeyName: "Content_space_id_fkey"; + columns: ["space_id"]; + isOneToOne: false; + referencedRelation: "Space"; + referencedColumns: ["id"]; }, - ] - } + ]; + }; content_contributors: { Row: { - content_id: number - contributor_id: number - } + content_id: number; + contributor_id: number; + }; Insert: { - content_id: number - contributor_id: number - } + content_id: number; + contributor_id: number; + }; Update: { - content_id?: number - contributor_id?: number - } + content_id?: number; + contributor_id?: number; + }; Relationships: [ { - foreignKeyName: "content_contributors_content_id_fkey" - columns: ["content_id"] - isOneToOne: false - referencedRelation: "Content" - referencedColumns: ["id"] + foreignKeyName: "content_contributors_content_id_fkey"; + columns: ["content_id"]; + isOneToOne: false; + referencedRelation: "Content"; + referencedColumns: ["id"]; }, { - foreignKeyName: "content_contributors_contributor_id_fkey" - columns: ["contributor_id"] - isOneToOne: false - referencedRelation: "PlatformAccount" - referencedColumns: ["id"] + foreignKeyName: "content_contributors_contributor_id_fkey"; + columns: ["contributor_id"]; + isOneToOne: false; + referencedRelation: "PlatformAccount"; + referencedColumns: ["id"]; }, - ] - } + ]; + }; ContentEmbedding_openai_text_embedding_3_small_1536: { Row: { - model: Database["public"]["Enums"]["EmbeddingName"] - obsolete: boolean | null - target_id: number - vector: string - } + model: Database["public"]["Enums"]["EmbeddingName"]; + obsolete: boolean | null; + target_id: number; + vector: string; + }; Insert: { - model?: Database["public"]["Enums"]["EmbeddingName"] - obsolete?: boolean | null - target_id: number - vector: string - } + model?: Database["public"]["Enums"]["EmbeddingName"]; + obsolete?: boolean | null; + target_id: number; + vector: string; + }; Update: { - model?: Database["public"]["Enums"]["EmbeddingName"] - obsolete?: boolean | null - target_id?: number - vector?: string - } + model?: Database["public"]["Enums"]["EmbeddingName"]; + obsolete?: boolean | null; + target_id?: number; + vector?: string; + }; Relationships: [ { - foreignKeyName: "ContentEmbedding_openai_text_embedding_3_small_1_target_id_fkey" - columns: ["target_id"] - isOneToOne: true - referencedRelation: "Content" - referencedColumns: ["id"] + foreignKeyName: "ContentEmbedding_openai_text_embedding_3_small_1_target_id_fkey"; + columns: ["target_id"]; + isOneToOne: true; + referencedRelation: "Content"; + referencedColumns: ["id"]; }, - ] - } + ]; + }; Document: { Row: { - author_id: number - contents: unknown | null - created: string - id: number - last_modified: string - metadata: Json - source_local_id: string | null - space_id: number | null - url: string | null - } + author_id: number; + contents: unknown | null; + created: string; + id: number; + last_modified: string; + metadata: Json; + source_local_id: string | null; + space_id: number | null; + url: string | null; + }; Insert: { - author_id: number - contents?: unknown | null - created: string - id?: number - last_modified: string - metadata?: Json - source_local_id?: string | null - space_id?: number | null - url?: string | null - } + author_id: number; + contents?: unknown | null; + created: string; + id?: number; + last_modified: string; + metadata?: Json; + source_local_id?: string | null; + space_id?: number | null; + url?: string | null; + }; Update: { - author_id?: number - contents?: unknown | null - created?: string - id?: number - last_modified?: string - metadata?: Json - source_local_id?: string | null - space_id?: number | null - url?: string | null - } + author_id?: number; + contents?: unknown | null; + created?: string; + id?: number; + last_modified?: string; + metadata?: Json; + source_local_id?: string | null; + space_id?: number | null; + url?: string | null; + }; Relationships: [ { - foreignKeyName: "Document_author_id_fkey" - columns: ["author_id"] - isOneToOne: false - referencedRelation: "PlatformAccount" - referencedColumns: ["id"] + foreignKeyName: "Document_author_id_fkey"; + columns: ["author_id"]; + isOneToOne: false; + referencedRelation: "PlatformAccount"; + referencedColumns: ["id"]; }, { - foreignKeyName: "Document_space_id_fkey" - columns: ["space_id"] - isOneToOne: false - referencedRelation: "Space" - referencedColumns: ["id"] + foreignKeyName: "Document_space_id_fkey"; + columns: ["space_id"]; + isOneToOne: false; + referencedRelation: "Space"; + referencedColumns: ["id"]; }, - ] - } + ]; + }; PlatformAccount: { Row: { - account_local_id: string - active: boolean - agent_type: Database["public"]["Enums"]["AgentType"] - dg_account: string | null - id: number - metadata: Json - name: string - platform: Database["public"]["Enums"]["Platform"] - write_permission: boolean - } + account_local_id: string; + active: boolean; + agent_type: Database["public"]["Enums"]["AgentType"]; + dg_account: string | null; + id: number; + metadata: Json; + name: string; + platform: Database["public"]["Enums"]["Platform"]; + write_permission: boolean; + }; Insert: { - account_local_id: string - active?: boolean - agent_type?: Database["public"]["Enums"]["AgentType"] - dg_account?: string | null - id?: number - metadata?: Json - name: string - platform: Database["public"]["Enums"]["Platform"] - write_permission?: boolean - } + account_local_id: string; + active?: boolean; + agent_type?: Database["public"]["Enums"]["AgentType"]; + dg_account?: string | null; + id?: number; + metadata?: Json; + name: string; + platform: Database["public"]["Enums"]["Platform"]; + write_permission?: boolean; + }; Update: { - account_local_id?: string - active?: boolean - agent_type?: Database["public"]["Enums"]["AgentType"] - dg_account?: string | null - id?: number - metadata?: Json - name?: string - platform?: Database["public"]["Enums"]["Platform"] - write_permission?: boolean - } - Relationships: [] - } + account_local_id?: string; + active?: boolean; + agent_type?: Database["public"]["Enums"]["AgentType"]; + dg_account?: string | null; + id?: number; + metadata?: Json; + name?: string; + platform?: Database["public"]["Enums"]["Platform"]; + write_permission?: boolean; + }; + Relationships: []; + }; Space: { Row: { - id: number - name: string - platform: Database["public"]["Enums"]["Platform"] - url: string - } + id: number; + name: string; + platform: Database["public"]["Enums"]["Platform"]; + url: string; + }; Insert: { - id?: number - name: string - platform: Database["public"]["Enums"]["Platform"] - url: string - } + id?: number; + name: string; + platform: Database["public"]["Enums"]["Platform"]; + url: string; + }; Update: { - id?: number - name?: string - platform?: Database["public"]["Enums"]["Platform"] - url?: string - } - Relationships: [] - } + id?: number; + name?: string; + platform?: Database["public"]["Enums"]["Platform"]; + url?: string; + }; + Relationships: []; + }; SpaceAccess: { Row: { - account_id: number - editor: boolean - space_id: number - } + account_id: number; + editor: boolean; + space_id: number; + }; Insert: { - account_id: number - editor: boolean - space_id: number - } + account_id: number; + editor: boolean; + space_id: number; + }; Update: { - account_id?: number - editor?: boolean - space_id?: number - } + account_id?: number; + editor?: boolean; + space_id?: number; + }; Relationships: [ { - foreignKeyName: "SpaceAccess_account_id_fkey" - columns: ["account_id"] - isOneToOne: false - referencedRelation: "PlatformAccount" - referencedColumns: ["id"] + foreignKeyName: "SpaceAccess_account_id_fkey"; + columns: ["account_id"]; + isOneToOne: false; + referencedRelation: "PlatformAccount"; + referencedColumns: ["id"]; }, { - foreignKeyName: "SpaceAccess_space_id_fkey" - columns: ["space_id"] - isOneToOne: false - referencedRelation: "Space" - referencedColumns: ["id"] + foreignKeyName: "SpaceAccess_space_id_fkey"; + columns: ["space_id"]; + isOneToOne: false; + referencedRelation: "Space"; + referencedColumns: ["id"]; }, - ] - } + ]; + }; sync_info: { Row: { - failure_count: number | null - id: number - last_task_end: string | null - last_task_start: string | null - status: Database["public"]["Enums"]["task_status"] | null - sync_function: string | null - sync_target: number | null - task_times_out_at: string | null - worker: string - } + failure_count: number | null; + id: number; + last_task_end: string | null; + last_task_start: string | null; + status: Database["public"]["Enums"]["task_status"] | null; + sync_function: string | null; + sync_target: number | null; + task_times_out_at: string | null; + worker: string; + }; Insert: { - failure_count?: number | null - id?: number - last_task_end?: string | null - last_task_start?: string | null - status?: Database["public"]["Enums"]["task_status"] | null - sync_function?: string | null - sync_target?: number | null - task_times_out_at?: string | null - worker: string - } + failure_count?: number | null; + id?: number; + last_task_end?: string | null; + last_task_start?: string | null; + status?: Database["public"]["Enums"]["task_status"] | null; + sync_function?: string | null; + sync_target?: number | null; + task_times_out_at?: string | null; + worker: string; + }; Update: { - failure_count?: number | null - id?: number - last_task_end?: string | null - last_task_start?: string | null - status?: Database["public"]["Enums"]["task_status"] | null - sync_function?: string | null - sync_target?: number | null - task_times_out_at?: string | null - worker?: string - } - Relationships: [] - } - } + failure_count?: number | null; + id?: number; + last_task_end?: string | null; + last_task_start?: string | null; + status?: Database["public"]["Enums"]["task_status"] | null; + sync_function?: string | null; + sync_target?: number | null; + task_times_out_at?: string | null; + worker?: string; + }; + Relationships: []; + }; + }; Views: { - [_ in never]: never - } + [_ in never]: never; + }; Functions: { end_sync_task: { Args: { - s_target: number - s_function: string - s_worker: string - s_status: Database["public"]["Enums"]["task_status"] - } - Returns: undefined - } + s_target: number; + s_function: string; + s_worker: string; + s_status: Database["public"]["Enums"]["task_status"]; + }; + Returns: undefined; + }; get_nodes_needing_sync: { - Args: { nodes_from_roam: Json } + Args: { nodes_from_roam: Json }; Returns: { - uid_to_sync: string - }[] - } + uid_to_sync: string; + }[]; + }; match_content_embeddings: { Args: { - query_embedding: string - match_threshold: number - match_count: number - current_document_id?: number - } + query_embedding: string; + match_threshold: number; + match_count: number; + current_document_id?: number; + }; Returns: { - content_id: number - roam_uid: string - text_content: string - similarity: number - }[] - } + content_id: number; + roam_uid: string; + text_content: string; + similarity: number; + }[]; + }; match_embeddings_for_subset_nodes: { - Args: { p_query_embedding: string; p_subset_roam_uids: string[] } + Args: { p_query_embedding: string; p_subset_roam_uids: string[] }; Returns: { - content_id: number - roam_uid: string - text_content: string - similarity: number - }[] - } + content_id: number; + roam_uid: string; + text_content: string; + similarity: number; + }[]; + }; propose_sync_task: { Args: { - s_target: number - s_function: string - s_worker: string - timeout: unknown - task_interval: unknown - } - Returns: unknown - } - } + s_target: number; + s_function: string; + s_worker: string; + timeout: unknown; + task_interval: unknown; + }; + Returns: unknown; + }; + }; Enums: { - AgentIdentifierType: "email" | "orcid" - AgentType: "person" | "organization" | "automated_agent" + AgentIdentifierType: "email" | "orcid"; + AgentType: "person" | "organization" | "automated_agent"; EmbeddingName: | "openai_text_embedding_ada2_1536" | "openai_text_embedding_3_small_512" | "openai_text_embedding_3_small_1536" | "openai_text_embedding_3_large_256" | "openai_text_embedding_3_large_1024" - | "openai_text_embedding_3_large_3072" + | "openai_text_embedding_3_large_3072"; EntityType: | "Platform" | "Space" @@ -537,7 +561,7 @@ export type Database = { | "Concept" | "ConceptSchema" | "ContentLink" - | "Occurrence" + | "Occurrence"; EpistemicStatus: | "certainly_not" | "strong_evidence_against" @@ -547,8 +571,8 @@ export type Database = { | "contentious" | "could_be_true" | "strong_evidence_for" - | "certain" - Platform: "Roam" | "Obsidian" + | "certain"; + Platform: "Roam" | "Obsidian"; Scale: | "document" | "post" @@ -559,23 +583,23 @@ export type Database = { | "paragraph" | "quote" | "sentence" - | "phrase" - task_status: "active" | "timeout" | "complete" | "failed" - } + | "phrase"; + task_status: "active" | "timeout" | "complete" | "failed"; + }; CompositeTypes: { - [_ in never]: never - } - } -} + [_ in never]: never; + }; + }; +}; -type DefaultSchema = Database[Extract] +type DefaultSchema = Database[Extract]; export type Tables< DefaultSchemaTableNameOrOptions extends | keyof (DefaultSchema["Tables"] & DefaultSchema["Views"]) | { schema: keyof Database }, TableName extends DefaultSchemaTableNameOrOptions extends { - schema: keyof Database + schema: keyof Database; } ? keyof (Database[DefaultSchemaTableNameOrOptions["schema"]]["Tables"] & Database[DefaultSchemaTableNameOrOptions["schema"]]["Views"]) @@ -583,7 +607,7 @@ export type Tables< > = DefaultSchemaTableNameOrOptions extends { schema: keyof Database } ? (Database[DefaultSchemaTableNameOrOptions["schema"]]["Tables"] & Database[DefaultSchemaTableNameOrOptions["schema"]]["Views"])[TableName] extends { - Row: infer R + Row: infer R; } ? R : never @@ -591,64 +615,64 @@ export type Tables< DefaultSchema["Views"]) ? (DefaultSchema["Tables"] & DefaultSchema["Views"])[DefaultSchemaTableNameOrOptions] extends { - Row: infer R + Row: infer R; } ? R : never - : never + : never; export type TablesInsert< DefaultSchemaTableNameOrOptions extends | keyof DefaultSchema["Tables"] | { schema: keyof Database }, TableName extends DefaultSchemaTableNameOrOptions extends { - schema: keyof Database + schema: keyof Database; } ? keyof Database[DefaultSchemaTableNameOrOptions["schema"]]["Tables"] : never = never, > = DefaultSchemaTableNameOrOptions extends { schema: keyof Database } ? Database[DefaultSchemaTableNameOrOptions["schema"]]["Tables"][TableName] extends { - Insert: infer I + Insert: infer I; } ? I : never : DefaultSchemaTableNameOrOptions extends keyof DefaultSchema["Tables"] ? DefaultSchema["Tables"][DefaultSchemaTableNameOrOptions] extends { - Insert: infer I + Insert: infer I; } ? I : never - : never + : never; export type TablesUpdate< DefaultSchemaTableNameOrOptions extends | keyof DefaultSchema["Tables"] | { schema: keyof Database }, TableName extends DefaultSchemaTableNameOrOptions extends { - schema: keyof Database + schema: keyof Database; } ? keyof Database[DefaultSchemaTableNameOrOptions["schema"]]["Tables"] : never = never, > = DefaultSchemaTableNameOrOptions extends { schema: keyof Database } ? Database[DefaultSchemaTableNameOrOptions["schema"]]["Tables"][TableName] extends { - Update: infer U + Update: infer U; } ? U : never : DefaultSchemaTableNameOrOptions extends keyof DefaultSchema["Tables"] ? DefaultSchema["Tables"][DefaultSchemaTableNameOrOptions] extends { - Update: infer U + Update: infer U; } ? U : never - : never + : never; export type Enums< DefaultSchemaEnumNameOrOptions extends | keyof DefaultSchema["Enums"] | { schema: keyof Database }, EnumName extends DefaultSchemaEnumNameOrOptions extends { - schema: keyof Database + schema: keyof Database; } ? keyof Database[DefaultSchemaEnumNameOrOptions["schema"]]["Enums"] : never = never, @@ -656,14 +680,14 @@ export type Enums< ? Database[DefaultSchemaEnumNameOrOptions["schema"]]["Enums"][EnumName] : DefaultSchemaEnumNameOrOptions extends keyof DefaultSchema["Enums"] ? DefaultSchema["Enums"][DefaultSchemaEnumNameOrOptions] - : never + : never; export type CompositeTypes< PublicCompositeTypeNameOrOptions extends | keyof DefaultSchema["CompositeTypes"] | { schema: keyof Database }, CompositeTypeName extends PublicCompositeTypeNameOrOptions extends { - schema: keyof Database + schema: keyof Database; } ? keyof Database[PublicCompositeTypeNameOrOptions["schema"]]["CompositeTypes"] : never = never, @@ -671,7 +695,7 @@ export type CompositeTypes< ? Database[PublicCompositeTypeNameOrOptions["schema"]]["CompositeTypes"][CompositeTypeName] : PublicCompositeTypeNameOrOptions extends keyof DefaultSchema["CompositeTypes"] ? DefaultSchema["CompositeTypes"][PublicCompositeTypeNameOrOptions] - : never + : never; export const Constants = { public: { @@ -726,5 +750,4 @@ export const Constants = { task_status: ["active", "timeout", "complete", "failed"], }, }, -} as const - +} as const; From f5e2dd32ecc4ccceac9d2600398e0f23a8812002 Mon Sep 17 00:00:00 2001 From: Michael Gartner Date: Mon, 9 Jun 2025 00:14:43 -0600 Subject: [PATCH 2/5] Refactor access-token to access_token in database schema and types for consistency. Update permissions and indexes in SQL migration files. --- .../20250609051037_create_access_table.sql | 62 ++++++++----------- .../supabase/schemas/access_token.sql | 24 +++++-- packages/database/types.gen.ts | 10 +-- 3 files changed, 49 insertions(+), 47 deletions(-) diff --git a/packages/database/supabase/migrations/20250609051037_create_access_table.sql b/packages/database/supabase/migrations/20250609051037_create_access_table.sql index bb1fd2b14..3dcf60c4d 100644 --- a/packages/database/supabase/migrations/20250609051037_create_access_table.sql +++ b/packages/database/supabase/migrations/20250609051037_create_access_table.sql @@ -1,68 +1,58 @@ -create table "public"."access-token" ( +create table "public"."access_token" ( "id" bigint generated always as identity not null, - "access-token" text not null, + "access_token" text not null, "code" text, "state" text, "created_date" timestamp with time zone not null default timezone('utc'::text, now()) ); -CREATE UNIQUE INDEX "access-token_pkey" ON public."access-token" USING btree (id); +CREATE UNIQUE INDEX access_token_access_token_idx ON public.access_token USING btree (access_token); -CREATE UNIQUE INDEX access_token_access_token_idx ON public."access-token" USING btree ("access-token"); +CREATE INDEX access_token_code_idx ON public.access_token USING btree (code); -CREATE INDEX access_token_code_idx ON public."access-token" USING btree (code); +CREATE INDEX access_token_created_date_idx ON public.access_token USING btree (created_date DESC); -CREATE INDEX access_token_created_date_idx ON public."access-token" USING btree (created_date DESC); +CREATE UNIQUE INDEX access_token_pkey ON public.access_token USING btree (id); -CREATE INDEX access_token_state_idx ON public."access-token" USING btree (state); +CREATE INDEX access_token_state_idx ON public.access_token USING btree (state); -alter table "public"."access-token" add constraint "access-token_pkey" PRIMARY KEY using index "access-token_pkey"; +alter table "public"."access_token" add constraint "access_token_pkey" PRIMARY KEY using index "access_token_pkey"; -alter table "public"."access-token" add constraint "access_token_code_state_check" CHECK (((code IS NOT NULL) OR (state IS NOT NULL))) not valid; +alter table "public"."access_token" add constraint "access_token_code_state_check" CHECK (((code IS NOT NULL) OR (state IS NOT NULL))) not valid; -alter table "public"."access-token" validate constraint "access_token_code_state_check"; +alter table "public"."access_token" validate constraint "access_token_code_state_check"; -grant delete on table "public"."access-token" to "anon"; +grant insert on table "public"."access_token" to "anon"; -grant insert on table "public"."access-token" to "anon"; +grant select on table "public"."access_token" to "anon"; -grant references on table "public"."access-token" to "anon"; +grant delete on table "public"."access_token" to "authenticated"; -grant select on table "public"."access-token" to "anon"; +grant insert on table "public"."access_token" to "authenticated"; -grant trigger on table "public"."access-token" to "anon"; +grant references on table "public"."access_token" to "authenticated"; -grant truncate on table "public"."access-token" to "anon"; +grant select on table "public"."access_token" to "authenticated"; -grant update on table "public"."access-token" to "anon"; +grant trigger on table "public"."access_token" to "authenticated"; -grant delete on table "public"."access-token" to "authenticated"; +grant truncate on table "public"."access_token" to "authenticated"; -grant insert on table "public"."access-token" to "authenticated"; +grant update on table "public"."access_token" to "authenticated"; -grant references on table "public"."access-token" to "authenticated"; +grant delete on table "public"."access_token" to "service_role"; -grant select on table "public"."access-token" to "authenticated"; +grant insert on table "public"."access_token" to "service_role"; -grant trigger on table "public"."access-token" to "authenticated"; +grant references on table "public"."access_token" to "service_role"; -grant truncate on table "public"."access-token" to "authenticated"; +grant select on table "public"."access_token" to "service_role"; -grant update on table "public"."access-token" to "authenticated"; +grant trigger on table "public"."access_token" to "service_role"; -grant delete on table "public"."access-token" to "service_role"; +grant truncate on table "public"."access_token" to "service_role"; -grant insert on table "public"."access-token" to "service_role"; - -grant references on table "public"."access-token" to "service_role"; - -grant select on table "public"."access-token" to "service_role"; - -grant trigger on table "public"."access-token" to "service_role"; - -grant truncate on table "public"."access-token" to "service_role"; - -grant update on table "public"."access-token" to "service_role"; +grant update on table "public"."access_token" to "service_role"; diff --git a/packages/database/supabase/schemas/access_token.sql b/packages/database/supabase/schemas/access_token.sql index 01c5e3c48..990921535 100644 --- a/packages/database/supabase/schemas/access_token.sql +++ b/packages/database/supabase/schemas/access_token.sql @@ -1,6 +1,7 @@ -create table "access-token" ( +create table "access_token" ( id bigint primary key generated always as identity, - "access-token" text not null, + -- TODO encrypt this + access_token text not null, code text, state text, created_date timestamp with time zone default timezone('utc'::text, now()) not null, @@ -9,7 +10,18 @@ create table "access-token" ( ) ); -create unique index access_token_access_token_idx on "access-token" ("access-token"); -create index access_token_code_idx on "access-token" (code); -create index access_token_state_idx on "access-token" (state); -create index access_token_created_date_idx on "access-token" (created_date desc); \ No newline at end of file +create unique index access_token_access_token_idx on "access_token" ("access_token"); +create index access_token_code_idx on "access_token" (code); +create index access_token_state_idx on "access_token" (state); +create index access_token_created_date_idx on "access_token" (created_date desc); + +-- Revoke dangerous permissions from anon role +revoke delete on table "public"."access_token" from "anon"; +revoke truncate on table "public"."access_token" from "anon"; +revoke update on table "public"."access_token" from "anon"; +revoke references on table "public"."access_token" from "anon"; +revoke trigger on table "public"."access_token" from "anon"; + +-- Ensure only necessary permissions remain for anon role +grant select on table "public"."access_token" to "anon"; +grant insert on table "public"."access_token" to "anon"; \ No newline at end of file diff --git a/packages/database/types.gen.ts b/packages/database/types.gen.ts index e3e50ab70..25014bcaf 100644 --- a/packages/database/types.gen.ts +++ b/packages/database/types.gen.ts @@ -9,23 +9,23 @@ export type Json = export type Database = { public: { Tables: { - "access-token": { + access_token: { Row: { - "access-token": string; + access_token: string; code: string | null; created_date: string; id: number; state: string | null; }; Insert: { - "access-token": string; + access_token: string; code?: string | null; created_date?: string; id?: never; state?: string | null; }; Update: { - "access-token"?: string; + access_token?: string; code?: string | null; created_date?: string; id?: never; @@ -33,7 +33,7 @@ export type Database = { }; Relationships: []; }; - AgentIdentifier: { + Account: { Row: { account_id: number; identifier_type: Database["public"]["Enums"]["AgentIdentifierType"]; From 5d7bee68794627bf2b3ad69e1c7deefb3cfd2960 Mon Sep 17 00:00:00 2001 From: Michael Gartner Date: Mon, 9 Jun 2025 22:04:21 -0600 Subject: [PATCH 3/5] add platform_account_id to access_token and updating related types --- ...=> 20250610035827_create_access_table.sql} | 7 +++ .../supabase/schemas/access_token.sql | 6 ++- packages/database/types.gen.ts | 54 ++++++++++++++++++- 3 files changed, 64 insertions(+), 3 deletions(-) rename packages/database/supabase/migrations/{20250609051037_create_access_table.sql => 20250610035827_create_access_table.sql} (82%) diff --git a/packages/database/supabase/migrations/20250609051037_create_access_table.sql b/packages/database/supabase/migrations/20250610035827_create_access_table.sql similarity index 82% rename from packages/database/supabase/migrations/20250609051037_create_access_table.sql rename to packages/database/supabase/migrations/20250610035827_create_access_table.sql index 3dcf60c4d..4643d1451 100644 --- a/packages/database/supabase/migrations/20250609051037_create_access_table.sql +++ b/packages/database/supabase/migrations/20250610035827_create_access_table.sql @@ -3,6 +3,7 @@ create table "public"."access_token" ( "access_token" text not null, "code" text, "state" text, + "platform_account_id" bigint, "created_date" timestamp with time zone not null default timezone('utc'::text, now()) ); @@ -15,6 +16,8 @@ CREATE INDEX access_token_created_date_idx ON public.access_token USING btree (c CREATE UNIQUE INDEX access_token_pkey ON public.access_token USING btree (id); +CREATE INDEX access_token_platform_account_id_idx ON public.access_token USING btree (platform_account_id); + CREATE INDEX access_token_state_idx ON public.access_token USING btree (state); alter table "public"."access_token" add constraint "access_token_pkey" PRIMARY KEY using index "access_token_pkey"; @@ -23,6 +26,10 @@ alter table "public"."access_token" add constraint "access_token_code_state_chec alter table "public"."access_token" validate constraint "access_token_code_state_check"; +alter table "public"."access_token" add constraint "access_token_platform_account_id_fkey" FOREIGN KEY (platform_account_id) REFERENCES "PlatformAccount"(id) ON UPDATE CASCADE ON DELETE SET NULL not valid; + +alter table "public"."access_token" validate constraint "access_token_platform_account_id_fkey"; + grant insert on table "public"."access_token" to "anon"; grant select on table "public"."access_token" to "anon"; diff --git a/packages/database/supabase/schemas/access_token.sql b/packages/database/supabase/schemas/access_token.sql index 990921535..130cecbd9 100644 --- a/packages/database/supabase/schemas/access_token.sql +++ b/packages/database/supabase/schemas/access_token.sql @@ -4,16 +4,20 @@ create table "access_token" ( access_token text not null, code text, state text, + platform_account_id bigint, created_date timestamp with time zone default timezone('utc'::text, now()) not null, constraint access_token_code_state_check check ( (code is not null) or (state is not null) - ) + ), + constraint access_token_platform_account_id_fkey foreign key (platform_account_id) + references public."PlatformAccount" (id) on update cascade on delete set null ); create unique index access_token_access_token_idx on "access_token" ("access_token"); create index access_token_code_idx on "access_token" (code); create index access_token_state_idx on "access_token" (state); create index access_token_created_date_idx on "access_token" (created_date desc); +create index access_token_platform_account_id_idx on "access_token" (platform_account_id); -- Revoke dangerous permissions from anon role revoke delete on table "public"."access_token" from "anon"; diff --git a/packages/database/types.gen.ts b/packages/database/types.gen.ts index 25014bcaf..2a94a14d7 100644 --- a/packages/database/types.gen.ts +++ b/packages/database/types.gen.ts @@ -15,6 +15,7 @@ export type Database = { code: string | null; created_date: string; id: number; + platform_account_id: number | null; state: string | null; }; Insert: { @@ -22,6 +23,7 @@ export type Database = { code?: string | null; created_date?: string; id?: never; + platform_account_id?: number | null; state?: string | null; }; Update: { @@ -29,11 +31,20 @@ export type Database = { code?: string | null; created_date?: string; id?: never; + platform_account_id?: number | null; state?: string | null; }; - Relationships: []; + Relationships: [ + { + foreignKeyName: "access_token_platform_account_id_fkey"; + columns: ["platform_account_id"]; + isOneToOne: false; + referencedRelation: "PlatformAccount"; + referencedColumns: ["id"]; + }, + ]; }; - Account: { + AgentIdentifier: { Row: { account_id: number; identifier_type: Database["public"]["Enums"]["AgentIdentifierType"]; @@ -491,6 +502,25 @@ export type Database = { [_ in never]: never; }; Functions: { + alpha_delete_by_source_local_ids: { + Args: { p_space_name: string; p_source_local_ids: string[] }; + Returns: string; + }; + alpha_get_last_update_time: { + Args: { p_space_name: string }; + Returns: { + last_update_time: string; + }[]; + }; + alpha_upsert_discourse_nodes: { + Args: { + p_space_name: string; + p_user_email: string; + p_user_name: string; + p_nodes: Json; + }; + Returns: string; + }; end_sync_task: { Args: { s_target: number; @@ -539,6 +569,26 @@ export type Database = { }; Returns: unknown; }; + upsert_discourse_nodes: { + Args: { + p_space_name: string; + p_user_email: string; + p_user_name: string; + p_nodes: Json; + p_platform_name?: string; + p_platform_url?: string; + p_space_url?: string; + p_agent_type?: string; + p_content_scale?: string; + p_embedding_model?: string; + p_document_source_id?: string; + }; + Returns: { + content_id: number; + embedding_created: boolean; + action: string; + }[]; + }; }; Enums: { AgentIdentifierType: "email" | "orcid"; From b3b744ad70d02ec5e90f7650d39f3fdf1be26c9b Mon Sep 17 00:00:00 2001 From: Michael Gartner Date: Mon, 9 Jun 2025 22:09:03 -0600 Subject: [PATCH 4/5] rm prettier save on types.gen --- packages/database/types.gen.ts | 991 +++++++++++++++++---------------- 1 file changed, 496 insertions(+), 495 deletions(-) diff --git a/packages/database/types.gen.ts b/packages/database/types.gen.ts index 2a94a14d7..a798f73f7 100644 --- a/packages/database/types.gen.ts +++ b/packages/database/types.gen.ts @@ -4,602 +4,602 @@ export type Json = | boolean | null | { [key: string]: Json | undefined } - | Json[]; + | Json[] export type Database = { public: { Tables: { access_token: { Row: { - access_token: string; - code: string | null; - created_date: string; - id: number; - platform_account_id: number | null; - state: string | null; - }; + access_token: string + code: string | null + created_date: string + id: number + platform_account_id: number | null + state: string | null + } Insert: { - access_token: string; - code?: string | null; - created_date?: string; - id?: never; - platform_account_id?: number | null; - state?: string | null; - }; + access_token: string + code?: string | null + created_date?: string + id?: never + platform_account_id?: number | null + state?: string | null + } Update: { - access_token?: string; - code?: string | null; - created_date?: string; - id?: never; - platform_account_id?: number | null; - state?: string | null; - }; + access_token?: string + code?: string | null + created_date?: string + id?: never + platform_account_id?: number | null + state?: string | null + } Relationships: [ { - foreignKeyName: "access_token_platform_account_id_fkey"; - columns: ["platform_account_id"]; - isOneToOne: false; - referencedRelation: "PlatformAccount"; - referencedColumns: ["id"]; + foreignKeyName: "access_token_platform_account_id_fkey" + columns: ["platform_account_id"] + isOneToOne: false + referencedRelation: "PlatformAccount" + referencedColumns: ["id"] }, - ]; - }; + ] + } AgentIdentifier: { Row: { - account_id: number; - identifier_type: Database["public"]["Enums"]["AgentIdentifierType"]; - trusted: boolean; - value: string; - }; + account_id: number + identifier_type: Database["public"]["Enums"]["AgentIdentifierType"] + trusted: boolean + value: string + } Insert: { - account_id: number; - identifier_type: Database["public"]["Enums"]["AgentIdentifierType"]; - trusted?: boolean; - value: string; - }; + account_id: number + identifier_type: Database["public"]["Enums"]["AgentIdentifierType"] + trusted?: boolean + value: string + } Update: { - account_id?: number; - identifier_type?: Database["public"]["Enums"]["AgentIdentifierType"]; - trusted?: boolean; - value?: string; - }; + account_id?: number + identifier_type?: Database["public"]["Enums"]["AgentIdentifierType"] + trusted?: boolean + value?: string + } Relationships: [ { - foreignKeyName: "AgentIdentifier_account_id_fkey"; - columns: ["account_id"]; - isOneToOne: false; - referencedRelation: "PlatformAccount"; - referencedColumns: ["id"]; + foreignKeyName: "AgentIdentifier_account_id_fkey" + columns: ["account_id"] + isOneToOne: false + referencedRelation: "PlatformAccount" + referencedColumns: ["id"] }, - ]; - }; + ] + } Concept: { Row: { - arity: number; - author_id: number | null; - content: Json; - created: string; - description: string | null; - epistemic_status: Database["public"]["Enums"]["EpistemicStatus"]; - id: number; - is_schema: boolean; - last_modified: string; - name: string; - represented_by_id: number | null; - schema_id: number | null; - space_id: number; - }; + arity: number + author_id: number | null + content: Json + created: string + description: string | null + epistemic_status: Database["public"]["Enums"]["EpistemicStatus"] + id: number + is_schema: boolean + last_modified: string + name: string + represented_by_id: number | null + schema_id: number | null + space_id: number + } Insert: { - arity?: number; - author_id?: number | null; - content?: Json; - created: string; - description?: string | null; - epistemic_status?: Database["public"]["Enums"]["EpistemicStatus"]; - id?: number; - is_schema?: boolean; - last_modified: string; - name: string; - represented_by_id?: number | null; - schema_id?: number | null; - space_id: number; - }; + arity?: number + author_id?: number | null + content?: Json + created: string + description?: string | null + epistemic_status?: Database["public"]["Enums"]["EpistemicStatus"] + id?: number + is_schema?: boolean + last_modified: string + name: string + represented_by_id?: number | null + schema_id?: number | null + space_id: number + } Update: { - arity?: number; - author_id?: number | null; - content?: Json; - created?: string; - description?: string | null; - epistemic_status?: Database["public"]["Enums"]["EpistemicStatus"]; - id?: number; - is_schema?: boolean; - last_modified?: string; - name?: string; - represented_by_id?: number | null; - schema_id?: number | null; - space_id?: number; - }; + arity?: number + author_id?: number | null + content?: Json + created?: string + description?: string | null + epistemic_status?: Database["public"]["Enums"]["EpistemicStatus"] + id?: number + is_schema?: boolean + last_modified?: string + name?: string + represented_by_id?: number | null + schema_id?: number | null + space_id?: number + } Relationships: [ { - foreignKeyName: "Concept_author_id_fkey"; - columns: ["author_id"]; - isOneToOne: false; - referencedRelation: "PlatformAccount"; - referencedColumns: ["id"]; + foreignKeyName: "Concept_author_id_fkey" + columns: ["author_id"] + isOneToOne: false + referencedRelation: "PlatformAccount" + referencedColumns: ["id"] }, { - foreignKeyName: "Concept_represented_by_id_fkey"; - columns: ["represented_by_id"]; - isOneToOne: false; - referencedRelation: "Content"; - referencedColumns: ["id"]; + foreignKeyName: "Concept_represented_by_id_fkey" + columns: ["represented_by_id"] + isOneToOne: false + referencedRelation: "Content" + referencedColumns: ["id"] }, { - foreignKeyName: "Concept_schema_id_fkey"; - columns: ["schema_id"]; - isOneToOne: false; - referencedRelation: "Concept"; - referencedColumns: ["id"]; + foreignKeyName: "Concept_schema_id_fkey" + columns: ["schema_id"] + isOneToOne: false + referencedRelation: "Concept" + referencedColumns: ["id"] }, { - foreignKeyName: "Concept_space_id_fkey"; - columns: ["space_id"]; - isOneToOne: false; - referencedRelation: "Space"; - referencedColumns: ["id"]; + foreignKeyName: "Concept_space_id_fkey" + columns: ["space_id"] + isOneToOne: false + referencedRelation: "Space" + referencedColumns: ["id"] }, - ]; - }; + ] + } concept_contributors: { Row: { - concept_id: number; - contributor_id: number; - }; + concept_id: number + contributor_id: number + } Insert: { - concept_id: number; - contributor_id: number; - }; + concept_id: number + contributor_id: number + } Update: { - concept_id?: number; - contributor_id?: number; - }; + concept_id?: number + contributor_id?: number + } Relationships: [ { - foreignKeyName: "concept_contributors_concept_id_fkey"; - columns: ["concept_id"]; - isOneToOne: false; - referencedRelation: "Concept"; - referencedColumns: ["id"]; + foreignKeyName: "concept_contributors_concept_id_fkey" + columns: ["concept_id"] + isOneToOne: false + referencedRelation: "Concept" + referencedColumns: ["id"] }, { - foreignKeyName: "concept_contributors_contributor_id_fkey"; - columns: ["contributor_id"]; - isOneToOne: false; - referencedRelation: "PlatformAccount"; - referencedColumns: ["id"]; + foreignKeyName: "concept_contributors_contributor_id_fkey" + columns: ["contributor_id"] + isOneToOne: false + referencedRelation: "PlatformAccount" + referencedColumns: ["id"] }, - ]; - }; + ] + } Content: { Row: { - author_id: number | null; - created: string; - creator_id: number | null; - document_id: number; - id: number; - last_modified: string; - metadata: Json; - part_of_id: number | null; - scale: Database["public"]["Enums"]["Scale"]; - source_local_id: string | null; - space_id: number | null; - text: string; - }; + author_id: number | null + created: string + creator_id: number | null + document_id: number + id: number + last_modified: string + metadata: Json + part_of_id: number | null + scale: Database["public"]["Enums"]["Scale"] + source_local_id: string | null + space_id: number | null + text: string + } Insert: { - author_id?: number | null; - created: string; - creator_id?: number | null; - document_id: number; - id?: number; - last_modified: string; - metadata?: Json; - part_of_id?: number | null; - scale: Database["public"]["Enums"]["Scale"]; - source_local_id?: string | null; - space_id?: number | null; - text: string; - }; + author_id?: number | null + created: string + creator_id?: number | null + document_id: number + id?: number + last_modified: string + metadata?: Json + part_of_id?: number | null + scale: Database["public"]["Enums"]["Scale"] + source_local_id?: string | null + space_id?: number | null + text: string + } Update: { - author_id?: number | null; - created?: string; - creator_id?: number | null; - document_id?: number; - id?: number; - last_modified?: string; - metadata?: Json; - part_of_id?: number | null; - scale?: Database["public"]["Enums"]["Scale"]; - source_local_id?: string | null; - space_id?: number | null; - text?: string; - }; + author_id?: number | null + created?: string + creator_id?: number | null + document_id?: number + id?: number + last_modified?: string + metadata?: Json + part_of_id?: number | null + scale?: Database["public"]["Enums"]["Scale"] + source_local_id?: string | null + space_id?: number | null + text?: string + } Relationships: [ { - foreignKeyName: "Content_author_id_fkey"; - columns: ["author_id"]; - isOneToOne: false; - referencedRelation: "PlatformAccount"; - referencedColumns: ["id"]; + foreignKeyName: "Content_author_id_fkey" + columns: ["author_id"] + isOneToOne: false + referencedRelation: "PlatformAccount" + referencedColumns: ["id"] }, { - foreignKeyName: "Content_creator_id_fkey"; - columns: ["creator_id"]; - isOneToOne: false; - referencedRelation: "PlatformAccount"; - referencedColumns: ["id"]; + foreignKeyName: "Content_creator_id_fkey" + columns: ["creator_id"] + isOneToOne: false + referencedRelation: "PlatformAccount" + referencedColumns: ["id"] }, { - foreignKeyName: "Content_document_id_fkey"; - columns: ["document_id"]; - isOneToOne: false; - referencedRelation: "Document"; - referencedColumns: ["id"]; + foreignKeyName: "Content_document_id_fkey" + columns: ["document_id"] + isOneToOne: false + referencedRelation: "Document" + referencedColumns: ["id"] }, { - foreignKeyName: "Content_part_of_id_fkey"; - columns: ["part_of_id"]; - isOneToOne: false; - referencedRelation: "Content"; - referencedColumns: ["id"]; + foreignKeyName: "Content_part_of_id_fkey" + columns: ["part_of_id"] + isOneToOne: false + referencedRelation: "Content" + referencedColumns: ["id"] }, { - foreignKeyName: "Content_space_id_fkey"; - columns: ["space_id"]; - isOneToOne: false; - referencedRelation: "Space"; - referencedColumns: ["id"]; + foreignKeyName: "Content_space_id_fkey" + columns: ["space_id"] + isOneToOne: false + referencedRelation: "Space" + referencedColumns: ["id"] }, - ]; - }; + ] + } content_contributors: { Row: { - content_id: number; - contributor_id: number; - }; + content_id: number + contributor_id: number + } Insert: { - content_id: number; - contributor_id: number; - }; + content_id: number + contributor_id: number + } Update: { - content_id?: number; - contributor_id?: number; - }; + content_id?: number + contributor_id?: number + } Relationships: [ { - foreignKeyName: "content_contributors_content_id_fkey"; - columns: ["content_id"]; - isOneToOne: false; - referencedRelation: "Content"; - referencedColumns: ["id"]; + foreignKeyName: "content_contributors_content_id_fkey" + columns: ["content_id"] + isOneToOne: false + referencedRelation: "Content" + referencedColumns: ["id"] }, { - foreignKeyName: "content_contributors_contributor_id_fkey"; - columns: ["contributor_id"]; - isOneToOne: false; - referencedRelation: "PlatformAccount"; - referencedColumns: ["id"]; + foreignKeyName: "content_contributors_contributor_id_fkey" + columns: ["contributor_id"] + isOneToOne: false + referencedRelation: "PlatformAccount" + referencedColumns: ["id"] }, - ]; - }; + ] + } ContentEmbedding_openai_text_embedding_3_small_1536: { Row: { - model: Database["public"]["Enums"]["EmbeddingName"]; - obsolete: boolean | null; - target_id: number; - vector: string; - }; + model: Database["public"]["Enums"]["EmbeddingName"] + obsolete: boolean | null + target_id: number + vector: string + } Insert: { - model?: Database["public"]["Enums"]["EmbeddingName"]; - obsolete?: boolean | null; - target_id: number; - vector: string; - }; + model?: Database["public"]["Enums"]["EmbeddingName"] + obsolete?: boolean | null + target_id: number + vector: string + } Update: { - model?: Database["public"]["Enums"]["EmbeddingName"]; - obsolete?: boolean | null; - target_id?: number; - vector?: string; - }; + model?: Database["public"]["Enums"]["EmbeddingName"] + obsolete?: boolean | null + target_id?: number + vector?: string + } Relationships: [ { - foreignKeyName: "ContentEmbedding_openai_text_embedding_3_small_1_target_id_fkey"; - columns: ["target_id"]; - isOneToOne: true; - referencedRelation: "Content"; - referencedColumns: ["id"]; + foreignKeyName: "ContentEmbedding_openai_text_embedding_3_small_1_target_id_fkey" + columns: ["target_id"] + isOneToOne: true + referencedRelation: "Content" + referencedColumns: ["id"] }, - ]; - }; + ] + } Document: { Row: { - author_id: number; - contents: unknown | null; - created: string; - id: number; - last_modified: string; - metadata: Json; - source_local_id: string | null; - space_id: number | null; - url: string | null; - }; + author_id: number + contents: unknown | null + created: string + id: number + last_modified: string + metadata: Json + source_local_id: string | null + space_id: number | null + url: string | null + } Insert: { - author_id: number; - contents?: unknown | null; - created: string; - id?: number; - last_modified: string; - metadata?: Json; - source_local_id?: string | null; - space_id?: number | null; - url?: string | null; - }; + author_id: number + contents?: unknown | null + created: string + id?: number + last_modified: string + metadata?: Json + source_local_id?: string | null + space_id?: number | null + url?: string | null + } Update: { - author_id?: number; - contents?: unknown | null; - created?: string; - id?: number; - last_modified?: string; - metadata?: Json; - source_local_id?: string | null; - space_id?: number | null; - url?: string | null; - }; + author_id?: number + contents?: unknown | null + created?: string + id?: number + last_modified?: string + metadata?: Json + source_local_id?: string | null + space_id?: number | null + url?: string | null + } Relationships: [ { - foreignKeyName: "Document_author_id_fkey"; - columns: ["author_id"]; - isOneToOne: false; - referencedRelation: "PlatformAccount"; - referencedColumns: ["id"]; + foreignKeyName: "Document_author_id_fkey" + columns: ["author_id"] + isOneToOne: false + referencedRelation: "PlatformAccount" + referencedColumns: ["id"] }, { - foreignKeyName: "Document_space_id_fkey"; - columns: ["space_id"]; - isOneToOne: false; - referencedRelation: "Space"; - referencedColumns: ["id"]; + foreignKeyName: "Document_space_id_fkey" + columns: ["space_id"] + isOneToOne: false + referencedRelation: "Space" + referencedColumns: ["id"] }, - ]; - }; + ] + } PlatformAccount: { Row: { - account_local_id: string; - active: boolean; - agent_type: Database["public"]["Enums"]["AgentType"]; - dg_account: string | null; - id: number; - metadata: Json; - name: string; - platform: Database["public"]["Enums"]["Platform"]; - write_permission: boolean; - }; + account_local_id: string + active: boolean + agent_type: Database["public"]["Enums"]["AgentType"] + dg_account: string | null + id: number + metadata: Json + name: string + platform: Database["public"]["Enums"]["Platform"] + write_permission: boolean + } Insert: { - account_local_id: string; - active?: boolean; - agent_type?: Database["public"]["Enums"]["AgentType"]; - dg_account?: string | null; - id?: number; - metadata?: Json; - name: string; - platform: Database["public"]["Enums"]["Platform"]; - write_permission?: boolean; - }; + account_local_id: string + active?: boolean + agent_type?: Database["public"]["Enums"]["AgentType"] + dg_account?: string | null + id?: number + metadata?: Json + name: string + platform: Database["public"]["Enums"]["Platform"] + write_permission?: boolean + } Update: { - account_local_id?: string; - active?: boolean; - agent_type?: Database["public"]["Enums"]["AgentType"]; - dg_account?: string | null; - id?: number; - metadata?: Json; - name?: string; - platform?: Database["public"]["Enums"]["Platform"]; - write_permission?: boolean; - }; - Relationships: []; - }; + account_local_id?: string + active?: boolean + agent_type?: Database["public"]["Enums"]["AgentType"] + dg_account?: string | null + id?: number + metadata?: Json + name?: string + platform?: Database["public"]["Enums"]["Platform"] + write_permission?: boolean + } + Relationships: [] + } Space: { Row: { - id: number; - name: string; - platform: Database["public"]["Enums"]["Platform"]; - url: string; - }; + id: number + name: string + platform: Database["public"]["Enums"]["Platform"] + url: string + } Insert: { - id?: number; - name: string; - platform: Database["public"]["Enums"]["Platform"]; - url: string; - }; + id?: number + name: string + platform: Database["public"]["Enums"]["Platform"] + url: string + } Update: { - id?: number; - name?: string; - platform?: Database["public"]["Enums"]["Platform"]; - url?: string; - }; - Relationships: []; - }; + id?: number + name?: string + platform?: Database["public"]["Enums"]["Platform"] + url?: string + } + Relationships: [] + } SpaceAccess: { Row: { - account_id: number; - editor: boolean; - space_id: number; - }; + account_id: number + editor: boolean + space_id: number + } Insert: { - account_id: number; - editor: boolean; - space_id: number; - }; + account_id: number + editor: boolean + space_id: number + } Update: { - account_id?: number; - editor?: boolean; - space_id?: number; - }; + account_id?: number + editor?: boolean + space_id?: number + } Relationships: [ { - foreignKeyName: "SpaceAccess_account_id_fkey"; - columns: ["account_id"]; - isOneToOne: false; - referencedRelation: "PlatformAccount"; - referencedColumns: ["id"]; + foreignKeyName: "SpaceAccess_account_id_fkey" + columns: ["account_id"] + isOneToOne: false + referencedRelation: "PlatformAccount" + referencedColumns: ["id"] }, { - foreignKeyName: "SpaceAccess_space_id_fkey"; - columns: ["space_id"]; - isOneToOne: false; - referencedRelation: "Space"; - referencedColumns: ["id"]; + foreignKeyName: "SpaceAccess_space_id_fkey" + columns: ["space_id"] + isOneToOne: false + referencedRelation: "Space" + referencedColumns: ["id"] }, - ]; - }; + ] + } sync_info: { Row: { - failure_count: number | null; - id: number; - last_task_end: string | null; - last_task_start: string | null; - status: Database["public"]["Enums"]["task_status"] | null; - sync_function: string | null; - sync_target: number | null; - task_times_out_at: string | null; - worker: string; - }; + failure_count: number | null + id: number + last_task_end: string | null + last_task_start: string | null + status: Database["public"]["Enums"]["task_status"] | null + sync_function: string | null + sync_target: number | null + task_times_out_at: string | null + worker: string + } Insert: { - failure_count?: number | null; - id?: number; - last_task_end?: string | null; - last_task_start?: string | null; - status?: Database["public"]["Enums"]["task_status"] | null; - sync_function?: string | null; - sync_target?: number | null; - task_times_out_at?: string | null; - worker: string; - }; + failure_count?: number | null + id?: number + last_task_end?: string | null + last_task_start?: string | null + status?: Database["public"]["Enums"]["task_status"] | null + sync_function?: string | null + sync_target?: number | null + task_times_out_at?: string | null + worker: string + } Update: { - failure_count?: number | null; - id?: number; - last_task_end?: string | null; - last_task_start?: string | null; - status?: Database["public"]["Enums"]["task_status"] | null; - sync_function?: string | null; - sync_target?: number | null; - task_times_out_at?: string | null; - worker?: string; - }; - Relationships: []; - }; - }; + failure_count?: number | null + id?: number + last_task_end?: string | null + last_task_start?: string | null + status?: Database["public"]["Enums"]["task_status"] | null + sync_function?: string | null + sync_target?: number | null + task_times_out_at?: string | null + worker?: string + } + Relationships: [] + } + } Views: { - [_ in never]: never; - }; + [_ in never]: never + } Functions: { alpha_delete_by_source_local_ids: { - Args: { p_space_name: string; p_source_local_ids: string[] }; - Returns: string; - }; + Args: { p_space_name: string; p_source_local_ids: string[] } + Returns: string + } alpha_get_last_update_time: { - Args: { p_space_name: string }; + Args: { p_space_name: string } Returns: { - last_update_time: string; - }[]; - }; + last_update_time: string + }[] + } alpha_upsert_discourse_nodes: { Args: { - p_space_name: string; - p_user_email: string; - p_user_name: string; - p_nodes: Json; - }; - Returns: string; - }; + p_space_name: string + p_user_email: string + p_user_name: string + p_nodes: Json + } + Returns: string + } end_sync_task: { Args: { - s_target: number; - s_function: string; - s_worker: string; - s_status: Database["public"]["Enums"]["task_status"]; - }; - Returns: undefined; - }; + s_target: number + s_function: string + s_worker: string + s_status: Database["public"]["Enums"]["task_status"] + } + Returns: undefined + } get_nodes_needing_sync: { - Args: { nodes_from_roam: Json }; + Args: { nodes_from_roam: Json } Returns: { - uid_to_sync: string; - }[]; - }; + uid_to_sync: string + }[] + } match_content_embeddings: { Args: { - query_embedding: string; - match_threshold: number; - match_count: number; - current_document_id?: number; - }; + query_embedding: string + match_threshold: number + match_count: number + current_document_id?: number + } Returns: { - content_id: number; - roam_uid: string; - text_content: string; - similarity: number; - }[]; - }; + content_id: number + roam_uid: string + text_content: string + similarity: number + }[] + } match_embeddings_for_subset_nodes: { - Args: { p_query_embedding: string; p_subset_roam_uids: string[] }; + Args: { p_query_embedding: string; p_subset_roam_uids: string[] } Returns: { - content_id: number; - roam_uid: string; - text_content: string; - similarity: number; - }[]; - }; + content_id: number + roam_uid: string + text_content: string + similarity: number + }[] + } propose_sync_task: { Args: { - s_target: number; - s_function: string; - s_worker: string; - timeout: unknown; - task_interval: unknown; - }; - Returns: unknown; - }; + s_target: number + s_function: string + s_worker: string + timeout: unknown + task_interval: unknown + } + Returns: unknown + } upsert_discourse_nodes: { Args: { - p_space_name: string; - p_user_email: string; - p_user_name: string; - p_nodes: Json; - p_platform_name?: string; - p_platform_url?: string; - p_space_url?: string; - p_agent_type?: string; - p_content_scale?: string; - p_embedding_model?: string; - p_document_source_id?: string; - }; + p_space_name: string + p_user_email: string + p_user_name: string + p_nodes: Json + p_platform_name?: string + p_platform_url?: string + p_space_url?: string + p_agent_type?: string + p_content_scale?: string + p_embedding_model?: string + p_document_source_id?: string + } Returns: { - content_id: number; - embedding_created: boolean; - action: string; - }[]; - }; - }; + content_id: number + embedding_created: boolean + action: string + }[] + } + } Enums: { - AgentIdentifierType: "email" | "orcid"; - AgentType: "person" | "organization" | "automated_agent"; + AgentIdentifierType: "email" | "orcid" + AgentType: "person" | "organization" | "automated_agent" EmbeddingName: | "openai_text_embedding_ada2_1536" | "openai_text_embedding_3_small_512" | "openai_text_embedding_3_small_1536" | "openai_text_embedding_3_large_256" | "openai_text_embedding_3_large_1024" - | "openai_text_embedding_3_large_3072"; + | "openai_text_embedding_3_large_3072" EntityType: | "Platform" | "Space" @@ -611,7 +611,7 @@ export type Database = { | "Concept" | "ConceptSchema" | "ContentLink" - | "Occurrence"; + | "Occurrence" EpistemicStatus: | "certainly_not" | "strong_evidence_against" @@ -621,8 +621,8 @@ export type Database = { | "contentious" | "could_be_true" | "strong_evidence_for" - | "certain"; - Platform: "Roam" | "Obsidian"; + | "certain" + Platform: "Roam" | "Obsidian" Scale: | "document" | "post" @@ -633,23 +633,23 @@ export type Database = { | "paragraph" | "quote" | "sentence" - | "phrase"; - task_status: "active" | "timeout" | "complete" | "failed"; - }; + | "phrase" + task_status: "active" | "timeout" | "complete" | "failed" + } CompositeTypes: { - [_ in never]: never; - }; - }; -}; + [_ in never]: never + } + } +} -type DefaultSchema = Database[Extract]; +type DefaultSchema = Database[Extract] export type Tables< DefaultSchemaTableNameOrOptions extends | keyof (DefaultSchema["Tables"] & DefaultSchema["Views"]) | { schema: keyof Database }, TableName extends DefaultSchemaTableNameOrOptions extends { - schema: keyof Database; + schema: keyof Database } ? keyof (Database[DefaultSchemaTableNameOrOptions["schema"]]["Tables"] & Database[DefaultSchemaTableNameOrOptions["schema"]]["Views"]) @@ -657,7 +657,7 @@ export type Tables< > = DefaultSchemaTableNameOrOptions extends { schema: keyof Database } ? (Database[DefaultSchemaTableNameOrOptions["schema"]]["Tables"] & Database[DefaultSchemaTableNameOrOptions["schema"]]["Views"])[TableName] extends { - Row: infer R; + Row: infer R } ? R : never @@ -665,64 +665,64 @@ export type Tables< DefaultSchema["Views"]) ? (DefaultSchema["Tables"] & DefaultSchema["Views"])[DefaultSchemaTableNameOrOptions] extends { - Row: infer R; + Row: infer R } ? R : never - : never; + : never export type TablesInsert< DefaultSchemaTableNameOrOptions extends | keyof DefaultSchema["Tables"] | { schema: keyof Database }, TableName extends DefaultSchemaTableNameOrOptions extends { - schema: keyof Database; + schema: keyof Database } ? keyof Database[DefaultSchemaTableNameOrOptions["schema"]]["Tables"] : never = never, > = DefaultSchemaTableNameOrOptions extends { schema: keyof Database } ? Database[DefaultSchemaTableNameOrOptions["schema"]]["Tables"][TableName] extends { - Insert: infer I; + Insert: infer I } ? I : never : DefaultSchemaTableNameOrOptions extends keyof DefaultSchema["Tables"] ? DefaultSchema["Tables"][DefaultSchemaTableNameOrOptions] extends { - Insert: infer I; + Insert: infer I } ? I : never - : never; + : never export type TablesUpdate< DefaultSchemaTableNameOrOptions extends | keyof DefaultSchema["Tables"] | { schema: keyof Database }, TableName extends DefaultSchemaTableNameOrOptions extends { - schema: keyof Database; + schema: keyof Database } ? keyof Database[DefaultSchemaTableNameOrOptions["schema"]]["Tables"] : never = never, > = DefaultSchemaTableNameOrOptions extends { schema: keyof Database } ? Database[DefaultSchemaTableNameOrOptions["schema"]]["Tables"][TableName] extends { - Update: infer U; + Update: infer U } ? U : never : DefaultSchemaTableNameOrOptions extends keyof DefaultSchema["Tables"] ? DefaultSchema["Tables"][DefaultSchemaTableNameOrOptions] extends { - Update: infer U; + Update: infer U } ? U : never - : never; + : never export type Enums< DefaultSchemaEnumNameOrOptions extends | keyof DefaultSchema["Enums"] | { schema: keyof Database }, EnumName extends DefaultSchemaEnumNameOrOptions extends { - schema: keyof Database; + schema: keyof Database } ? keyof Database[DefaultSchemaEnumNameOrOptions["schema"]]["Enums"] : never = never, @@ -730,14 +730,14 @@ export type Enums< ? Database[DefaultSchemaEnumNameOrOptions["schema"]]["Enums"][EnumName] : DefaultSchemaEnumNameOrOptions extends keyof DefaultSchema["Enums"] ? DefaultSchema["Enums"][DefaultSchemaEnumNameOrOptions] - : never; + : never export type CompositeTypes< PublicCompositeTypeNameOrOptions extends | keyof DefaultSchema["CompositeTypes"] | { schema: keyof Database }, CompositeTypeName extends PublicCompositeTypeNameOrOptions extends { - schema: keyof Database; + schema: keyof Database } ? keyof Database[PublicCompositeTypeNameOrOptions["schema"]]["CompositeTypes"] : never = never, @@ -745,7 +745,7 @@ export type CompositeTypes< ? Database[PublicCompositeTypeNameOrOptions["schema"]]["CompositeTypes"][CompositeTypeName] : PublicCompositeTypeNameOrOptions extends keyof DefaultSchema["CompositeTypes"] ? DefaultSchema["CompositeTypes"][PublicCompositeTypeNameOrOptions] - : never; + : never export const Constants = { public: { @@ -800,4 +800,5 @@ export const Constants = { task_status: ["active", "timeout", "complete", "failed"], }, }, -} as const; +} as const + From 763792a888eb0833da2bd953bbe9e9233adcf7dd Mon Sep 17 00:00:00 2001 From: Michael Gartner Date: Tue, 10 Jun 2025 14:22:08 -0600 Subject: [PATCH 5/5] Refactor access_token schema and types: replace stace with request_id, remove id, and update constraints. --- ...l => 20250610201801_create_access_table.sql} | 17 ++++++----------- .../database/supabase/schemas/access_token.sql | 15 ++++++--------- packages/database/types.gen.ts | 9 +++------ 3 files changed, 15 insertions(+), 26 deletions(-) rename packages/database/supabase/migrations/{20250610035827_create_access_table.sql => 20250610201801_create_access_table.sql} (83%) diff --git a/packages/database/supabase/migrations/20250610035827_create_access_table.sql b/packages/database/supabase/migrations/20250610201801_create_access_table.sql similarity index 83% rename from packages/database/supabase/migrations/20250610035827_create_access_table.sql rename to packages/database/supabase/migrations/20250610201801_create_access_table.sql index 4643d1451..474fa9185 100644 --- a/packages/database/supabase/migrations/20250610035827_create_access_table.sql +++ b/packages/database/supabase/migrations/20250610201801_create_access_table.sql @@ -1,8 +1,7 @@ create table "public"."access_token" ( - "id" bigint generated always as identity not null, - "access_token" text not null, - "code" text, - "state" text, + "request_id" character varying not null, + "access_token" character varying not null, + "code" character varying, "platform_account_id" bigint, "created_date" timestamp with time zone not null default timezone('utc'::text, now()) ); @@ -12,19 +11,15 @@ CREATE UNIQUE INDEX access_token_access_token_idx ON public.access_token USING b CREATE INDEX access_token_code_idx ON public.access_token USING btree (code); -CREATE INDEX access_token_created_date_idx ON public.access_token USING btree (created_date DESC); - -CREATE UNIQUE INDEX access_token_pkey ON public.access_token USING btree (id); +CREATE UNIQUE INDEX access_token_pkey ON public.access_token USING btree (request_id); CREATE INDEX access_token_platform_account_id_idx ON public.access_token USING btree (platform_account_id); -CREATE INDEX access_token_state_idx ON public.access_token USING btree (state); - alter table "public"."access_token" add constraint "access_token_pkey" PRIMARY KEY using index "access_token_pkey"; -alter table "public"."access_token" add constraint "access_token_code_state_check" CHECK (((code IS NOT NULL) OR (state IS NOT NULL))) not valid; +alter table "public"."access_token" add constraint "access_token_code_check" CHECK ((code IS NOT NULL)) not valid; -alter table "public"."access_token" validate constraint "access_token_code_state_check"; +alter table "public"."access_token" validate constraint "access_token_code_check"; alter table "public"."access_token" add constraint "access_token_platform_account_id_fkey" FOREIGN KEY (platform_account_id) REFERENCES "PlatformAccount"(id) ON UPDATE CASCADE ON DELETE SET NULL not valid; diff --git a/packages/database/supabase/schemas/access_token.sql b/packages/database/supabase/schemas/access_token.sql index 130cecbd9..642022764 100644 --- a/packages/database/supabase/schemas/access_token.sql +++ b/packages/database/supabase/schemas/access_token.sql @@ -1,13 +1,12 @@ create table "access_token" ( - id bigint primary key generated always as identity, - -- TODO encrypt this - access_token text not null, - code text, - state text, + request_id varchar primary key, + -- TODO encrypt this (look into supabase vault) + access_token varchar not null, + code varchar, platform_account_id bigint, created_date timestamp with time zone default timezone('utc'::text, now()) not null, - constraint access_token_code_state_check check ( - (code is not null) or (state is not null) + constraint access_token_code_check check ( + code is not null ), constraint access_token_platform_account_id_fkey foreign key (platform_account_id) references public."PlatformAccount" (id) on update cascade on delete set null @@ -15,8 +14,6 @@ create table "access_token" ( create unique index access_token_access_token_idx on "access_token" ("access_token"); create index access_token_code_idx on "access_token" (code); -create index access_token_state_idx on "access_token" (state); -create index access_token_created_date_idx on "access_token" (created_date desc); create index access_token_platform_account_id_idx on "access_token" (platform_account_id); -- Revoke dangerous permissions from anon role diff --git a/packages/database/types.gen.ts b/packages/database/types.gen.ts index a798f73f7..8cf0f272f 100644 --- a/packages/database/types.gen.ts +++ b/packages/database/types.gen.ts @@ -14,25 +14,22 @@ export type Database = { access_token: string code: string | null created_date: string - id: number platform_account_id: number | null - state: string | null + request_id: string } Insert: { access_token: string code?: string | null created_date?: string - id?: never platform_account_id?: number | null - state?: string | null + request_id: string } Update: { access_token?: string code?: string | null created_date?: string - id?: never platform_account_id?: number | null - state?: string | null + request_id?: string } Relationships: [ {