Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Update sync-link-tags.ts

Steven Tey56fb0eeec4eb
diff --git a/apps/web/scripts/sync-link-tags.ts b/apps/web/scripts/sync-link-tags.ts
index 1fc5fd0e44..dff21450b7 100644
--- a/apps/web/scripts/sync-link-tags.ts
+++ b/apps/web/scripts/sync-link-tags.ts
@@ -17,13 +17,26 @@ async function main() {
},
});
+ // make sure all tagId exist
+ const tagIds = links.map(({ tagId }) => tagId!);
+ const tags = await prisma.tag.findMany({
+ where: {
+ id: {
+ in: tagIds,
+ },
+ },
+ });
+
console.log(`Updating ${links.length} links...`);
const response = await prisma.linkTag.createMany({
- data: links.map((link) => ({
- linkId: link.id,
- tagId: link.tagId!, // cause we filtered out links without tagId
- })),
+ data: links
+ // filter out links with tagIds that don't exist
+ .filter(({ tagId }) => tags.find((tag) => tag.id === tagId) !== undefined)
+ .map((link) => ({
+ linkId: link.id,
+ tagId: link.tagId!, // cause we filtered out links without tagId
+ })),
});
console.log(`Created ${response.count} LinkTag records`);