Skip to content

Commit 5e21302

Browse files
committed
Enhance content management by adding support for content types and variants
- Introduced a new scenario in the feature file to test coexistence of different content types. - Updated step definitions to include checks for content rows based on variant and content type. - Modified database types to include `content_type` in relevant tables and relationships. - Adjusted SQL schemas to enforce content type constraints and ensure proper indexing. - Backfilled existing rows with default content types to maintain data integrity.
1 parent 0d85690 commit 5e21302

7 files changed

Lines changed: 351 additions & 15 deletions

File tree

packages/database/features/addContent.feature

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,52 @@ Feature: Content access
133133
And a user logged in space s1 should see 3 Content in the database
134134
And a user logged in space s1 should see 1 ContentEmbedding_openai_text_embedding_3_small_1536 in the database
135135
And a user logged in space s1 should see 1 Document in the database
136+
137+
Scenario: Full content representations with different content types coexist
138+
When user user1 upserts these documents to space s1:
139+
"""json
140+
[
141+
{
142+
"source_local_id": "page1_uid",
143+
"created": "2000/01/01",
144+
"last_modified": "2001/01/02",
145+
"author_local_id": "user1",
146+
"content_type": "text/markdown"
147+
}
148+
]
149+
"""
150+
And user user1 upserts this content to space s1:
151+
"""json
152+
[
153+
{
154+
"author_local_id": "user1",
155+
"document_local_id": "page1_uid",
156+
"source_local_id": "page1_uid",
157+
"variant": "full",
158+
"scale": "document",
159+
"created": "2000/01/01",
160+
"last_modified": "2001/01/02",
161+
"text": "# Markdown",
162+
"content_type": "text/markdown"
163+
}
164+
]
165+
"""
166+
And user user1 upserts this content to space s1:
167+
"""json
168+
[
169+
{
170+
"author_local_id": "user1",
171+
"document_local_id": "page1_uid",
172+
"source_local_id": "page1_uid",
173+
"variant": "full",
174+
"scale": "document",
175+
"created": "2000/01/01",
176+
"last_modified": "2001/01/02",
177+
"text": "{\"type\":\"root\",\"children\":[]}",
178+
"content_type": "application/vnd.discourse-graph.atjson+json; version=1"
179+
}
180+
]
181+
"""
182+
Then a user logged in space s1 should see 2 Content in the database
183+
And a user logged in space s1 should see 1 content rows with variant "full" and content type "text/markdown"
184+
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"

packages/database/features/step-definitions/stepdefs.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from "@repo/database/lib/contextFunctions";
2222

2323
type Platform = Enums<"Platform">;
24+
type ContentVariant = Enums<"ContentVariant">;
2425
type TableName = keyof Database["public"]["Tables"];
2526
type LocalRefsType = Record<string, number | string>;
2627
const PLATFORMS: readonly Platform[] = Constants.public.Enums.Platform;
@@ -307,6 +308,30 @@ Then(
307308
},
308309
);
309310

311+
Then(
312+
"a user logged in space {word} should see {int} content rows with variant {string} and content type {string}",
313+
async (
314+
...[spaceName, expectedCount, variant, contentType]: [
315+
string,
316+
number,
317+
ContentVariant,
318+
string,
319+
]
320+
) => {
321+
const localRefs = (world.localRefs || {}) as LocalRefsType;
322+
const spaceId = localRefs[spaceName];
323+
if (typeof spaceId !== "number") assert.fail("spaceId not a number");
324+
const client = await getLoggedinDatabase(spaceId);
325+
const response = await client
326+
.from("my_contents")
327+
.select("*", { count: "exact", head: true })
328+
.eq("variant", variant)
329+
.eq("content_type", contentType);
330+
assert.equal(response.error, null);
331+
assert.equal(response.count, expectedCount);
332+
},
333+
);
334+
310335
// invoke the upsert_accounts_in_space function, expects json
311336
Given(
312337
"user {word} upserts these accounts to space {word}:",

packages/database/src/dbTypes.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ export type Database = {
587587
}
588588
FileReference: {
589589
Row: {
590+
content_type: string
590591
created: string
591592
filehash: string
592593
filepath: string
@@ -596,6 +597,7 @@ export type Database = {
596597
variant: Database["public"]["Enums"]["ContentVariant"] | null
597598
}
598599
Insert: {
600+
content_type?: string
599601
created: string
600602
filehash: string
601603
filepath: string
@@ -605,6 +607,7 @@ export type Database = {
605607
variant?: Database["public"]["Enums"]["ContentVariant"] | null
606608
}
607609
Update: {
610+
content_type?: string
608611
created?: string
609612
filehash?: string
610613
filepath?: string
@@ -616,24 +619,39 @@ export type Database = {
616619
Relationships: [
617620
{
618621
foreignKeyName: "FileReference_content_fkey"
619-
columns: ["space_id", "source_local_id", "variant"]
622+
columns: ["space_id", "source_local_id", "variant", "content_type"]
620623
isOneToOne: false
621624
referencedRelation: "Content"
622-
referencedColumns: ["space_id", "source_local_id", "variant"]
625+
referencedColumns: [
626+
"space_id",
627+
"source_local_id",
628+
"variant",
629+
"content_type",
630+
]
623631
},
624632
{
625633
foreignKeyName: "FileReference_content_fkey"
626-
columns: ["space_id", "source_local_id", "variant"]
634+
columns: ["space_id", "source_local_id", "variant", "content_type"]
627635
isOneToOne: false
628636
referencedRelation: "my_contents"
629-
referencedColumns: ["space_id", "source_local_id", "variant"]
637+
referencedColumns: [
638+
"space_id",
639+
"source_local_id",
640+
"variant",
641+
"content_type",
642+
]
630643
},
631644
{
632645
foreignKeyName: "FileReference_content_fkey"
633-
columns: ["space_id", "source_local_id", "variant"]
646+
columns: ["space_id", "source_local_id", "variant", "content_type"]
634647
isOneToOne: false
635648
referencedRelation: "my_contents_with_embedding_openai_text_embedding_3_small_1536"
636-
referencedColumns: ["space_id", "source_local_id", "variant"]
649+
referencedColumns: [
650+
"space_id",
651+
"source_local_id",
652+
"variant",
653+
"content_type",
654+
]
637655
},
638656
]
639657
}
@@ -1164,6 +1182,7 @@ export type Database = {
11641182
text: string | null
11651183
variant: Database["public"]["Enums"]["ContentVariant"] | null
11661184
vector: string | null
1185+
content_type: string | null
11671186
}
11681187
Relationships: [
11691188
{

0 commit comments

Comments
 (0)