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
merge-requests/341/head v0.11.0
Thomas Lynch 1 year ago
parent 78cf3bde5a
commit 5f99ca5062
  1. 69
      migrations/0.11.0.js

@ -3,25 +3,47 @@
module.exports = async(db, redis) => {
console.log('changing post/report/ban ip type storage format');
await db.collection('posts').updateMany({
'ip.cloak': /PRUNED$/
/* Make sure they all existing ones at least have a type
in case the site uses "dont store raw ips" */
}, {
'$set': {
'ip.type': 3,
'ip.type': 0,
}
});
});
await db.collection('posts').updateMany({
'ip.cloak': /BP$/
'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': 2,
'ip.type': 3,
}
});
await db.collection('posts').updateMany({
'ip.cloak': /IP[46]*$/
'ip.cloak': /BP$/
}, {
'$set': {
'ip.type': 0, //wont try and figure out migrating ipv4 vs 6
'ip.type': 2,
}
});
await db.collection('posts').updateMany({}, {
@ -32,24 +54,45 @@ module.exports = async(db, redis) => {
});
await db.collection('bans').updateMany({
'ip.cloak': /PRUNED$/
/* Make sure they all existing ones at least have a type
in case the site uses "dont store raw ips" */
}, {
'$set': {
'ip.type': 3,
'ip.type': 0,
}
});
await db.collection('bans').updateMany({
'ip.cloak': /BP$/
'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': 2,
'ip.type': 3,
}
});
await db.collection('bans').updateMany({
'ip.cloak': /IP[46]*$/
'ip.cloak': /BP$/
}, {
'$set': {
'ip.type': 0,
'ip.type': 2,
}
});

Loading…
Cancel
Save