Monorepo for Aesthetic.Computer aesthetic.computer
at main 48 lines 1.3 kB view raw
1#!/usr/bin/env node 2// regenerate-codes.mjs 3// Regenerate all painting codes with new algorithm 4 5import 'dotenv/config'; 6import { generateCode } from './generate-code.mjs'; 7import { MongoClient } from 'mongodb'; 8 9const client = new MongoClient(process.env.MONGODB_CONNECTION_STRING); 10await client.connect(); 11const db = client.db(process.env.MONGODB_NAME); 12const paintings = db.collection('paintings'); 13 14console.log('🔄 Regenerating all painting codes...\n'); 15 16const total = await paintings.countDocuments(); 17console.log(`📊 Found ${total} paintings to regenerate\n`); 18 19const existingCodes = new Set(); 20let updated = 0; 21 22const allPaintings = await paintings.find({}).toArray(); 23 24for (const painting of allPaintings) { 25 const newCode = generateCode(existingCodes); 26 27 await paintings.updateOne( 28 { _id: painting._id }, 29 { $set: { code: newCode } } 30 ); 31 32 updated++; 33 if (updated % 500 === 0) { 34 console.log(` ... ${updated}/${total} codes regenerated`); 35 } 36} 37 38console.log(`\n✅ Regenerated ${updated} codes\n`); 39 40// Show samples 41console.log('📝 Sample new codes:\n'); 42const samples = await paintings.find({}).limit(20).toArray(); 43samples.forEach(p => { 44 const user = p.user ? 'user' : 'guest'; 45 console.log(` #${p.code.padEnd(4)} | ${user}`); 46}); 47 48await client.close();