I'm kinda curious, are you trying to
I'm kinda curious, are you trying to migrate to convex, or use convex and postgress together?
if you're doing the first, I can probably help you with it (because I'm bored and curious),
for the second, there are a few things that you can do like installing a webhook, and when ever something happens accross your API, you can make calls on, maybe something like supabase can help you with it
17 Replies
hey @Sara , apologies, just saw your message in the channel. I am doing the first, from postgres to convex. Currently I've migrated most routes/internal db calls to convex but have trouble with:
1. Leaderboard component, it seems like I have to restructure my data for convex as convex doesn't do my (overloaded to be fair) subqueries.
2. My postgres tables have an associated id per row and there are some FK constraints that I need to shift to Convex's
_id
column.
Let me know what further information/context you need!have a public repository you'd be willing to share?
only have a private one but I can share the schemas/internal functions as text/files
mmm, if you have time paste the leaderboard tables (and the connections to other tables), and if you're trying to migrate items in tables I suggest using the migration component, it does backfliing for you and is quite easy
but I can help with writing the query for you π
(curiousity kills a cat)
yeah let me paste the leaderboard route/query for you, it's very scrappy π
we used drizzle for the schema definitions
https://discord.com/channels/1019350475847499849/1385157075851673681 I've migrated the fame component now (thread here). I used aggregates and sumValue as the
is_positive
column bool
Would the best way to migrate the id
relational links to use _id
instead be to run the migration from bottom up and replace on matching ids?
I've just given bad advice, no don't use the migration component from postgres to convex, you could use a combonation of both with an ORM and pass the function to convex (.findAll())
ah, is there a stack article/docs link for this? also, doing this online would be quite difficult I presume?
+ if you don't have real users data that you can delete just start from convex
I'm not sure, I'm reading the code you sent me so I'll be 10-20 min
thank you for using drizzle btw
unfortunately we do have live users' data so we can't do that. I think at most, we can pause the existing systems and have a short downtime on the live app if that makes the migration much much easier π
no worries! I'm stepping out for dinner right now, will try to respond asap
HAHA
on this, i was thinking another solution would be to maintain the links using the ids from postgres and then eventually run a migration while support the relational link using the id column. Then the first step would be swap out the values in id for those in _id and then swap the column out to _id
I got lost way too many times, the query is way too long and too much sql strings
those are the tables you've shared,
and part of the query,
for relations you usually index tables using the
.index()
, and use it to find the tables requiredthis could help you with it,
https://stack.convex.dev/functional-relationships-helpers
and I like using filter and map from convex helpers for
Promise.all
and filters
https://www.npmjs.com/package/convex-helpersDatabase Relationship Helpers
Traverse database relationships in a readable, predictable, and debuggable way. Support for one-to-one, one-to-many, and many-to-many via utility func...
npm
convex-helpers
A collection of useful code to complement the official convex package.. Latest version: 0.1.94, last published: 5 days ago. Start using convex-helpers in your project by running
npm i convex-helpers
. There are 16 other projects in the npm registry using convex-helpers.thanks ππ» will take me awhile to dive into your solution. i noticed quite a number of collect calls, i think thats unfeasible especially on the users table? we would hit the limits quite easily
you don't have to do that, you can use the .take(10) instead, that's me being over caffeinated
oh hmm but prior to the take(10), we need to compute the sorted list of either fame/streaks/volume. apart from that i need the list to be paginated as well (itβs like a scrollable component). the sql strings are because the values are bigints and could run into problems if using js numbers too early
there's a bigint reference in js the eco system is fast but not stupid π , I genuinely would consider moving away completely from using sql like that,
pagination would make things simple, you don't have to worry about "limits" within the query itself as its already included (afaik), you could take a look at different stack posts, I'd play around with query streams from convex-helpers too
https://www.npmjs.com/package/convex-helpers#example-1-paginate-all-messages-by-a-fixed-set-of-authors
https://stack.convex.dev/complex-filters-in-convex
Using TypeScript to Write Complex Query Filters
Thereβs a new Convex helper to perform generic TypeScript filters, with the same performance as built-in Convex filters, and unlimited potential.
alright, thank you!