Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

bug fix

daniel31x13dd78c1570ffa
diff --git a/lib/api/controllers/users/userId/deleteUserById.ts b/lib/api/controllers/users/userId/deleteUserById.ts
index 83b2397a..798583e3 100644
--- a/lib/api/controllers/users/userId/deleteUserById.ts
+++ b/lib/api/controllers/users/userId/deleteUserById.ts
@@ -108,16 +108,6 @@ export default async function deleteUserById(
await prisma
.$transaction(
async (prisma) => {
- // Delete Access Tokens
- await prisma.accessToken.deleteMany({
- where: { userId: queryId },
- });
-
- // Delete whitelisted users
- await prisma.whitelistedUser.deleteMany({
- where: { userId: queryId },
- });
-
const links = await prisma.link.findMany({
where: { collection: { ownerId: queryId } },
select: { id: true },
@@ -127,57 +117,19 @@ export default async function deleteUserById(
await meiliClient?.index("links").deleteDocuments(linkIds);
- // Delete links
- await prisma.link.deleteMany({
- where: { collection: { ownerId: queryId } },
- });
-
- // Delete tags
- await prisma.tag.deleteMany({
- where: { ownerId: queryId },
- });
-
- // Find collections that the user owns
const collections = await prisma.collection.findMany({
where: { ownerId: queryId },
});
await Promise.all(
collections.map(async (collection) => {
- // Delete related users and collections relations
- await prisma.usersAndCollections.deleteMany({
- where: { collectionId: collection.id },
- });
-
- // Delete archive folders
await removeFolder({ filePath: `archives/${collection.id}` });
-
await removeFolder({
filePath: `archives/preview/${collection.id}`,
});
})
);
- // Delete collections after cleaning up related data
- await prisma.collection.deleteMany({
- where: { ownerId: queryId },
- });
-
- // Delete subscription
- if (process.env.STRIPE_SECRET_KEY)
- await prisma.subscription
- .delete({
- where: { userId: queryId },
- })
- .catch((err) => console.log(err));
-
- await prisma.usersAndCollections.deleteMany({
- where: {
- OR: [{ userId: queryId }, { collection: { ownerId: queryId } }],
- },
- });
-
- // Delete user's avatar
await removeFile({ filePath: `uploads/avatar/${queryId}.jpg` });
// Finally, delete the user
diff --git a/lib/api/rssHandler.ts b/lib/api/rssHandler.ts
index 2a8a71b6..985afe5f 100644
--- a/lib/api/rssHandler.ts
+++ b/lib/api/rssHandler.ts
@@ -54,7 +54,7 @@ const rssHandler = async (rssSubscription: RssSubscription, parser: Parser) => {
data: {
name: item.title,
url: item.link,
- type: "link",
+ type: "url",
createdBy: {
connect: {
id: rssSubscription.ownerId,
diff --git a/prisma/migrations/20250318123928_add_referential_actions_to_certain_fields/migration.sql b/prisma/migrations/20250318123928_add_referential_actions_to_certain_fields/migration.sql
new file mode 100644
index 00000000..c737a486
--- /dev/null
+++ b/prisma/migrations/20250318123928_add_referential_actions_to_certain_fields/migration.sql
@@ -0,0 +1,65 @@
+-- DropForeignKey
+ALTER TABLE "AccessToken" DROP CONSTRAINT "AccessToken_userId_fkey";
+
+-- DropForeignKey
+ALTER TABLE "Collection" DROP CONSTRAINT "Collection_parentId_fkey";
+
+-- DropForeignKey
+ALTER TABLE "Highlight" DROP CONSTRAINT "Highlight_linkId_fkey";
+
+-- DropForeignKey
+ALTER TABLE "Highlight" DROP CONSTRAINT "Highlight_userId_fkey";
+
+-- DropForeignKey
+ALTER TABLE "Link" DROP CONSTRAINT "Link_collectionId_fkey";
+
+-- DropForeignKey
+ALTER TABLE "Link" DROP CONSTRAINT "Link_createdById_fkey";
+
+-- DropForeignKey
+ALTER TABLE "RssSubscription" DROP CONSTRAINT "RssSubscription_collectionId_fkey";
+
+-- DropForeignKey
+ALTER TABLE "Subscription" DROP CONSTRAINT "Subscription_userId_fkey";
+
+-- DropForeignKey
+ALTER TABLE "Tag" DROP CONSTRAINT "Tag_ownerId_fkey";
+
+-- DropForeignKey
+ALTER TABLE "UsersAndCollections" DROP CONSTRAINT "UsersAndCollections_collectionId_fkey";
+
+-- DropForeignKey
+ALTER TABLE "UsersAndCollections" DROP CONSTRAINT "UsersAndCollections_userId_fkey";
+
+-- AddForeignKey
+ALTER TABLE "Collection" ADD CONSTRAINT "Collection_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "Collection"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "UsersAndCollections" ADD CONSTRAINT "UsersAndCollections_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "UsersAndCollections" ADD CONSTRAINT "UsersAndCollections_collectionId_fkey" FOREIGN KEY ("collectionId") REFERENCES "Collection"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Link" ADD CONSTRAINT "Link_createdById_fkey" FOREIGN KEY ("createdById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Link" ADD CONSTRAINT "Link_collectionId_fkey" FOREIGN KEY ("collectionId") REFERENCES "Collection"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Tag" ADD CONSTRAINT "Tag_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Subscription" ADD CONSTRAINT "Subscription_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "AccessToken" ADD CONSTRAINT "AccessToken_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "RssSubscription" ADD CONSTRAINT "RssSubscription_collectionId_fkey" FOREIGN KEY ("collectionId") REFERENCES "Collection"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Highlight" ADD CONSTRAINT "Highlight_linkId_fkey" FOREIGN KEY ("linkId") REFERENCES "Link"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Highlight" ADD CONSTRAINT "Highlight_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
diff --git a/prisma/migrations/20250318130241_add_referential_action_to_field/migration.sql b/prisma/migrations/20250318130241_add_referential_action_to_field/migration.sql
new file mode 100644
index 00000000..ebf68179
--- /dev/null
+++ b/prisma/migrations/20250318130241_add_referential_action_to_field/migration.sql
@@ -0,0 +1,5 @@
+-- DropForeignKey
+ALTER TABLE "WhitelistedUser" DROP CONSTRAINT "WhitelistedUser_userId_fkey";
+
+-- AddForeignKey
+ALTER TABLE "WhitelistedUser" ADD CONSTRAINT "WhitelistedUser_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
diff --git a/prisma/migrations/20250318131012_add_referential_action_to_field/migration.sql b/prisma/migrations/20250318131012_add_referential_action_to_field/migration.sql
new file mode 100644
index 00000000..f5b5698c
--- /dev/null
+++ b/prisma/migrations/20250318131012_add_referential_action_to_field/migration.sql
@@ -0,0 +1,5 @@
+-- DropForeignKey
+ALTER TABLE "Collection" DROP CONSTRAINT "Collection_ownerId_fkey";
+
+-- AddForeignKey
+ALTER TABLE "Collection" ADD CONSTRAINT "Collection_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
diff --git a/prisma/migrations/20250318131228_rename_link_to_url_in_link_type/migration.sql b/prisma/migrations/20250318131228_rename_link_to_url_in_link_type/migration.sql
new file mode 100644
index 00000000..4235ecdd
--- /dev/null
+++ b/prisma/migrations/20250318131228_rename_link_to_url_in_link_type/migration.sql
@@ -0,0 +1 @@
+UPDATE "Link" SET "type" = 'url' WHERE "type" = 'link';
\ No newline at end of file
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 7e86e8ae..b7517e1e 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -86,7 +86,7 @@ enum LinksRouteTo {
model WhitelistedUser {
id Int @id @default(autoincrement())
username String @default("")
- User User? @relation(fields: [userId], references: [id])
+ User User? @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@ -118,10 +118,10 @@ model Collection {
iconWeight String?
color String @default("#0ea5e9")
parentId Int?
- parent Collection? @relation("SubCollections", fields: [parentId], references: [id])
+ parent Collection? @relation("SubCollections", fields: [parentId], references: [id], onDelete: Cascade)
subCollections Collection[] @relation("SubCollections")
isPublic Boolean @default(false)
- owner User @relation(fields: [ownerId], references: [id])
+ owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
ownerId Int
members UsersAndCollections[]
createdBy User? @relation("CreatedCollections", fields: [createdById], references: [id])
@@ -135,9 +135,9 @@ model Collection {
}
model UsersAndCollections {
- user User @relation(fields: [userId], references: [id])
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int
- collection Collection @relation(fields: [collectionId], references: [id])
+ collection Collection @relation(fields: [collectionId], references: [id], onDelete: Cascade)
collectionId Int
canCreate Boolean
canUpdate Boolean
@@ -154,11 +154,11 @@ model Link {
name String @default("")
type String @default("url")
description String @default("")
- highlight Highlight[]
+ highlight Highlight[]
pinnedBy User[] @relation("PinnedLinks")
- createdBy User? @relation("CreatedLinks", fields: [createdById], references: [id])
+ createdBy User? @relation("CreatedLinks", fields: [createdById], references: [id], onDelete: Cascade)
createdById Int?
- collection Collection @relation(fields: [collectionId], references: [id])
+ collection Collection @relation(fields: [collectionId], references: [id], onDelete: Cascade)
collectionId Int
tags Tag[]
icon String?
@@ -183,7 +183,7 @@ model Tag {
id Int @id @default(autoincrement())
name String
links Link[]
- owner User @relation(fields: [ownerId], references: [id])
+ owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
ownerId Int
archiveAsScreenshot Boolean?
archiveAsMonolith Boolean?
@@ -205,7 +205,7 @@ model Subscription {
currentPeriodStart DateTime
currentPeriodEnd DateTime
quantity Int @default(1)
- user User @relation(fields: [userId], references: [id])
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int @unique
childUsers User[] @relation("ChildUsers")
createdAt DateTime @default(now())
@@ -215,7 +215,7 @@ model Subscription {
model AccessToken {
id Int @id @default(autoincrement())
name String
- user User @relation(fields: [userId], references: [id])
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int
token String @unique
revoked Boolean @default(false)
@@ -231,7 +231,7 @@ model RssSubscription {
url String
name String
lastBuildDate DateTime?
- collection Collection @relation(fields: [collectionId], references: [id])
+ collection Collection @relation(fields: [collectionId], references: [id], onDelete: Cascade)
collectionId Int
ownerId Int
createdAt DateTime @default(now())
@@ -242,9 +242,9 @@ model Highlight {
id Int @id @default(autoincrement())
color String
comment String?
- link Link @relation(fields: [linkId], references: [id])
+ link Link @relation(fields: [linkId], references: [id], onDelete: Cascade)
linkId Int
- user User @relation(fields: [userId], references: [id])
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int
startOffset Int
endOffset Int