different schemas
Hello guys, can I use same DB with different schemas? Is it gonna work?
78 Replies
what would you want to use the different schemas for
I have admin dashboard site and website admin dashbord do CRUD things for my wesite, but website doesn't do CRUD things so I don't need that schemas
And these are different project but same DB
I cannot run same db 2 project same time in development getting error
I need the close one
each convex deployment has a single schema and functions from a single convex/ folder
but you can connect multiple frontends to the same convex backend https://docs.convex.dev/production/multiple-repos
Multiple Repositories | Convex Developer Hub
Use Convex in multiple repositories
Still don't get it
Can I use same DB but different schema?
yes or no I just need that
Rn maybe I get it if I create api.ts file and replace all generated/api to api.ts is it gonna work with different schemas?
I tried api.ts way but it's so buggy I guess, type-safe structure little bit broken and some queries not included on api.ts which is interesting, code generation really buggy it's not working like api.d.ts
It's totally different maybe because of the beta? I don't know but I'm really sure this problem causing it's not because of me
Can you explain more about what you're trying to do
The schema defines what is in the db
I have 2 different projects but same convex url
when I try to different queries on my project other one getting error
I guess it's not because of schema it's because of different queries
Oh yes all convex functions need to come from a single convex folder
is convex overwriting queries?
If you run npx convex dev from a new project, it will delete all existing queries in the project, replacing them with the ones from the current convex/ directory
how I'm gonna do that I can do that in development but in production?
whyyy 🥺 this is why I'm getting error
Can you put all of the convex functions you want in one convex folder?
(you can import them from somewhere else, as long as they are re-exported from the single convex folder)
yeah this is gonna work in development but I don't think so it's not gonna work on prod
Can you explain how you expect prod to work?
just one single folder on 2 different repo is it possible
or I need to re-export again?
every single time
It is not possible. All of your convex functions should be exported from a single convex folder
If you need to use them from two repos, you would generate an api.ts for the other repo
but like I said api.ts really buggy
In what way is it buggy?
like some queries not generated on my api.ts but on my convex folder it does
Because you hadn't rerun the api.ts?
what do you mean re-run no I don't think so cuz I didn't any update
I mean rerun
npx convex-helpers ts-api-spec
I just ran one time that generation command
my queries already in there
Ah yeah i think you need to rerun it when the function signatures change
but didn't generated
I never changed this is what I'm trying to say
I know api.ts is static file
not working like api.d.ts
Hmm so the query is missing from the api.ts file?
yeap
and that query is working on api.d.ts way with no problem
That is unexpected. The api.ts should contain all functions from your deployment
but it's not... maybe that's why it's beta
No, the beta label wouldn't make it skip queries
Does api.ts contain any functions?
yes
really have more functions, but some of them missing
Does the function appear in the convex dashboard "functions" page
and api.ts types is hard to understand every response any, success boolean and message string
yes it does
To generate return types you would need to set
returns
validators (like args
)should be already done
cuz api.d.ts way all types working and not any
api.d.ts does not use
returns
validatorshmmm
I need the return validator nah it should be different what I'm thinking
If the function appears in the convex dashboard yet
npx convex-helpers ts-api-spec
doesn't include it, that would be a bug. What happens if you rerun the command? Can you provide your deployment url so we can look into itCan you give me a minute please
This is my auth functions and you can see all of them

And this is the generated api.ts

Literally bunch of missing
Yep looks like they're missing. And you reran the command? If you share the url i might be able to see if anything's different about the functions that are missing
What I'm gonna share? My development url?
I just re-ran that command but I'm getting this error now

Can you know why
That error indicates you're running the command in the wrong directory. Can you run it from the same directory you run
npx convex dev
?No it's not I already in there, but I fixed with this way:
then
is it ok? is it optimized or not? looks like there is no missing functions now
I got new api.ts file and it's working let's test it now with that 2 repos
if you say that's okay
good call. i'll fix up that error message. using this api.ts you just made sounds good
awh thank you 🥺
let's test it now then
I hope it's gonna work
that any types broke something? should I return validator? cuz I changed it api path to api.ts and all my queries worked same
i still don't understand why functions were missing from api.ts
me2 lol 😄
probably I missed one thing I don't know which is that, I just gave up and asked ai and maybe ai created api.ts file manually
probably that's because
but for now no missing functions on my api.ts
oh yeah we've observed ai trying to generate api.ts files, that could be it.
i would also like to know why your
npx convex-helpers ts-api-spec
command hit an error. pity we don't print out the errorlike I said I already in convex project path
but got error
Yeah the error message says you're in the wrong directory but it always says that, even if the error is completely different
Gonna fix
Nice to hear that
One more question Lee, why api.ts file functions coming from convex functions which is stored in cloud not local
should be come from local?
I mean I don't get it the logic, local functions should be more logical
I'm getting so much type error because of this, Is there a chance that the working method of api.ts will change in the future?
i don't believe there are plans for that. you may be able to ask Cursor to generate
returns
validators for everythingLOL, I'm doing that right now
you just read my brain
and can you explain this if you have time
convex only parses your functions during
npx convex dev
, on the server. on the client there are typescript types for type-time validation, but for runtime validation and actually defining your functions it's all happening on the serverI see
thank you for your support Lee, I really understand convex multiple repo structure
but maybe document is just not enought detailed there, if your convex functions not on development server api.ts is not generated what you expect (if you working multiple repo convex functions every single time gonna change because you are using npx convex dev) you need the run npx convex dev (for the functions push to convex cloud) then run convex helpers commands
I know this has gone on for too long but I just created return validators with cursor but api.ts generated "any" types again


is it true way to do it, or any example for that I need to check
cuz function-spec.json file generated with any types but I already add return validators

To double check my understanding, the function-spec.json has return types but the api.ts does not? Strange
also function-spec.json doesn't have return types too
it's seems bot of tupe is any
This looks like it has return types to me
I just guess, maybe yeah, but there is type field there and it is any
The only any i see is the args. Does that function have an args validator?
What do you mean?
Can you show me an example please?
i mean the only
any
i see in your screenshot is here
which indicates to me that you have a function
which is missing an
args:
field@lee hey Lee how are you? I'm trying to that repos to production,,, sorry for tag...
one of using default api (convex/generated) import one of using generated (multiple repo way) import
I deploy both of them with this method, I probably shouldn't, because when I deploy using the multiple repo method, the convex backend of my site that uses the default api import does not work
Using Convex with Vercel | Convex Developer Hub
Host your frontend on Vercel and your backend on Convex.
what should I do?
giving this error but I'm already using different api import

Why am I still facing this issue
https://discord.com/channels/1019350475847499849/1335001211077787678/1335011948328128625 this means when am I deploy other repo so should I remove convex provider cuz no need it (using multiple repo import)? and no need the npx convex deploy command?
actually I'm confused right now...
ok Lee I fix that
let me tell you how am I fix
I have an admin and a landing page project, I enter content from admin and show them in landing, I took admin as base backend, I wrote all the functions in it and removed the convex folder in landing page
I converted my base backend to ts file with convex helper command, I copied that ts file to landing project and changed api imports
While deploying, I added base backend to repo as in the document, while I added normal next build to landing page and entered prod database url in env
Both are working now
but I have to say, I found this structure of convex strange, I thought it would allow something like multiple servers and add external functions and schemas, but everything works from a file, very strange...
I don't totally understand what you did to fix it, but good job! Some notes which may be relevant:
1. One repo should have the convex/ folder and that repo should import from the convex/_generated/api.
2. Both repos should have a ConvexProvider, so they can call useQuery and such.
3. The repo with the convex directory should be pushed with
npx convex deploy --cmd "npm run build"
. The other one should just be npm run build
4. For the repo without the convex directory, you should set an env variable in vercel like NEXT_PUBLIC_CONVEX_URL
to your prod deployment url
I think this is probably what you did. Just checking. And you are correct that I don't think we document the multi-repo-for-production flow anywhereYes, this is exactly what I did, but like you said, you guys need to add this document
Cuz document just not enough for that
I found almost everything by trial and error without looking at the documentation, even generating the api.ts file
cuz that helper command on the document giving to me error