Files
Thomas Lynch 4b07e685b6 Improve 0.11.0 migration
add simple regex for handling ipv4/6 instead of assuming all ipv4
actually append 4/6 to existing cloaks
set type 0 on all bans/posts before applying correct types to ensure all have at least some ip type
2022-12-30 15:14:40 +11:00

102 lines
1.8 KiB
JavaScript

'use strict';
module.exports = async(db, redis) => {
console.log('changing post/report/ban ip type storage format');
await db.collection('posts').updateMany({
/* Make sure they all existing ones at least have a type
in case the site uses "dont store raw ips" */
}, {
'$set': {
'ip.type': 0,
}
});
await db.collection('posts').updateMany({
'ip.raw': /^([0-9]+(\.|$)){4}/
}, [{
'$set': {
'ip.type': 0,
'ip.cloak': {
$concat: ['$ip.cloak', '4']
}
}
}]);
await db.collection('posts').updateMany({
'ip.raw': /:/
}, [{
'$set': {
'ip.type': 1,
'ip.cloak': {
$concat: ['$ip.cloak', '6']
}
}
}]);
await db.collection('posts').updateMany({
'ip.cloak': /PRUNED$/
}, {
'$set': {
'ip.type': 3,
}
});
await db.collection('posts').updateMany({
'ip.cloak': /BP$/
}, {
'$set': {
'ip.type': 2,
}
});
await db.collection('posts').updateMany({}, {
'$set': {
reports: [],
globalreports: [],
}
});
await db.collection('bans').updateMany({
/* Make sure they all existing ones at least have a type
in case the site uses "dont store raw ips" */
}, {
'$set': {
'ip.type': 0,
}
});
await db.collection('bans').updateMany({
'ip.raw': /^([0-9]+(\.|$)){4}/
}, [{
'$set': {
'ip.type': 0,
'ip.cloak': {
$concat: ['$ip.cloak', '4']
}
}
}]);
await db.collection('bans').updateMany({
'ip.raw': /:/
}, [{
'$set': {
'ip.type': 1,
'ip.cloak': {
$concat: ['$ip.cloak', '6']
}
}
}]);
await db.collection('bans').updateMany({
'ip.cloak': /PRUNED$/
}, {
'$set': {
'ip.type': 3,
}
});
await db.collection('bans').updateMany({
'ip.cloak': /BP$/
}, {
'$set': {
'ip.type': 2,
}
});
console.log('Clearing globalsettings cache');
await redis.deletePattern('globalsettings');
};