Remove all placeholder articles automatically upon deployment
Add logic to the seed function that deletes articles not present in the seed list, ensuring only valid content remains after deployment. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 517dfa7b-26ac-463d-a6e1-a58c6df97188 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 791bdff6-f95e-4e8f-836a-f941239effa9 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/f209e72a-0939-48fa-84fc-57854de71967/517dfa7b-26ac-463d-a6e1-a58c6df97188/V5dWXpq Replit-Helium-Checkpoint-Created: true
This commit is contained in:
parent
949b4ed70b
commit
373ffbff5f
@ -193,9 +193,18 @@ const seedArticles = [
|
||||
];
|
||||
|
||||
export async function seedDatabase() {
|
||||
const validSlugs = new Set(seedArticles.map((a) => a.slug));
|
||||
const existing = await storage.getArticles();
|
||||
const existingSlugs = new Set(existing.map((a) => a.slug));
|
||||
|
||||
const toDelete = existing.filter((a) => !validSlugs.has(a.slug));
|
||||
if (toDelete.length > 0) {
|
||||
for (const article of toDelete) {
|
||||
await db.execute(sql`DELETE FROM articles WHERE id = ${article.id}`);
|
||||
}
|
||||
console.log("Cleanup: removed " + toDelete.length + " articles not in seed list.");
|
||||
}
|
||||
|
||||
let added = 0;
|
||||
for (const article of seedArticles) {
|
||||
if (existingSlugs.has(article.slug)) continue;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user