-
-
Notifications
You must be signed in to change notification settings - Fork 109
WIP: Compute balances in database #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 33 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
a9ed276
Add typed query to get groups with balances
FriesischScott beb89da
Return groups without expenses
FriesischScott df6a7ad
Order groups descending by newest
FriesischScott ab4c7ee
Compute blances for group overview in db
FriesischScott 56af112
Compute balance list in db
FriesischScott de25193
Merge branch 'main' into sql-balances
FriesischScott 24d1b99
Include group id in all balances
FriesischScott 70e58c6
Fix linting
FriesischScott a40ca8c
Move prisma client to src/prisma/client
FriesischScott cee753c
Fix prettier warning
FriesischScott 23fece2
Use path alias to move prisma client
FriesischScott b3002be
gitignore prisma client files
FriesischScott 20fb843
Fix sql imports
FriesischScott 44a3bdd
Set prisma client output
FriesischScott a36344d
Run lint --fix
FriesischScott cd32056
Fix type issues
FriesischScott c619e26
Fix prettier warnings
FriesischScott 646c2e0
Add postgresql service container
FriesischScott 7de67eb
Run migrations before generating sql types
FriesischScott bb996e9
Merge branch 'main' into sql-balances
FriesischScott fa22c43
Remove sql types
FriesischScott 1ff2229
Fix workflow file
FriesischScott 6ff9a98
Fix bigint conversions
FriesischScott 0e5b29c
Fix lint
FriesischScott bec3f4d
Seed db for stress testing
FriesischScott af4c06d
Fix prettier warnings
FriesischScott 2684a71
Exclude seed.ts
FriesischScott 4b02518
Don't set prisma output folder
FriesischScott c26dc4a
Exclude deleted expenses from group balance
FriesischScott 06eea78
Update seed
FriesischScott bca6c9d
Add userid index to ExpenseParticipant
FriesischScott 4dc3d38
Merge branch 'main' into sql-balances
FriesischScott 1f330a5
Fix prettier warnings
FriesischScott 3270d55
Merge remote-tracking branch 'upstream/main' into sql-balances
FriesischScott 510df2e
Format SQL queries
FriesischScott 391f161
Switch service container to ossapps/postgres
FriesischScott File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |
| # database | ||
| /prisma/db.sqlite | ||
| /prisma/db.sqlite-journal | ||
|
|
||
| /src/prisma/client | ||
| # next.js | ||
| /.next/ | ||
| /out/ | ||
|
|
||
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20250618113146_add_expense_participant_userid_index/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- CreateIndex | ||
| CREATE INDEX "ExpenseParticipant_userId_idx" ON "ExpenseParticipant" USING HASH ("userId"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
krokosik marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| -- @param {Int} $1:id of the group | ||
| select "groupId", "userId" as "borrowedBy", "paidBy", "currency", CAST(Coalesce(-1 * sum("ExpenseParticipant".amount),0) as BIGINT) as amount FROM "Expense" | ||
| JOIN "ExpenseParticipant" ON "ExpenseParticipant"."expenseId" = "Expense".id | ||
| WhERE "groupId" = $1 AND "userId" != "paidBy" AND "Expense"."deletedAt" IS NULL | ||
| GROUP BY "userId", "paidBy", "currency", "groupId" | ||
| ORDER By "currency" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| -- @param {Int} $1:id of the user | ||
| SELECT "Group"."id", "Group".name, CAST(Coalesce(sum("ExpenseParticipant".amount),0) as BIGINT) as balance, Coalesce("Expense".currency, "Group"."defaultCurrency") as currency | ||
| FROM "GroupUser" | ||
| JOIN "Group" ON "GroupUser"."groupId" = "Group".id | ||
| LEFT JOIN "Expense" ON "Expense"."groupId" = "Group".id | ||
| LEFT JOIN "ExpenseParticipant" ON "Expense".id = "ExpenseParticipant"."expenseId" | ||
| WHERE "GroupUser"."userId" = $1 AND "deletedAt" IS NULL AND ("ExpenseParticipant"."userId" = $1 OR "Expense".id is null) | ||
| GROUP BY "Group".id, "Group".name, "Expense".currency | ||
| ORDER BY "Group"."createdAt" DESC, balance DESC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original
seedscript is useful for local dev work, while this one takes a long time to execute. Please move it to a separate fileThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My plan was to only use this as and intermediate script and revert to the original before we merge. If you think it's worth keeping around I'll move it to a separate script.