|
|
@ -13,14 +13,16 @@ const saveExcelDataFile = require('./tasks/writeExcelSheet')
|
|
|
|
|
|
|
|
|
|
|
|
async function doMigration() {
|
|
|
|
async function doMigration() {
|
|
|
|
const items = await oldDB.sock.find().lean().exec()
|
|
|
|
const items = await oldDB.sock.find().lean().exec()
|
|
|
|
const users = await oldDB.user.find().populate('purchases').lean().exec()
|
|
|
|
const allUsers = await oldDB.user.find().populate('purchases').lean().exec()
|
|
|
|
const carts = users.map(u => u.purchases).flat()
|
|
|
|
const carts = allUsers.map(u => u.purchases).flat()
|
|
|
|
const coupons = await oldDB.coupon.find().lean().exec()
|
|
|
|
const coupons = await oldDB.coupon.find().lean().exec()
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`Loaded ${carts.length} purchases from ${users.length} users`)
|
|
|
|
const registeredUsers = allUsers.filter(user => user.email)
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`Inserting ${users.length} users into the database`)
|
|
|
|
console.log(`Loaded ${carts.length} purchases and ${registeredUsers.length} users`)
|
|
|
|
const importAdmin = await createUsers(newDB, users);
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`Inserting ${registeredUsers.length} users into the database`)
|
|
|
|
|
|
|
|
const importAdmin = await createUsers(newDB, registeredUsers);
|
|
|
|
console.log(` Found user account ${importAdmin.uuid} (${importAdmin.email}) to attribute file uploads to`)
|
|
|
|
console.log(` Found user account ${importAdmin.uuid} (${importAdmin.email}) to attribute file uploads to`)
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`\nInserting ${items.length} items into database`)
|
|
|
|
console.log(`\nInserting ${items.length} items into database`)
|
|
|
@ -31,7 +33,7 @@ async function doMigration() {
|
|
|
|
await uploadImages(newDB, itemImages, importAdmin.uuid)
|
|
|
|
await uploadImages(newDB, itemImages, importAdmin.uuid)
|
|
|
|
|
|
|
|
|
|
|
|
console.log('\nWriting Excel data file')
|
|
|
|
console.log('\nWriting Excel data file')
|
|
|
|
await saveExcelDataFile(users, coupons, items, path.join(__dirname, './datafile.xlsx'))
|
|
|
|
await saveExcelDataFile(allUsers, coupons, items, path.join(__dirname, './datafile.xlsx'))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
doMigration()
|
|
|
|
doMigration()
|
|
|
|