From 9f7ea9ca5066322db3e1697cc1d7102fe574aebb Mon Sep 17 00:00:00 2001 From: Sebastien Castiel Date: Mon, 11 Dec 2023 11:39:04 -0500 Subject: README --- src/app/page.tsx | 10 ---------- src/scripts/migrate.ts | 14 +++++++++----- 2 files changed, 9 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/app/page.tsx b/src/app/page.tsx index 77dfed0..e1b43e0 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -33,16 +33,6 @@ export default function HomePage() { Create a group - diff --git a/src/scripts/migrate.ts b/src/scripts/migrate.ts index bf7d93c..beeecc1 100644 --- a/src/scripts/migrate.ts +++ b/src/scripts/migrate.ts @@ -10,6 +10,9 @@ async function main() { withClient(async (client) => { const prisma = await getPrisma() + // console.log('Deleting all groups…') + // await prisma.group.deleteMany({}) + const { rows: groupRows } = await client.query<{ id: string name: string @@ -17,6 +20,10 @@ async function main() { created_at: Date }>('select id, name, currency, created_at from groups') + const existingGroups = ( + await prisma.group.findMany({ select: { id: true } }) + ).map((group) => group.id) + for (const groupRow of groupRows) { const participants: Prisma.ParticipantCreateManyInput[] = [] const expenses: Prisma.ExpenseCreateManyInput[] = [] @@ -24,10 +31,7 @@ async function main() { const participantIdsMapping: Record = {} const expenseIdsMapping: Record = {} - const existingGroup = await prisma.group.findUnique({ - where: { id: groupRow.id }, - }) - if (existingGroup) { + if (existingGroups.includes(groupRow.id)) { console.log(`Group ${groupRow.id} already exists, skipping.`) continue } @@ -65,7 +69,7 @@ async function main() { paid_by_participant_id: number is_reimbursement: boolean }>( - 'select id, created_at, description, amount, paid_by_participant_id, is_reimbursement from expenses where group_id = $1::text', + 'select id, created_at, description, amount, paid_by_participant_id, is_reimbursement from expenses where group_id = $1::text and deleted_at is null', [groupRow.id], ) for (const expenseRow of expenseRows) { -- cgit v1.3