aboutsummaryrefslogtreecommitdiffstats
path: root/src/scripts
diff options
context:
space:
mode:
authorSebastien Castiel <sebastien@castiel.me>2023-12-11 11:39:04 -0500
committerSebastien Castiel <sebastien@castiel.me>2023-12-11 11:39:04 -0500
commit9f7ea9ca5066322db3e1697cc1d7102fe574aebb (patch)
tree5cb648e92eaed74726b02a1e9fd1f90cfe50269a /src/scripts
parent69fa008ea4e1a167e6076a69869388bf012d24b1 (diff)
README
Diffstat (limited to 'src/scripts')
-rw-r--r--src/scripts/migrate.ts14
1 files changed, 9 insertions, 5 deletions
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<number, string> = {}
const expenseIdsMapping: Record<number, string> = {}
- 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) {