devstc
devstc2mo ago

Create a new table programmatically?

If I'm trying to use a backend mutation using insert to create a new table, the insert function only appears to be able to accept table names that already exist, so it doesn't appear I can create a new table that way. Also, I know when I define a table in the schema.ts file and save the file, a new table is created in the database, so perhaps somehow working with the schema.ts file is the way to add new tables programmatically. Is this a method worth pursuing or is there another way that's better? Or is creating a new table programmatically just not possible? In other words, do all new tables have to be created manually? Thanks for any help someone may be able to provide.
5 Replies
Convex Bot
Convex Bot2mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
jamwt
jamwt2mo ago
creating tables programmatically is not possible. however, you can create a virtual table with a table that has two fields: { tableName: v.string(), fields: v.any() } just make sure to index on table name
devstc
devstcOP2mo ago
Thanks Jamie. Not sure what a virtual table is, so I'll have to look into that. So if it's not possible to create tables programmatically, what is the intended way to run a multi-tenant app, keeping each tenants data separated from one another?
jamwt
jamwt2mo ago
An indexed field that indicates the tenantid for each row.
devstc
devstcOP2mo ago
Thanks for taking the time to respond, Jamie! Appreciate the guidance.

Did you find this page helpful?