Skip to content

Commit 86b9a77

Browse files
glassbead0vnugent
authored andcommitted
Migration to fix invalid ticks
1 parent 4a38521 commit 86b9a77

4 files changed

Lines changed: 179 additions & 0 deletions
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// This migration will update all tick styles and attemptTypes with incorrect capitalization
2+
const tickCapitalizationRs = db.ticks.updateMany(
3+
{
4+
$or: [
5+
{ style: 'lead' },
6+
{ style: 'follow' },
7+
{ style: 'tr' },
8+
{ style: 'top_rope' },
9+
{ style: 'solo' },
10+
{ style: 'aid' },
11+
{ style: 'boulder' },
12+
{ attemptType: 'onsight' },
13+
{ attemptType: 'redpoint' },
14+
{ attemptType: 'flash' },
15+
{ attemptType: 'pinkpoint' },
16+
{ attemptType: 'send' },
17+
{ attemptType: 'attempt' },
18+
{ attemptType: 'frenchfree' },
19+
{ attemptType: 'repeat' }
20+
]
21+
},
22+
[
23+
{
24+
$set: {
25+
style: {
26+
$switch: {
27+
branches: [
28+
{ case: { $eq: ['$style', 'lead'] }, then: 'Lead' },
29+
{ case: { $eq: ['$style', 'follow'] }, then: 'Follow' },
30+
{ case: { $eq: ['$style', 'tr'] }, then: 'TR' },
31+
{ case: { $eq: ['$style', 'top_rope'] }, then: 'TR' },
32+
{ case: { $eq: ['$style', 'solo'] }, then: 'Solo' },
33+
{ case: { $eq: ['$style', 'aid'] }, then: 'Aid' },
34+
{ case: { $eq: ['$style', 'boulder'] }, then: 'Boulder' }
35+
],
36+
default: '$style'
37+
}
38+
},
39+
attemptType: {
40+
$switch: {
41+
branches: [
42+
{ case: { $eq: ['$attemptType', 'redpoint'] }, then: 'Redpoint' },
43+
{ case: { $eq: ['$attemptType', 'onsight'] }, then: 'Onsight' },
44+
{ case: { $eq: ['$attemptType', 'flash'] }, then: 'Flash' },
45+
{ case: { $eq: ['$attemptType', 'pinkpoint'] }, then: 'Pinkpoint' },
46+
{ case: { $eq: ['$attemptType', 'send'] }, then: 'Send' },
47+
{ case: { $eq: ['$attemptType', 'attempt'] }, then: 'Attempt' },
48+
{ case: { $eq: ['$attemptType', 'frenchfree'] }, then: 'Frenchfree' },
49+
{ case: { $eq: ['$attemptType', 'repeat'] }, then: 'Repeat' }
50+
],
51+
default: '$attemptType'
52+
}
53+
}
54+
},
55+
}
56+
]
57+
);
58+
59+
printjson(tickCapitalizationRs);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This migration will update all ticks that have values of "N/A" for style or attemptType by unsetting those fields
2+
const tickStyleNullificationRs = db.ticks.updateMany(
3+
{
4+
style: "N/A"
5+
},
6+
{
7+
$unset: { style: "" }
8+
}
9+
);
10+
11+
const tickAttemptTypeNullificationRs = db.ticks.updateMany(
12+
{
13+
attemptType: "N/A"
14+
},
15+
{
16+
$unset: { attemptType: "" }
17+
}
18+
);
19+
20+
printjson(tickStyleNullificationRs);
21+
printjson(tickAttemptTypeNullificationRs);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// This migration will fix ticks where attemptType has a value that belongs in style instead.
2+
const attemptTypeToStyleRs = db.ticks.updateMany(
3+
{
4+
$or: [
5+
{ attemptType: 'Lead' },
6+
{ attemptType: 'TR' },
7+
{ attemptyType: 'Follow' },
8+
{ attemptyType: 'Solo' },
9+
{ attemptyType: 'Aid' },
10+
{ attemptyType: 'Boulder' }
11+
]
12+
},
13+
[
14+
{
15+
$set: {
16+
style: {
17+
$switch: {
18+
branches: [
19+
{ case: { $eq: ['$attemptType', 'Lead'] }, then: 'Lead' },
20+
{ case: { $eq: ['$attemptType', 'TR'] }, then: 'TR' },
21+
{ case: { $eq: ['$attemptType', 'Follow'] }, then: 'Follow' },
22+
{ case: { $eq: ['$attemptType', 'Solo'] }, then: 'Solo' },
23+
{ case: { $eq: ['$attemptType', 'Aid'] }, then: 'Aid' },
24+
{ case: { $eq: ['$attemptType', 'Boulder'] }, then: 'Boulder' }
25+
],
26+
default: '$style'
27+
}
28+
}
29+
}
30+
}
31+
]
32+
);
33+
34+
// Now nullify the attemptType field since we've moved that value to style
35+
const nullifyAttemptTypeRs = db.ticks.updateMany(
36+
{
37+
$or: [
38+
{ attemptType: 'Lead' },
39+
{ attemptType: 'TR' },
40+
{ attemptyType: 'Follow' },
41+
{ attemptyType: 'Solo' },
42+
{ attemptyType: 'Aid' },
43+
{ attemptyType: 'Boulder' }
44+
]
45+
},
46+
{
47+
$unset: { attemptType: "" }
48+
}
49+
);
50+
51+
printjson(attemptTypeToStyleRs);
52+
printjson(nullifyAttemptTypeRs);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// This migration will fix ticks where the style was set to a value that belongs in attemptType instead, specifically for boulders
2+
// this is likely specific to one user, but it can be run for all ticks that may be affected.
3+
4+
// Move the value of style to attemptType (and capitalize it)
5+
const incorrectBoulderTick1Rs = db.ticks.updateMany(
6+
{
7+
$or: [
8+
{ style: 'send' },
9+
{ style: 'attempt' },
10+
{ style: 'flash' }
11+
]
12+
},
13+
[
14+
{
15+
$set: {
16+
attemptType: {
17+
$switch: {
18+
branches: [
19+
{ case: { $eq: ['$style', 'send'] }, then: 'Send' },
20+
{ case: { $eq: ['$style', 'attempt'] }, then: 'Attempt' },
21+
{ case: { $eq: ['$style', 'flash'] }, then: 'Flash' }
22+
]
23+
}
24+
}
25+
}
26+
}
27+
]
28+
);
29+
30+
// Set style to 'Boulder'
31+
const incorrectBoulderTick2Rs = db.ticks.updateMany(
32+
{
33+
$or: [
34+
{ style: 'send' },
35+
{ style: 'attempt' },
36+
{ style: 'flash' }
37+
]
38+
},
39+
[
40+
{
41+
$set: { style: 'Boulder' }
42+
}
43+
]
44+
);
45+
46+
printjson(incorrectBoulderTick1Rs);
47+
printjson(incorrectBoulderTick2Rs);

0 commit comments

Comments
 (0)