mirror of
https://github.com/EvolutionAPI/evolution-manager.git
synced 2025-12-22 12:32:18 -06:00
Fix migration error handling and add data validation
This commit is contained in:
@@ -16,14 +16,19 @@ module.exports = async (instanceName, options, progressBars, conn) => {
|
||||
const progress = progressBars.create(files.length, 0)
|
||||
progress.update({ process: 'Chats' })
|
||||
for (const file of files) {
|
||||
const collectionName = file.key
|
||||
const collection = conn.collection(collectionName)
|
||||
try {
|
||||
const collectionName = file.key
|
||||
const collection = conn.collection(collectionName)
|
||||
|
||||
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
||||
data._id = file.path.split('\\').pop().split('.')[0]
|
||||
await collection.findOneAndUpdate({ _id: data._id }, { $set: data }, { upsert: true })
|
||||
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
||||
data._id = file.path.split('\\').pop().split('.')[0]
|
||||
await collection.findOneAndUpdate({ _id: data._id }, { $set: data }, { upsert: true })
|
||||
|
||||
progress.increment()
|
||||
progress.increment()
|
||||
} catch (err) {
|
||||
progress.stop()
|
||||
throw { err, file }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,19 @@ module.exports = async (instanceName, options, progressBars, conn) => {
|
||||
const progress = progressBars.create(files.length, 0)
|
||||
progress.update({ process: 'Contacts' })
|
||||
for (const file of files) {
|
||||
const collectionName = file.key
|
||||
const collection = conn.collection(collectionName)
|
||||
try {
|
||||
const collectionName = file.key
|
||||
const collection = conn.collection(collectionName)
|
||||
|
||||
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
||||
data._id = file.path.split('\\').pop().split('.')[0]
|
||||
await collection.findOneAndUpdate({ _id: data._id }, { $set: data }, { upsert: true })
|
||||
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
||||
data._id = file.path.split('\\').pop().split('.')[0]
|
||||
await collection.findOneAndUpdate({ _id: data._id }, { $set: data }, { upsert: true })
|
||||
|
||||
progress.increment()
|
||||
progress.increment()
|
||||
} catch (err) {
|
||||
progress.stop()
|
||||
throw { err, file }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,13 +30,18 @@ module.exports = async (instanceName, options, progressBars, conn, connInstance)
|
||||
const progress = progressBars.create(files.length, 0)
|
||||
progress.update({ process: 'Instance' })
|
||||
for (const file of files) {
|
||||
const collectionName = file.key || instanceName
|
||||
const collection = (!file.secondaryConnection ? conn : connInstance).collection(collectionName)
|
||||
try {
|
||||
const collectionName = file.key || instanceName
|
||||
const collection = (!file.secondaryConnection ? conn : connInstance).collection(collectionName)
|
||||
|
||||
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
||||
data._id = file.path.split('\\').pop().split('.')[0]
|
||||
await collection.findOneAndUpdate({ _id: data._id }, { $set: data }, { upsert: true })
|
||||
progress.increment()
|
||||
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
||||
data._id = file.path.split('\\').pop().split('.')[0]
|
||||
await collection.findOneAndUpdate({ _id: data._id }, { $set: data }, { upsert: true })
|
||||
progress.increment()
|
||||
} catch (err) {
|
||||
progress.stop()
|
||||
throw { err, file }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,19 @@ module.exports = async (instanceName, options, progressBars, conn) => {
|
||||
const progress = progressBars.create(files.length, 0)
|
||||
progress.update({ process: 'Message Update' })
|
||||
for (const file of files) {
|
||||
const collectionName = file.key
|
||||
const collection = conn.collection(collectionName)
|
||||
try {
|
||||
const collectionName = file.key
|
||||
const collection = conn.collection(collectionName)
|
||||
|
||||
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
||||
data._id = file.path.split('\\').pop().split('.')[0]
|
||||
await collection.findOneAndUpdate({ _id: data._id }, { $set: data }, { upsert: true })
|
||||
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
||||
data._id = file.path.split('\\').pop().split('.')[0]
|
||||
await collection.findOneAndUpdate({ _id: data._id }, { $set: data }, { upsert: true })
|
||||
|
||||
progress.increment()
|
||||
progress.increment()
|
||||
} catch (err) {
|
||||
progress.stop()
|
||||
throw { err, file }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,19 @@ module.exports = async (instanceName, options, progressBars, conn) => {
|
||||
const progress = progressBars.create(files.length, 0)
|
||||
progress.update({ process: 'Messages' })
|
||||
for (const file of files) {
|
||||
const collectionName = file.key
|
||||
const collection = conn.collection(collectionName)
|
||||
try {
|
||||
const collectionName = file.key
|
||||
const collection = conn.collection(collectionName)
|
||||
|
||||
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
||||
data._id = file.path.split('\\').pop().split('.')[0]
|
||||
await collection.findOneAndUpdate({ _id: data._id }, { $set: data }, { upsert: true })
|
||||
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
||||
data._id = file.path.split('\\').pop().split('.')[0]
|
||||
await collection.findOneAndUpdate({ _id: data._id }, { $set: data }, { upsert: true })
|
||||
|
||||
progress.increment()
|
||||
progress.increment()
|
||||
} catch (err) {
|
||||
progress.stop()
|
||||
throw { err, file }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user