From eb4fca62edf5a8ac769c5214df7e86983d251d74 Mon Sep 17 00:00:00 2001 From: sebastjanartic <45803536-sebastjanartic@users.noreply.replit.com> Date: Sat, 28 Feb 2026 20:08:20 +0000 Subject: [PATCH] Ensure all articles are consistently added to the database upon deployment Update the seeding logic to prevent duplicate entries and add missing articles based on slug, ensuring all content, including new articles, is present after deployment. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 413891e8-d784-4bea-b9f5-91a5a68316b4 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 78e398a1-256d-4d38-a394-be3230ab70e9 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/f209e72a-0939-48fa-84fc-57854de71967/413891e8-d784-4bea-b9f5-91a5a68316b4/oYq1Msd Replit-Helium-Checkpoint-Created: true --- server/seed.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) 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}` + ); + } + } }