mirror of
https://github.com/EvolutionAPI/evolution-manager.git
synced 2025-07-13 15:14:49 -06:00
Fix migration error handling and add data validation
This commit is contained in:
parent
c6b743a9b8
commit
2d54cec268
@ -83,9 +83,17 @@ module.exports = async () => {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
// get folders from /instances
|
|
||||||
const answers = await inquirer.prompt(questions);
|
const answers = await inquirer.prompt(questions);
|
||||||
|
|
||||||
|
// check if there is any data to migrate
|
||||||
|
if (answers.saveData.length === 0) {
|
||||||
|
console.log('🌱 No data selected to migrate!\n\n');
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
if (answers.selectedInstances.length === 0) {
|
||||||
|
console.log('🌱 No instances selected to migrate!\n\n');
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
// connect to mongodb
|
// connect to mongodb
|
||||||
console.log('\n\n🌱 Connecting to MongoDB...');
|
console.log('\n\n🌱 Connecting to MongoDB...');
|
||||||
@ -102,27 +110,35 @@ module.exports = async () => {
|
|||||||
}, cliProgress.Presets.shades_classic);
|
}, cliProgress.Presets.shades_classic);
|
||||||
|
|
||||||
instancesBar.start(answers.selectedInstances.length, 0);
|
instancesBar.start(answers.selectedInstances.length, 0);
|
||||||
for (const instanceName of answers.selectedInstances) {
|
try {
|
||||||
instancesBar.update({ instanceName });
|
for (const instanceName of answers.selectedInstances) {
|
||||||
|
instancesBar.update({ instanceName });
|
||||||
|
|
||||||
const instanceBars = new cliProgress.MultiBar({
|
const instanceBars = new cliProgress.MultiBar({
|
||||||
format: '|' + colors.cyan('{bar}') + '| ' + colors.blue('{process}') + ' | {percentage}% || {value}/{total} Files',
|
format: '|' + colors.cyan('{bar}') + '| ' + colors.blue('{process}') + ' | {percentage}% || {value}/{total} Files',
|
||||||
clearOnComplete: true,
|
clearOnComplete: true,
|
||||||
}, cliProgress.Presets.shades_classic);
|
}, cliProgress.Presets.shades_classic);
|
||||||
|
|
||||||
for (const migration of answers.saveData) {
|
for (const migration of answers.saveData) {
|
||||||
await migratorsFunctions[migration](instanceName, answers, instanceBars, conn, connInstance);
|
await migratorsFunctions[migration](instanceName, answers, instanceBars, conn, connInstance);
|
||||||
|
}
|
||||||
|
|
||||||
|
instanceBars.stop();
|
||||||
|
instancesBar.increment();
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
instanceBars.stop();
|
instancesBar.stop();
|
||||||
instancesBar.increment();
|
console.log(err.file);
|
||||||
|
console.log(err.err);
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
instancesBar.stop();
|
|
||||||
|
|
||||||
|
instancesBar.stop();
|
||||||
|
|
||||||
// disconnect from mongodb
|
// disconnect from mongodb
|
||||||
console.log('\n\n🌱 Disconnecting from MongoDB...');
|
console.log('\n\n🌱 Disconnecting from MongoDB...');
|
||||||
await conn.close();
|
await conn.close();
|
||||||
|
if (connInstance) await connInstance.close();
|
||||||
console.log('🌱 Disconnected from MongoDB!\n\n');
|
console.log('🌱 Disconnected from MongoDB!\n\n');
|
||||||
|
|
||||||
console.log('🌱 Migration completed!\n\n');
|
console.log('🌱 Migration completed!\n\n');
|
||||||
|
@ -16,14 +16,19 @@ module.exports = async (instanceName, options, progressBars, conn) => {
|
|||||||
const progress = progressBars.create(files.length, 0)
|
const progress = progressBars.create(files.length, 0)
|
||||||
progress.update({ process: 'Chats' })
|
progress.update({ process: 'Chats' })
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const collectionName = file.key
|
try {
|
||||||
const collection = conn.collection(collectionName)
|
const collectionName = file.key
|
||||||
|
const collection = conn.collection(collectionName)
|
||||||
|
|
||||||
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
||||||
data._id = file.path.split('\\').pop().split('.')[0]
|
data._id = file.path.split('\\').pop().split('.')[0]
|
||||||
await collection.findOneAndUpdate({ _id: data._id }, { $set: data }, { upsert: true })
|
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)
|
const progress = progressBars.create(files.length, 0)
|
||||||
progress.update({ process: 'Contacts' })
|
progress.update({ process: 'Contacts' })
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const collectionName = file.key
|
try {
|
||||||
const collection = conn.collection(collectionName)
|
const collectionName = file.key
|
||||||
|
const collection = conn.collection(collectionName)
|
||||||
|
|
||||||
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
||||||
data._id = file.path.split('\\').pop().split('.')[0]
|
data._id = file.path.split('\\').pop().split('.')[0]
|
||||||
await collection.findOneAndUpdate({ _id: data._id }, { $set: data }, { upsert: true })
|
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)
|
const progress = progressBars.create(files.length, 0)
|
||||||
progress.update({ process: 'Instance' })
|
progress.update({ process: 'Instance' })
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const collectionName = file.key || instanceName
|
try {
|
||||||
const collection = (!file.secondaryConnection ? conn : connInstance).collection(collectionName)
|
const collectionName = file.key || instanceName
|
||||||
|
const collection = (!file.secondaryConnection ? conn : connInstance).collection(collectionName)
|
||||||
|
|
||||||
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
||||||
data._id = file.path.split('\\').pop().split('.')[0]
|
data._id = file.path.split('\\').pop().split('.')[0]
|
||||||
await collection.findOneAndUpdate({ _id: data._id }, { $set: data }, { upsert: true })
|
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)
|
const progress = progressBars.create(files.length, 0)
|
||||||
progress.update({ process: 'Message Update' })
|
progress.update({ process: 'Message Update' })
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const collectionName = file.key
|
try {
|
||||||
const collection = conn.collection(collectionName)
|
const collectionName = file.key
|
||||||
|
const collection = conn.collection(collectionName)
|
||||||
|
|
||||||
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
||||||
data._id = file.path.split('\\').pop().split('.')[0]
|
data._id = file.path.split('\\').pop().split('.')[0]
|
||||||
await collection.findOneAndUpdate({ _id: data._id }, { $set: data }, { upsert: true })
|
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)
|
const progress = progressBars.create(files.length, 0)
|
||||||
progress.update({ process: 'Messages' })
|
progress.update({ process: 'Messages' })
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const collectionName = file.key
|
try {
|
||||||
const collection = conn.collection(collectionName)
|
const collectionName = file.key
|
||||||
|
const collection = conn.collection(collectionName)
|
||||||
|
|
||||||
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
const data = JSON.parse(fs.readFileSync(file.path, 'utf8'))
|
||||||
data._id = file.path.split('\\').pop().split('.')[0]
|
data._id = file.path.split('\\').pop().split('.')[0]
|
||||||
await collection.findOneAndUpdate({ _id: data._id }, { $set: data }, { upsert: true })
|
await collection.findOneAndUpdate({ _id: data._id }, { $set: data }, { upsert: true })
|
||||||
|
|
||||||
progress.increment()
|
progress.increment()
|
||||||
|
} catch (err) {
|
||||||
|
progress.stop()
|
||||||
|
throw { err, file }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "evolution-manager",
|
"name": "evolution-manager",
|
||||||
"description": "Evolution Manager is an open-source interface for managing the Evolution API, simplifying the creation and administration of API instances with advanced features and diverse integrations.",
|
"description": "Evolution Manager is an open-source interface for managing the Evolution API, simplifying the creation and administration of API instances with advanced features and diverse integrations.",
|
||||||
"version": "0.4.8",
|
"version": "0.4.9",
|
||||||
"main": "dist",
|
"main": "dist",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.0.0"
|
"node": ">=16.0.0"
|
||||||
|
Loading…
Reference in New Issue
Block a user