Skip to content
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

Add support for multiple payers #146

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

dcbr
Copy link
Contributor

@dcbr dcbr commented Apr 22, 2024

This PR adds support for multiple payers of a certain expense. The database changes are minimal and resemble the structure of the paidFor expense field. There's quite some changes to the interface, mostly to the expense form, which are showcased in the video below.

Spliit_multi_payer.mp4

The PR is in a finished state, however it is still marked as draft as I don't know how to provide a correct migration strategy for existing databases (the prisma generated one just seems to drop the paidById column entirely). Some help there would be appreciated. The necessary migration is not too complicated: for each existing expense a new ExpensePaidBy row must be created with participantId equal to the old paidById, expenseId equal to the corresponding expense id and amount equal to the expense's (total) amount.

Closes #14.

Additionally fixes some small bugs regarding amount and balance formatting (this might resolve issues #87 and #140). Also resolves #156 by increasing the upper bound to 10 billion.

@Maxco10
Copy link
Contributor

Maxco10 commented Apr 23, 2024

Good job @dcbr . You should replace "Remove payer" option into dropdown with a "trash icon" close to amount.
An icon is more intuitive for my personal opinion.

@dcbr
Copy link
Contributor Author

dcbr commented Apr 24, 2024

You mean something like this? (This is in mobile viewer)

image

Initially, I didn't opt to introduce an extra icon as I thought it would become too crowded on mobile, but maybe it's just doable.

@Maxco10
Copy link
Contributor

Maxco10 commented Apr 24, 2024

@dcbr it is perfect with this layout for my personal opinion.

@justcallmelarry
Copy link
Contributor

I would put the remove payer button either on the far right or the far left instead of in the middle, personally

@tasken
Copy link

tasken commented May 18, 2024

Align to the right, together with the "add payer"

@dcbr
Copy link
Contributor Author

dcbr commented May 18, 2024

This right alignment is already part of the last commit, I just haven't updated the previous screenshots.
Anybody knows how to implement the correct database migration? Is it the src/scripts/migrate.ts script that needs to be modified or appended to?

@shynst
Copy link
Contributor

shynst commented May 28, 2024

This looks like a great addition! Thank you!

This should do for the database migration: npx prisma migrate dev --name multiple_payers

See here for the docs on prisma: https://www.prisma.io/docs/orm/prisma-migrate/getting-started

@dcbr
Copy link
Contributor Author

dcbr commented May 28, 2024

Yes, I already did that. The problem is that the generated migration commands just drop the old paidById column without transferring it to the new ExpensePaidBy table.
But I can manually modify this file to do so and that also seems to be suggested on their website. I will finish this once I have some more time then.

@shynst
Copy link
Contributor

shynst commented May 29, 2024

I see. You need to manually adjust the migration file. This should do (please test!):

-- CreateTable
CREATE TABLE "ExpensePaidBy" (
    "expenseId" TEXT NOT NULL,
    "participantId" TEXT NOT NULL,
    "amount" INTEGER NOT NULL,

    CONSTRAINT "ExpensePaidBy_pkey" PRIMARY KEY ("expenseId","participantId")
);

-- AddForeignKey
ALTER TABLE "ExpensePaidBy" ADD CONSTRAINT "ExpensePaidBy_expenseId_fkey" FOREIGN KEY ("expenseId") REFERENCES "Expense"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ExpensePaidBy" ADD CONSTRAINT "ExpensePaidBy_participantId_fkey" FOREIGN KEY ("participantId") REFERENCES "Participant"("id") ON DELETE CASCADE ON UPDATE CASCADE;

/*
step 2: copy values of old column "paidById" to new table
*/

INSERT INTO "ExpensePaidBy"
	SELECT "id" AS "expenseId", "paidById" AS "participantId", amount
	FROM "Expense";

/*
step 3: drop old column "paidById"
*/

-- DropForeignKey
ALTER TABLE "Expense" DROP CONSTRAINT "Expense_paidById_fkey";

-- AlterTable
ALTER TABLE "Expense" DROP COLUMN "paidById";

@dcbr dcbr force-pushed the multiple_payers branch 3 times, most recently from a820694 to d95b4bc Compare June 15, 2024 14:06
@dcbr
Copy link
Contributor Author

dcbr commented Jun 15, 2024

I see. You need to manually adjust the migration file. This should do (please test!):

Thanks @shynst, that worked like a charm! :)

The merge conflicts with the main branch are resolved and the database migration is correctly configured now.
This is ready for review.

@dcbr dcbr marked this pull request as ready for review June 15, 2024 14:09
@dcbr dcbr force-pushed the multiple_payers branch from d95b4bc to 5383fc6 Compare June 16, 2024 08:14
@pktiuk
Copy link
Contributor

pktiuk commented Jul 18, 2024

What is this PR waiting for?

@dcbr
Copy link
Contributor Author

dcbr commented Aug 8, 2024

@scastiel could you let me know whether this is a feature you want in spliit or not? Because otherwise it's quite the hassle to continue resolving all conflicts introduced by later PRs.

@rock-meister
Copy link

This is one of the key feature that folks are missing (coming from Splitwise). Is there a decision from the the core contributors that can be shared to the community?

@sir-argupta
Copy link

Hi @dcbr
If you don't mind, then can you please reslove conflicts for this time ??🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow expense values to be larger than 10.000.000 Feature Request: Multi-payer support
8 participants