mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-12-16 06:01:56 +01:00
44 lines
840 B
JavaScript
44 lines
840 B
JavaScript
// for Node.js interpret
|
|
|
|
const { default: DriveFile } = require('../../built/api/models/drive-file')
|
|
|
|
const migrate = async (doc) => {
|
|
const result = await DriveFile.update(doc._id, {
|
|
$set: {
|
|
contentType: doc.metadata.type
|
|
},
|
|
$unset: {
|
|
'metadata.type': ''
|
|
}
|
|
})
|
|
return result.ok === 1
|
|
}
|
|
|
|
async function main() {
|
|
let i = 0;
|
|
|
|
const count = await db.get('drive_files').count({});
|
|
|
|
const iterate = async () => {
|
|
if (i == count) return true;
|
|
console.log(`${i} / ${count}`);
|
|
const doc = (await db.get('drive_files').find({}, { limit: 1, skip: i }))[0]
|
|
const res = await migrate(doc);
|
|
if (!res) {
|
|
return false;
|
|
} else {
|
|
i++
|
|
return await iterate();
|
|
}
|
|
}
|
|
|
|
const res = await iterate();
|
|
|
|
if (res) {
|
|
return 'ok';
|
|
} else {
|
|
throw 'something happened';
|
|
}
|
|
}
|
|
|
|
main().then(console.dir).catch(console.error)
|