-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate-blogs.ts
More file actions
49 lines (45 loc) · 1.4 KB
/
Copy pathmigrate-blogs.ts
File metadata and controls
49 lines (45 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { db } from "../src/lib/db";
import { blogPosts } from "../src/lib/db/schema";
import { BLOG_POSTS } from "../src/lib/blog-catalog";
async function main() {
console.log("Seeding blog posts...");
for (const post of BLOG_POSTS) {
try {
await db.insert(blogPosts).values({
slug: post.slug,
title: post.title,
description: post.description,
primaryKeyword: post.primaryKeyword,
keywords: post.keywords,
publishedAt: new Date(post.publishedAt),
updatedAt: new Date(post.updatedAt),
readingMinutes: post.readingMinutes,
author: post.author,
hero: post.hero,
sections: post.sections,
faqs: post.faqs,
}).onConflictDoUpdate({
target: blogPosts.slug,
set: {
title: post.title,
description: post.description,
primaryKeyword: post.primaryKeyword,
keywords: post.keywords,
publishedAt: new Date(post.publishedAt),
updatedAt: new Date(post.updatedAt),
readingMinutes: post.readingMinutes,
author: post.author,
hero: post.hero,
sections: post.sections,
faqs: post.faqs,
}
});
console.log(`- Seeded: ${post.slug}`);
} catch (error) {
console.error(`- Error seeding ${post.slug}:`, error);
}
}
console.log("Seeding complete!");
process.exit(0);
}
main();