Skip to content

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

created migration script [WIP]

daniel31x13966136dab6a1
diff --git a/lib/api/controllers/users/userId/deleteUserById.ts b/lib/api/controllers/users/userId/deleteUserById.ts
index 731e877f..06415257 100644
--- a/lib/api/controllers/users/userId/deleteUserById.ts
+++ b/lib/api/controllers/users/userId/deleteUserById.ts
@@ -59,7 +59,7 @@ export default async function deleteUserById(
where: { collectionId: collection.id },
});
- // Delete archive folders associated with collections
+ // Delete archive folders
removeFolder({ filePath: `archives/${collection.id}` });
}
diff --git a/lib/api/migration/migrateToV2.js b/lib/api/migration/migrateToV2.js
new file mode 100644
index 00000000..aeb07fbe
--- /dev/null
+++ b/lib/api/migration/migrateToV2.js
@@ -0,0 +1,83 @@
+const { PrismaClient } = require("@prisma/client");
+const axios = require("axios");
+const { existsSync } = require("fs");
+
+const prisma = new PrismaClient();
+
+const STORAGE_FOLDER = process.env.STORAGE_FOLDER || "data";
+
+async function checkFileExistence(path) {
+ try {
+ if (existsSync(path)) {
+ return true;
+ } else return false;
+ } catch (err) {
+ console.log(err);
+ }
+}
+
+// Avatars
+async function migrateAvatars() {
+ const users = await prisma.user.findMany();
+
+ for (let user of users) {
+ const path = STORAGE_FOLDER + `/uploads/avatar/${user.id}.jpg`;
+
+ const res = await checkFileExistence(path);
+
+ if (res) {
+ // await prisma.user.update({
+ // where: { id: user.id },
+ // data: { image: "avatar/" + user.id },
+ // });
+ console.log(`Updated avatar for user ${user.id}`);
+ } else {
+ console.log(`No avatar found for user ${user.id}`);
+ }
+ }
+
+ const links = await prisma.link.findMany();
+
+ // Screenshots
+ for (let link of links) {
+ const path =
+ STORAGE_FOLDER + `/archives/${link.collectionId}/${link.id}.pdf`;
+
+ const res = await checkFileExistence(path);
+
+ if (res) {
+ // await prisma.user.update({
+ // where: { id: user.id },
+ // data: { image: "avatar/" + user.id },
+ // });
+ console.log(`Updated capture for link ${link.id}`);
+ } else {
+ console.log(`No capture found for link ${link.id}`);
+ }
+ }
+
+ // PDFs
+ for (let link of links) {
+ const path =
+ STORAGE_FOLDER + `/archives/${link.collectionId}/${link.id}.png`;
+
+ const res = await checkFileExistence(path);
+
+ if (res) {
+ // await prisma.user.update({
+ // where: { id: user.id },
+ // data: { image: "avatar/" + user.id },
+ // });
+ console.log(`Updated capture for link ${link.id}`);
+ } else {
+ console.log(`No capture found for link ${link.id}`);
+ }
+ }
+
+ await prisma.$disconnect();
+}
+
+migrateAvatars().catch((e) => {
+ console.error(e);
+ process.exit(1);
+});
diff --git a/prisma/migrations/20231025123038_added_pathname_to_files/migration.sql b/prisma/migrations/20231025123038_added_pathname_to_files/migration.sql
new file mode 100644
index 00000000..65fa41ae
--- /dev/null
+++ b/prisma/migrations/20231025123038_added_pathname_to_files/migration.sql
@@ -0,0 +1,13 @@
+/*
+ Warnings:
+
+ - You are about to drop the column `image` on the `User` table. All the data in the column will be lost.
+
+*/
+-- AlterTable
+ALTER TABLE "Link" ADD COLUMN "pdfPath" TEXT,
+ADD COLUMN "screenshotPath" TEXT;
+
+-- AlterTable
+ALTER TABLE "User" DROP COLUMN "image",
+ADD COLUMN "imagePath" TEXT;
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index ab67eb6f..e417a4fe 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -42,7 +42,7 @@ model User {
email String? @unique
emailVerified DateTime?
- image String?
+ imagePath String?
accounts Account[]
sessions Session[]
@@ -122,6 +122,9 @@ model Link {
collectionId Int
tags Tag[]
+ screenshotPath String?
+ pdfPath String?
+
createdAt DateTime @default(now())
}