/** * Fix Blog Published Dates * Replace empty {} objects with proper ISO date strings */ const { MongoClient } = require('mongodb'); const DEV_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017'; const DEV_DB = process.env.MONGODB_DB || 'tractatus_dev'; // Date assignments based on blog content context const DATE_FIXES = [ { slug: 'scaling-tractatus-roadmap', date: new Date('2025-10-15T10:00:00Z'), // Mid-October (roadmap blog) title: 'How to Scale Tractatus: Breaking the Chicken-and-Egg Problem' }, { slug: 'introducing-tractatus-framework', date: new Date('2025-10-05T09:00:00Z'), // Early October (inaugural post) title: 'Introducing the Tractatus Framework' }, { slug: 'why-ai-safety-requires-architectural-boundaries-not-just-training', date: new Date('2025-10-22T20:00:00Z'), // Just fixed and deployed today title: 'Why AI Safety Requires Architectural Boundaries' } ]; async function fixDates() { const client = new MongoClient(DEV_URI); try { console.log('šŸ“… Fixing Blog Published Dates\n'); console.log('═'.repeat(70)); await client.connect(); const db = client.db(DEV_DB); const collection = db.collection('blog_posts'); let fixedCount = 0; for (const fix of DATE_FIXES) { console.log(`\nšŸ“„ ${fix.title}`); console.log(` Slug: ${fix.slug}`); const blog = await collection.findOne({ slug: fix.slug }); if (!blog) { console.log(` āŒ Blog not found`); continue; } // Check if published_at is empty object or invalid const currentDate = blog.published_at; const needsFix = !currentDate || (typeof currentDate === 'object' && Object.keys(currentDate).length === 0) || currentDate.toString() === '[object Object]'; if (needsFix) { const result = await collection.updateOne( { slug: fix.slug }, { $set: { published_at: fix.date, 'moderation.approved_at': fix.date // Also update approval date for consistency } } ); if (result.modifiedCount === 1) { console.log(` āœ… Fixed: ${fix.date.toISOString()}`); fixedCount++; } else { console.log(` āŒ Update failed`); } } else { console.log(` āš ļø Already has valid date: ${currentDate}`); } } console.log('\n' + '═'.repeat(70)); console.log(`\n✨ Complete: ${fixedCount}/${DATE_FIXES.length} dates fixed\n`); return fixedCount > 0; } catch (error) { console.error('āŒ Error:', error.message); throw error; } finally { await client.close(); } } // Run if called directly if (require.main === module) { fixDates() .then((success) => { process.exit(success ? 0 : 1); }) .catch(error => { console.error('\nšŸ’„ Failed:', error); process.exit(1); }); } module.exports = { fixDates, DATE_FIXES };