diff --git a/server/seed.ts b/server/seed.ts index e546d77..f89b73e 100644 --- a/server/seed.ts +++ b/server/seed.ts @@ -95,9 +95,12 @@ const seedArticles = [ export async function seedDatabase() { const existing = await storage.getArticles(); - if (existing.length > 0) return; + const existingSlugs = new Set(existing.map((a) => a.slug)); + let added = 0; for (const article of seedArticles) { + if (existingSlugs.has(article.slug)) continue; + await storage.createArticle({ title: article.title, slug: article.slug, @@ -108,15 +111,24 @@ export async function seedDatabase() { author: article.author, featured: article.featured, }); - } - for (const article of seedArticles) { if (article.publishedAt) { await db.execute( sql`UPDATE articles SET published_at = ${article.publishedAt} WHERE slug = ${article.slug}` ); } + added++; } - console.log("Database seeded with " + seedArticles.length + " articles."); + if (added > 0) { + console.log("Database seeded: added " + added + " new articles."); + } + + for (const article of seedArticles) { + if (article.publishedAt && existingSlugs.has(article.slug)) { + await db.execute( + sql`UPDATE articles SET published_at = ${article.publishedAt} WHERE slug = ${article.slug}` + ); + } + } }