Skip to content

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

merged the two migration scripts for v2.6.1

daniel31x138e6f88d29fb4
diff --git a/scripts/migration/descriptionToName.js b/scripts/migration/descriptionToName.js
deleted file mode 100644
index 435e59ff..00000000
--- a/scripts/migration/descriptionToName.js
+++ /dev/null
@@ -1,70 +0,0 @@
-// [Optional, but recommended]
-
-// We decided that the "name" field should be the auto-generated field instead of the "description" field, so we need to
-// move the data from the "description" field to the "name" field for links that have an empty name.
-
-// This script is meant to be run only once.
-
-// Run the script with `node scripts/migration/descriptionToName.js`
-
-const { PrismaClient } = require("@prisma/client");
-
-const prisma = new PrismaClient();
-
-async function main() {
- console.log("Starting...");
-
- const count = await prisma.link.count({
- where: {
- name: "",
- description: {
- not: "",
- },
- },
- });
-
- console.log(
- `Applying the changes to ${count} ${
- count == 1 ? "link" : "links"
- } in 10 seconds...`
- );
-
- await new Promise((resolve) => setTimeout(resolve, 10000));
-
- console.log("Applying the changes...");
-
- const links = await prisma.link.findMany({
- where: {
- name: "",
- description: {
- not: "",
- },
- },
- select: {
- id: true,
- description: true,
- },
- });
-
- for (const link of links) {
- await prisma.link.update({
- where: {
- id: link.id,
- },
- data: {
- name: link.description,
- description: "",
- },
- });
- }
-
- console.log("Done!");
-}
-
-main()
- .catch((e) => {
- throw e;
- })
- .finally(async () => {
- await prisma.$disconnect();
- });
diff --git a/scripts/migration/pdfScreenshotIndexing.js b/scripts/migration/v2.6.1/index.js
similarity index 68%
rename from scripts/migration/pdfScreenshotIndexing.js
rename to scripts/migration/v2.6.1/index.js
index 422085b3..0c537e0c 100644
--- a/scripts/migration/pdfScreenshotIndexing.js
+++ b/scripts/migration/v2.6.1/index.js
@@ -1,4 +1,12 @@
-// This is a script that looks for every link and checks if the pdf/screenshot exist in the filesystem.
+// Run the script with `node scripts/migration/v2.6.1/index.js`
+// Docker users can run the script with `docker exec -it CONTAINER_ID /bin/bash -c 'node scripts/migration/v2.6.1/index.js'`
+
+// There are two parts to this script:
+
+// Firstly we decided that the "name" field should be the auto-generated field instead of the "description" field, so we need to
+// move the data from the "description" field to the "name" field for links that have an empty name.
+
+// Secondly it looks for every link and checks if the pdf/screenshot exist in the filesystem.
// If they do, it updates the link with the path in the db.
// If they don't, it passes.
@@ -64,7 +72,34 @@ async function checkFileExistence(path) {
}
}
-async function pdfScreenshotIndexing() {
+async function main() {
+ console.log("Starting... Please do not interrupt the process.");
+
+ const linksWithoutName = await prisma.link.findMany({
+ where: {
+ name: "",
+ description: {
+ not: "",
+ },
+ },
+ select: {
+ id: true,
+ description: true,
+ },
+ });
+
+ for (const link of linksWithoutName) {
+ await prisma.link.update({
+ where: {
+ id: link.id,
+ },
+ data: {
+ name: link.description,
+ description: "",
+ },
+ });
+ }
+
const links = await prisma.link.findMany({
select: {
id: true,
@@ -77,8 +112,6 @@ async function pdfScreenshotIndexing() {
orderBy: { id: "asc" },
});
- let counter = 0;
-
// PDFs
for (let link of links) {
const path = `archives/${link.collectionId}/${link.id}.pdf`;
@@ -92,13 +125,9 @@ async function pdfScreenshotIndexing() {
});
}
- console.log("count:", counter, "id:", link.id, "PDF");
-
- counter++;
+ console.log("Indexing the PDF for link:", link.id);
}
- counter = 0;
-
// Screenshots (PNGs)
for (let link of links) {
const path = `archives/${link.collectionId}/${link.id}.png`;
@@ -112,13 +141,9 @@ async function pdfScreenshotIndexing() {
});
}
- console.log("count:", counter, "id:", link.id, "PNG");
-
- counter++;
+ console.log("Indexing the PNG for link:", link.id);
}
- counter = 0;
-
// Screenshots (JPEGs)
for (let link of links) {
const path = `archives/${link.collectionId}/${link.id}.jpeg`;
@@ -132,15 +157,13 @@ async function pdfScreenshotIndexing() {
});
}
- console.log("count:", counter, "id:", link.id, "JPEG");
-
- counter++;
+ console.log("Indexing the JPEG for link:", link.id);
}
await prisma.$disconnect();
}
-pdfScreenshotIndexing().catch((e) => {
+main().catch((e) => {
console.error(e);
process.exit(1);
});