Need help creating and organizing my schema:
Here's is what I am trying to achieve:
I am working on app that helps users to improve thier essay writing skills. There are three ways they can create an essay:
1) Blank Essay Page, where they have to manually enter an essay title
2) An essay with an already prepared essay title beforehand, so the user needs to pick one, and start writing its content. The essay also needs to have a list of categories for filtering
3) Similar to 2nd one, but this time, along with the essay title, there is a data chart that is also prepared before hand and also has list of categories like economics, science, tech, and etc.
Additionally, all the essay content should be evaluated by an AI and will be assessed based on a sclae of 1-10.
Here's how my initial schema looks like:
blankEssay: defineTable({
title: v.string(),
userId: v.string(),
isArchived: v.boolean(),
content: v.optional(v.string()),
isPublished: v.optional(v.boolean()),
score: v.optional(v.number()),
}).index("by_user", ["userId"]),
chartEssays: defineTable({
title: v.string(),
userId: v.string(),
isArchived: v.boolean(),
content: v.optional(v.string()),
isPublished: v.optional(v.boolean()),
score: v.optional(v.number()),
// additional table for displaying the charts:
chartData: v.optional(v.string()),
}).index("by_user", ["userId"]),
});
It would be great if I could have one table called essays that has a relation to "blankEssays", "selectEssays", chartEssays", and all of these tables had a relationship to "essayCategories" and "score" table. How to achieve that? Please, anyone help...
4 Replies
@KomaSattarov would an essay be able to have more than one chart?
If you can share more info on what chart data might consist of, and whether you may have more than one, I can help a bit further.
Here's a great resource on this @KomaSattarov https://stack.convex.dev/relationship-structures-let-s-talk-about-schemas
Relationship Structures: Let's Talk About Schemas
In this post we’ll look at some patterns for structuring relationships in the Convex database.
Essays with chart data can have one or more charts, should I create an additional table for charts?. Also, if we assume that each essay can either be of Type-A or Type-B, and can also relate to one or more categories (i.e. economics, business, science, and/or tech), how can I achieve this?
BTW, thank you very much for your response
As an experiment, you could try chatting with the AI bot on the docs and see what schema it proposes.
If there’s going to only be <100 charts and they have small amounts of data, you could add them as an array. Otherwise another charts table- see “one-to-many” in the above post. You can use v.union to represent different types but if every field in the document is different you might want one table for each type