Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 6 additions & 3 deletions packages/database/features/getContext.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ Feature: Get Context
When the user user1 opens the Roam plugin in space abc
Then the database should contain 2 PlatformAccount
And the database should contain 1 AgentIdentifier
And the database should contain 2 SpaceAccess
And the database should contain 1 SpaceAccess
And the database should contain 1 LocalAccess
And the database should contain 1 Space
And a user logged in space abc should see 1 Space in the database
And a user logged in space abc should see 1 AgentIdentifier in the database
And a user logged in space abc should see 2 SpaceAccess in the database
And a user logged in space abc should see 1 SpaceAccess in the database
And a user logged in space abc should see 1 LocalAccess in the database
And a user logged in space abc should see 2 PlatformAccount in the database

Scenario Outline: Calling getContext again
When the user user1 opens the Roam plugin in space abc
Then the database should contain 2 PlatformAccount
And the database should contain 1 Space
And the database should contain 1 AgentIdentifier
And the database should contain 2 SpaceAccess
And the database should contain 1 SpaceAccess
And the database should contain 1 LocalAccess
9 changes: 7 additions & 2 deletions packages/database/schema.puml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ class "PlatformAccount" [[{An account for an agent on a platform}]] {
class "Users" [[{A database user account. Managed by the auth infrastructure.}]] {
{field} id : integer
}
"PlatformAccount" --> "0..1" "Users" : "dg_account"
class "SpaceAccess" [[{An access control entry for a space}]] {
{field} editor : boolean
}
"PlatformAccount" --> "0..1" "Users" : "dg_account"
"SpaceAccess" --> "1" "Users" : "account"
class "Space" [[{A space on a platform representing a community engaged in a conversation}]] {
{field} id : integer
{field} url : string
{field} name : string
{field} platform : Platform
}
"SpaceAccess" --> "1" "PlatformAccount" : "account"
"SpaceAccess" --> "0..1" "Space" : "space"
class "LocalAccess" [[{A record of which platform accounts have used this space}]] {

}
class "Content" [[{A unit of content}]] {
{field} id : integer
{field} source_local_id : string
Expand Down Expand Up @@ -57,6 +60,7 @@ class "Concept" [[{An abstract concept, claim or relation}]] {
{field} literal_content : JSON
{field} is_schema : boolean
}
"LocalAccess" --> "0..1" "Space" : "space"
"Content" --> "0..1" "Space" : "space"
"Document" --> "0..1" "Space" : "space"
"Concept" --> "0..1" "Space" : "space"
Expand All @@ -73,6 +77,7 @@ class "AgentIdentifier" [[{An identifying attribute associated with an agent, ca
"Document" --> "0..*" "PlatformAccount" : "contributors"
"Concept" --> "0..*" "PlatformAccount" : "contributors"
"Content" --> "1" "PlatformAccount" : "creator"
"LocalAccess" --> "1" "PlatformAccount" : "account"
"Content" --> "1" "Document" : "document"
abstract "ContentEmbedding" [[{An embedding for a piece of content.}]] {
{field} model : EmbeddingName
Expand Down
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.
10 changes: 9 additions & 1 deletion packages/database/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,21 @@ classes:
space_url:
unique_key_slots:
- url
LocalAccess:
description: A record of which platform accounts have used this space
slots:
- space
attributes:
account:
range: PlatformAccount
required: true
SpaceAccess:
description: An access control entry for a space
slots:
- space
attributes:
account:
range: PlatformAccount
range: Users
required: true
editor:
range: boolean
Expand Down
65 changes: 47 additions & 18 deletions packages/database/src/dbTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,50 @@ export type Database = {
},
]
}
LocalAccess: {
Row: {
account_id: number
space_id: number
}
Insert: {
account_id: number
space_id: number
}
Update: {
account_id?: number
space_id?: number
}
Relationships: [
{
foreignKeyName: "LocalAccess_account_id_fkey"
columns: ["account_id"]
isOneToOne: false
referencedRelation: "my_accounts"
referencedColumns: ["id"]
},
{
foreignKeyName: "LocalAccess_account_id_fkey"
columns: ["account_id"]
isOneToOne: false
referencedRelation: "PlatformAccount"
referencedColumns: ["id"]
},
{
foreignKeyName: "LocalAccess_space_id_fkey"
columns: ["space_id"]
isOneToOne: false
referencedRelation: "my_spaces"
referencedColumns: ["id"]
},
{
foreignKeyName: "LocalAccess_space_id_fkey"
columns: ["space_id"]
isOneToOne: false
referencedRelation: "Space"
referencedColumns: ["id"]
},
]
}
PlatformAccount: {
Row: {
account_local_id: string
Expand Down Expand Up @@ -603,35 +647,21 @@ export type Database = {
}
SpaceAccess: {
Row: {
account_id: number
account_uid: string
editor: boolean
space_id: number
}
Insert: {
account_id: number
account_uid: string
editor: boolean
space_id: number
}
Update: {
account_id?: number
account_uid?: string
editor?: boolean
space_id?: number
}
Relationships: [
{
foreignKeyName: "SpaceAccess_account_id_fkey"
columns: ["account_id"]
isOneToOne: false
referencedRelation: "my_accounts"
referencedColumns: ["id"]
},
{
foreignKeyName: "SpaceAccess_account_id_fkey"
columns: ["account_id"]
isOneToOne: false
referencedRelation: "PlatformAccount"
referencedColumns: ["id"]
},
{
foreignKeyName: "SpaceAccess_space_id_fkey"
columns: ["space_id"]
Expand Down Expand Up @@ -1472,7 +1502,6 @@ export type Database = {
text_content: string
}[]
}
my_account: { Args: never; Returns: number }
my_space_ids: { Args: never; Returns: number[] }
propose_sync_task: {
Args: {
Expand Down
4 changes: 2 additions & 2 deletions packages/database/supabase/functions/create-space/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ const processAndGetOrCreateSpace = async (
.upsert(
{
space_id,
account_id: anonPlatformUserResult.data.id,
account_uid: anonymousUser.id,
editor: true,
},
{
onConflict: "space_id,account_id",
onConflict: "account_uid,space_id",
ignoreDuplicates: false,
count: "estimated",
},
Expand Down
Loading