names should be auto generated instead of descriptions + add default value to name field
This commit is contained in:
parent
cb50de96a3
commit
bcb6aea119
|
@ -155,7 +155,7 @@ export default function NewLinkModal({ onClose }: Props) {
|
||||||
<TextInput
|
<TextInput
|
||||||
value={link.name}
|
value={link.name}
|
||||||
onChange={(e) => setLink({ ...link, name: e.target.value })}
|
onChange={(e) => setLink({ ...link, name: e.target.value })}
|
||||||
placeholder="e.g. Example Link"
|
placeholder="Will be auto generated if left empty."
|
||||||
className="bg-base-200"
|
className="bg-base-200"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -177,7 +177,7 @@ export default function NewLinkModal({ onClose }: Props) {
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setLink({ ...link, description: e.target.value })
|
setLink({ ...link, description: e.target.value })
|
||||||
}
|
}
|
||||||
placeholder="Will be auto generated if nothing is provided."
|
placeholder="Notes, thoughts, etc."
|
||||||
className="resize-none w-full rounded-md p-2 border-neutral-content bg-base-200 focus:border-primary border-solid border outline-none duration-100"
|
className="resize-none w-full rounded-md p-2 border-neutral-content bg-base-200 focus:border-primary border-solid border outline-none duration-100"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -160,12 +160,13 @@ export default async function postLink(
|
||||||
|
|
||||||
link.collection.name = link.collection.name.trim();
|
link.collection.name = link.collection.name.trim();
|
||||||
|
|
||||||
const description =
|
const title =
|
||||||
link.description && link.description !== ""
|
!(link.name && link.name !== "") && link.url
|
||||||
? link.description
|
|
||||||
: link.url
|
|
||||||
? await getTitle(link.url)
|
? await getTitle(link.url)
|
||||||
: undefined;
|
: "";
|
||||||
|
|
||||||
|
const name =
|
||||||
|
link.name && link.name !== "" ? link.name : link.url ? title : "";
|
||||||
|
|
||||||
const validatedUrl = link.url ? await validateUrlSize(link.url) : undefined;
|
const validatedUrl = link.url ? await validateUrlSize(link.url) : undefined;
|
||||||
|
|
||||||
|
@ -184,8 +185,8 @@ export default async function postLink(
|
||||||
const newLink = await prisma.link.create({
|
const newLink = await prisma.link.create({
|
||||||
data: {
|
data: {
|
||||||
url: link.url?.trim().replace(/\/+$/, "") || null,
|
url: link.url?.trim().replace(/\/+$/, "") || null,
|
||||||
name: link.name,
|
name,
|
||||||
description,
|
description: link.description,
|
||||||
type: linkType,
|
type: linkType,
|
||||||
collection: {
|
collection: {
|
||||||
connect: {
|
connect: {
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Link" ALTER COLUMN "name" SET DEFAULT '';
|
|
@ -123,7 +123,7 @@ model UsersAndCollections {
|
||||||
|
|
||||||
model Link {
|
model Link {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
name String
|
name String @default("")
|
||||||
type String @default("url")
|
type String @default("url")
|
||||||
description String @default("")
|
description String @default("")
|
||||||
pinnedBy User[]
|
pinnedBy User[]
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
// [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.
|
||||||
|
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Run the script with `node scripts/migration/descriptionToName.js`
|
Ŝarĝante…
Reference in New Issue