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
This commit is contained in:
parent
32b6e79e26
commit
eb4fca62ed
@ -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}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user