mirror of
https://github.com/lukevella/rallly.git
synced 2025-08-06 09:59:00 +02:00
Squashing
This commit is contained in:
parent
a0b0098e5c
commit
dac3766542
4 changed files with 52 additions and 69 deletions
|
@ -53,48 +53,11 @@ export const user = router({
|
|||
});
|
||||
}),
|
||||
delete: privateProcedure.mutation(async ({ ctx }) => {
|
||||
await prisma.$transaction(async (tx) => {
|
||||
const polls = await tx.poll.findMany({
|
||||
select: { id: true },
|
||||
where: {
|
||||
userId: ctx.user.id,
|
||||
},
|
||||
});
|
||||
const pollIds = polls.map((poll) => poll.id);
|
||||
|
||||
await tx.vote.deleteMany({
|
||||
where: { pollId: { in: pollIds } },
|
||||
});
|
||||
await tx.comment.deleteMany({
|
||||
where: { OR: [{ pollId: { in: pollIds } }, { userId: ctx.user.id }] },
|
||||
});
|
||||
await tx.option.deleteMany({
|
||||
where: { pollId: { in: pollIds } },
|
||||
});
|
||||
await tx.participant.deleteMany({
|
||||
where: { OR: [{ pollId: { in: pollIds } }, { userId: ctx.user.id }] },
|
||||
});
|
||||
await tx.watcher.deleteMany({
|
||||
where: { OR: [{ pollId: { in: pollIds } }, { userId: ctx.user.id }] },
|
||||
});
|
||||
await tx.event.deleteMany({
|
||||
where: { userId: ctx.user.id },
|
||||
});
|
||||
await tx.poll.deleteMany({
|
||||
where: { userId: ctx.user.id },
|
||||
});
|
||||
await tx.account.deleteMany({
|
||||
where: { userId: ctx.user.id },
|
||||
});
|
||||
await tx.userPaymentData.deleteMany({
|
||||
where: { userId: ctx.user.id },
|
||||
});
|
||||
await tx.user.delete({
|
||||
await prisma.user.delete({
|
||||
where: {
|
||||
id: ctx.user.id,
|
||||
},
|
||||
});
|
||||
});
|
||||
}),
|
||||
subscription: possiblyPublicProcedure.query(
|
||||
async ({ ctx }): Promise<{ legacy?: boolean; active: boolean }> => {
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- Made the column `user_id` on table `comments` required. This step will fail if there are existing NULL values in that column.
|
||||
- Made the column `user_id` on table `participants` required. This step will fail if there are existing NULL values in that column.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "comments" DROP CONSTRAINT "comments_user_id_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "comments" ALTER COLUMN "user_id" SET NOT NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "participants" ALTER COLUMN "user_id" SET NOT NULL;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "participants" ADD CONSTRAINT "participants_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "comments" ADD CONSTRAINT "comments_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- Made the column `user_id` on table `comments` required. This step will fail if there are existing NULL values in that column.
|
||||
- Made the column `user_id` on table `participants` required. This step will fail if there are existing NULL values in that column.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "comments" DROP CONSTRAINT "comments_user_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "events" DROP CONSTRAINT "events_user_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "users" DROP CONSTRAINT "users_subscription_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "watchers" DROP CONSTRAINT "watchers_user_id_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "comments" ALTER COLUMN "user_id" SET NOT NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "participants" ALTER COLUMN "user_id" SET NOT NULL;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_subscription_id_fkey" FOREIGN KEY ("subscription_id") REFERENCES "subscriptions"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "events" ADD CONSTRAINT "events_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "watchers" ADD CONSTRAINT "watchers_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "participants" ADD CONSTRAINT "participants_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "comments" ADD CONSTRAINT "comments_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@ -52,11 +52,12 @@ model User {
|
|||
customerId String? @map("customer_id")
|
||||
subscriptionId String? @unique @map("subscription_id")
|
||||
|
||||
subscription Subscription? @relation(fields: [subscriptionId], references: [id], onDelete: Cascade)
|
||||
|
||||
comments Comment[]
|
||||
polls Poll[]
|
||||
watcher Watcher[]
|
||||
events Event[]
|
||||
subscription Subscription? @relation(fields: [subscriptionId], references: [id])
|
||||
accounts Account[]
|
||||
participants Participant[]
|
||||
|
||||
|
@ -155,13 +156,13 @@ model Poll {
|
|||
model Event {
|
||||
id String @id @default(cuid())
|
||||
userId String @map("user_id")
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
optionId String @map("option_id")
|
||||
title String
|
||||
start DateTime @db.Timestamp(0)
|
||||
duration Int @default(0) @map("duration_minutes")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
poll Poll?
|
||||
|
||||
@@map("events")
|
||||
|
@ -170,10 +171,10 @@ model Event {
|
|||
model Watcher {
|
||||
id Int @id @default(autoincrement())
|
||||
userId String @map("user_id")
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
pollId String @map("poll_id")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
poll Poll @relation("PollToWatchers", fields: [pollId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([pollId], type: Hash)
|
||||
|
@ -205,9 +206,10 @@ model Option {
|
|||
startTime DateTime @map("start_time") @db.Timestamp(0)
|
||||
duration Int @default(0) @map("duration_minutes")
|
||||
pollId String @map("poll_id")
|
||||
poll Poll @relation("PollToOptions", fields: [pollId], references: [id], onDelete: Cascade)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
|
||||
poll Poll @relation("PollToOptions", fields: [pollId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([pollId], type: Hash)
|
||||
@@map("options")
|
||||
}
|
||||
|
@ -248,7 +250,7 @@ model Comment {
|
|||
updatedAt DateTime? @updatedAt @map("updated_at")
|
||||
|
||||
poll Poll @relation("PollToComments", fields: [pollId], references: [id], onDelete: Cascade)
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([pollId], type: Hash)
|
||||
@@map("comments")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue