atalay
atalay•4w ago

different schemas

Hello guys, can I use same DB with different schemas? Is it gonna work?
78 Replies
lee
lee•4w ago
what would you want to use the different schemas for
atalay
atalayOP•4w ago
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
lee
lee•4w ago
each convex deployment has a single schema and functions from a single convex/ folder
lee
lee•4w ago
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
atalay
atalayOP•4w ago
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
lee
lee•4w ago
Can you explain more about what you're trying to do The schema defines what is in the db
atalay
atalayOP•4w ago
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
lee
lee•4w ago
Oh yes all convex functions need to come from a single convex folder
atalay
atalayOP•4w ago
is convex overwriting queries?
lee
lee•4w ago
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
atalay
atalayOP•4w ago
how I'm gonna do that I can do that in development but in production? whyyy 🥺 this is why I'm getting error
lee
lee•4w ago
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)
atalay
atalayOP•4w ago
yeah this is gonna work in development but I don't think so it's not gonna work on prod
lee
lee•4w ago
Can you explain how you expect prod to work?
atalay
atalayOP•4w ago
just one single folder on 2 different repo is it possible or I need to re-export again? every single time
lee
lee•4w ago
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
atalay
atalayOP•4w ago
but like I said api.ts really buggy
lee
lee•4w ago
In what way is it buggy?
atalay
atalayOP•4w ago
like some queries not generated on my api.ts but on my convex folder it does
lee
lee•4w ago
Because you hadn't rerun the api.ts?
atalay
atalayOP•4w ago
what do you mean re-run no I don't think so cuz I didn't any update
lee
lee•4w ago
I mean rerun npx convex-helpers ts-api-spec
atalay
atalayOP•4w ago
I just ran one time that generation command my queries already in there
lee
lee•4w ago
Ah yeah i think you need to rerun it when the function signatures change
atalay
atalayOP•4w ago
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
lee
lee•4w ago
Hmm so the query is missing from the api.ts file?
atalay
atalayOP•4w ago
yeap and that query is working on api.d.ts way with no problem
lee
lee•4w ago
That is unexpected. The api.ts should contain all functions from your deployment
atalay
atalayOP•4w ago
but it's not... maybe that's why it's beta
lee
lee•4w ago
No, the beta label wouldn't make it skip queries Does api.ts contain any functions?
atalay
atalayOP•4w ago
yes really have more functions, but some of them missing
lee
lee•4w ago
Does the function appear in the convex dashboard "functions" page
atalay
atalayOP•4w ago
and api.ts types is hard to understand every response any, success boolean and message string yes it does
lee
lee•4w ago
To generate return types you would need to set returns validators (like args)
atalay
atalayOP•4w ago
should be already done cuz api.d.ts way all types working and not any
lee
lee•4w ago
api.d.ts does not use returns validators
atalay
atalayOP•4w ago
hmmm I need the return validator nah it should be different what I'm thinking
lee
lee•4w ago
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 it
atalay
atalayOP•4w ago
Can you give me a minute please
atalay
atalayOP•4w ago
This is my auth functions and you can see all of them
No description
atalay
atalayOP•4w ago
And this is the generated api.ts
No description
atalay
atalayOP•4w ago
Literally bunch of missing
lee
lee•4w ago
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
atalay
atalayOP•4w ago
What I'm gonna share? My development url?
atalay
atalayOP•4w ago
I just re-ran that command but I'm getting this error now
No description
atalay
atalayOP•4w ago
Can you know why
lee
lee•4w ago
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 ?
atalay
atalayOP•4w ago
No it's not I already in there, but I fixed with this way:
npx convex function-spec > function-spec.json
npx convex function-spec > function-spec.json
then
npx convex-helpers ts-api-spec --input-file function-spec.json --output-file api.ts
npx convex-helpers ts-api-spec --input-file function-spec.json --output-file api.ts
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
lee
lee•4w ago
good call. i'll fix up that error message. using this api.ts you just made sounds good
atalay
atalayOP•4w ago
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
lee
lee•4w ago
i still don't understand why functions were missing from api.ts
atalay
atalayOP•4w ago
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
lee
lee•4w ago
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 error
atalay
atalayOP•4w ago
like I said I already in convex project path but got error
lee
lee•4w ago
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
atalay
atalayOP•4w ago
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?
lee
lee•4w ago
i don't believe there are plans for that. you may be able to ask Cursor to generate returns validators for everything
atalay
atalayOP•4w ago
LOL, I'm doing that right now you just read my brain and can you explain this if you have time
lee
lee•4w ago
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 server
atalay
atalayOP•4w ago
I 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
atalay
atalayOP•4w ago
I know this has gone on for too long but I just created return validators with cursor but api.ts generated "any" types again
No description
No description
atalay
atalayOP•4w ago
is it true way to do it, or any example for that I need to check
atalay
atalayOP•4w ago
cuz function-spec.json file generated with any types but I already add return validators
No description
lee
lee•4w ago
To double check my understanding, the function-spec.json has return types but the api.ts does not? Strange
atalay
atalayOP•4w ago
also function-spec.json doesn't have return types too it's seems bot of tupe is any
lee
lee•4w ago
This looks like it has return types to me
atalay
atalayOP•4w ago
I just guess, maybe yeah, but there is type field there and it is any
lee
lee•4w ago
The only any i see is the args. Does that function have an args validator?
atalay
atalayOP•4w ago
What do you mean? Can you show me an example please?
lee
lee•4w ago
i mean the only any i see in your screenshot is here
No description
lee
lee•4w ago
which indicates to me that you have a function
export const getCategories = query({
returns: {... something here...},
handler: async (ctx, args) => { ... },
});
export const getCategories = query({
returns: {... something here...},
handler: async (ctx, args) => { ... },
});
which is missing an args: field
atalay
atalayOP•4w ago
@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
atalay
atalayOP•4w ago
atalay
atalayOP•4w ago
what should I do?
atalay
atalayOP•4w ago
giving this error but I'm already using different api import
No description
atalay
atalayOP•4w ago
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...
lee
lee•4w ago
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 anywhere
atalay
atalayOP•4w ago
Yes, 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

Did you find this page helpful?