merged the two migration scripts for v2.6.1
This commit is contained in:
parent
6983e41576
commit
8e6f88d29f
|
@ -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();
|
|
||||||
});
|
|
|
@ -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 do, it updates the link with the path in the db.
|
||||||
// If they don't, it passes.
|
// 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({
|
const links = await prisma.link.findMany({
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
@ -77,8 +112,6 @@ async function pdfScreenshotIndexing() {
|
||||||
orderBy: { id: "asc" },
|
orderBy: { id: "asc" },
|
||||||
});
|
});
|
||||||
|
|
||||||
let counter = 0;
|
|
||||||
|
|
||||||
// PDFs
|
// PDFs
|
||||||
for (let link of links) {
|
for (let link of links) {
|
||||||
const path = `archives/${link.collectionId}/${link.id}.pdf`;
|
const path = `archives/${link.collectionId}/${link.id}.pdf`;
|
||||||
|
@ -92,13 +125,9 @@ async function pdfScreenshotIndexing() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("count:", counter, "id:", link.id, "PDF");
|
console.log("Indexing the PDF for link:", link.id);
|
||||||
|
|
||||||
counter++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
counter = 0;
|
|
||||||
|
|
||||||
// Screenshots (PNGs)
|
// Screenshots (PNGs)
|
||||||
for (let link of links) {
|
for (let link of links) {
|
||||||
const path = `archives/${link.collectionId}/${link.id}.png`;
|
const path = `archives/${link.collectionId}/${link.id}.png`;
|
||||||
|
@ -112,13 +141,9 @@ async function pdfScreenshotIndexing() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("count:", counter, "id:", link.id, "PNG");
|
console.log("Indexing the PNG for link:", link.id);
|
||||||
|
|
||||||
counter++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
counter = 0;
|
|
||||||
|
|
||||||
// Screenshots (JPEGs)
|
// Screenshots (JPEGs)
|
||||||
for (let link of links) {
|
for (let link of links) {
|
||||||
const path = `archives/${link.collectionId}/${link.id}.jpeg`;
|
const path = `archives/${link.collectionId}/${link.id}.jpeg`;
|
||||||
|
@ -132,15 +157,13 @@ async function pdfScreenshotIndexing() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("count:", counter, "id:", link.id, "JPEG");
|
console.log("Indexing the JPEG for link:", link.id);
|
||||||
|
|
||||||
counter++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await prisma.$disconnect();
|
await prisma.$disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
pdfScreenshotIndexing().catch((e) => {
|
main().catch((e) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
Ŝarĝante…
Reference in New Issue