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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions packages/database/features/addContent.feature
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,52 @@ Feature: Content access
And a user logged in space s1 should see 3 Content in the database
And a user logged in space s1 should see 1 ContentEmbedding_openai_text_embedding_3_small_1536 in the database
And a user logged in space s1 should see 1 Document in the database

Scenario: Full content representations with different content types coexist
When user user1 upserts these documents to space s1:
"""json
[
{
"source_local_id": "page1_uid",
"created": "2000/01/01",
"last_modified": "2001/01/02",
"author_local_id": "user1",
"content_type": "text/markdown"
}
]
"""
And user user1 upserts this content to space s1:
"""json
[
{
"author_local_id": "user1",
"document_local_id": "page1_uid",
"source_local_id": "page1_uid",
"variant": "full",
"scale": "document",
"created": "2000/01/01",
"last_modified": "2001/01/02",
"text": "# Markdown",
"content_type": "text/markdown"
}
]
"""
And user user1 upserts this content to space s1:
"""json
[
{
"author_local_id": "user1",
"document_local_id": "page1_uid",
"source_local_id": "page1_uid",
"variant": "full",
"scale": "document",
"created": "2000/01/01",
"last_modified": "2001/01/02",
"text": "{\"type\":\"root\",\"children\":[]}",
"content_type": "application/vnd.discourse-graph.atjson+json; version=1"
}
]
"""
Then a user logged in space s1 should see 2 Content in the database
And a user logged in space s1 should see 1 content rows with variant "full" and content type "text/markdown"
And a user logged in space s1 should see 1 content rows with variant "full" and content type "application/vnd.discourse-graph.atjson+json; version=1"
25 changes: 25 additions & 0 deletions packages/database/features/step-definitions/stepdefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from "@repo/database/lib/contextFunctions";

type Platform = Enums<"Platform">;
type ContentVariant = Enums<"ContentVariant">;
type TableName = keyof Database["public"]["Tables"];
type LocalRefsType = Record<string, number | string>;
const PLATFORMS: readonly Platform[] = Constants.public.Enums.Platform;
Expand Down Expand Up @@ -307,6 +308,30 @@ Then(
},
);

/* eslint-disable max-params -- Cucumber inspects function.length for step arity. */
Then(
"a user logged in space {word} should see {int} content rows with variant {string} and content type {string}",
async (
spaceName: string,
expectedCount: number,
variant: ContentVariant,
contentType: string,
) => {
const localRefs = (world.localRefs || {}) as LocalRefsType;
const spaceId = localRefs[spaceName];
if (typeof spaceId !== "number") assert.fail("spaceId not a number");
const client = await getLoggedinDatabase(spaceId);
const response = await client
.from("my_contents")
.select("*", { count: "exact", head: true })
.eq("variant", variant)
.eq("content_type", contentType);
assert.equal(response.error, null);
assert.equal(response.count, expectedCount);
},
);
/* eslint-enable max-params */

// invoke the upsert_accounts_in_space function, expects json
Given(
"user {word} upserts these accounts to space {word}:",
Expand Down
31 changes: 25 additions & 6 deletions packages/database/src/dbTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ export type Database = {
}
FileReference: {
Row: {
content_type: string
created: string
filehash: string
filepath: string
Expand All @@ -596,6 +597,7 @@ export type Database = {
variant: Database["public"]["Enums"]["ContentVariant"] | null
}
Insert: {
content_type?: string
created: string
filehash: string
filepath: string
Expand All @@ -605,6 +607,7 @@ export type Database = {
variant?: Database["public"]["Enums"]["ContentVariant"] | null
}
Update: {
content_type?: string
created?: string
filehash?: string
filepath?: string
Expand All @@ -616,24 +619,39 @@ export type Database = {
Relationships: [
{
foreignKeyName: "FileReference_content_fkey"
columns: ["space_id", "source_local_id", "variant"]
columns: ["space_id", "source_local_id", "variant", "content_type"]
isOneToOne: false
referencedRelation: "Content"
referencedColumns: ["space_id", "source_local_id", "variant"]
referencedColumns: [
"space_id",
"source_local_id",
"variant",
"content_type",
]
},
{
foreignKeyName: "FileReference_content_fkey"
columns: ["space_id", "source_local_id", "variant"]
columns: ["space_id", "source_local_id", "variant", "content_type"]
isOneToOne: false
referencedRelation: "my_contents"
referencedColumns: ["space_id", "source_local_id", "variant"]
referencedColumns: [
"space_id",
"source_local_id",
"variant",
"content_type",
]
},
{
foreignKeyName: "FileReference_content_fkey"
columns: ["space_id", "source_local_id", "variant"]
columns: ["space_id", "source_local_id", "variant", "content_type"]
isOneToOne: false
referencedRelation: "my_contents_with_embedding_openai_text_embedding_3_small_1536"
referencedColumns: ["space_id", "source_local_id", "variant"]
referencedColumns: [
"space_id",
"source_local_id",
"variant",
"content_type",
]
},
]
}
Expand Down Expand Up @@ -1164,6 +1182,7 @@ export type Database = {
text: string | null
variant: Database["public"]["Enums"]["ContentVariant"] | null
vector: string | null
content_type: string | null
}
Relationships: [
{
Expand Down
Loading