Skip to content

Commit

Permalink
migrate broadcast tour.info
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jun 28, 2024
1 parent 9cce5fd commit 73fd1a7
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions bin/mongodb/relay-tour-info-migrate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
db.relay_tour.find({
'description': { $exists: true },
'info.dates': { $exists: false },
'info.format': { $exists: false },
'info.tc': { $exists: false },
'info.players': { $exists: false },
}).forEach(function(tour) {
if (!tour.description.includes('|')) {
return;
}
const split = tour.description.split('|').map(x => x.trim());
const info = {};
const dates = split.shift();
if (dates && /\d/.test(dates))
info.dates = dates;
const format = split.shift();
if (format)
info.format = format;
const tc = split.shift();
if (tc)
info.tc = tc.replace(/time control/i, '').trim();
const players = split.shift();
if (players)
info.players = players;
db.relay_tour.updateOne({ _id: tour._id }, { $set: { info: info } });
});

0 comments on commit 73fd1a7

Please sign in to comment.