From 8f543118ee8fe2e3f910a4e36a50a618e0794490 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Sat, 26 May 2012 15:55:26 +0200 Subject: [PATCH] Add mongodb migration scripts --- mongo_migration_forum.js | 81 ++++++++++++++++++++++++++++++++++++++++ mongo_migration_user.js | 10 +++++ todo | 11 ++---- 3 files changed, 94 insertions(+), 8 deletions(-) create mode 100644 mongo_migration_forum.js create mode 100644 mongo_migration_user.js diff --git a/mongo_migration_forum.js b/mongo_migration_forum.js new file mode 100644 index 0000000000..38e0d085b6 --- /dev/null +++ b/mongo_migration_forum.js @@ -0,0 +1,81 @@ +// categories +var categSlugs = {}; +var topicIds = {}; + +(function(oldColl, coll) { + print("Categs"); + var cursor = oldColl.find(), nb = 0; + coll.drop(); + while(cursor.hasNext()) { + var obj = cursor.next(); + categSlugs[obj._id] = obj.slug; + coll.insert({ + _id: obj.slug, + pos: obj.position, + name: obj.name, + desc: obj.description + }); + nb ++; + } + coll.ensureIndex({pos: 1}, {unique: true}); + print("Done categs: " + nb); +})(db.forum_category, db.f_categ); + +(function(oldColl, coll) { + print("Topics"); + var cursor = oldColl.find(), nb = 0; + coll.drop(); + while(cursor.hasNext()) { + var obj = cursor.next(); + var id = makeId(8); + topicIds[obj._id] = id; + coll.insert({ + _id: id, + slug: obj.slug, + categ: categSlugs[obj.category["$id"]], + createdAt: obj.createdAt, + updatedAt: obj.pulledAt, + views: obj.numViews, + name: obj.subject + }); + nb ++; + } + coll.ensureIndex({categ: 1, slug: 1}, {unique: true}); + coll.ensureIndex({categ: 1}); + coll.ensureIndex({categ: 1, updatedAt: -1}); + print("Done topics: " + nb); +})(db.forum_topic, db.f_topic); + +(function(oldColl, coll) { + print("Posts"); + var cursor = oldColl.find(), nb = 0; + coll.drop(); + while(cursor.hasNext()) { + var obj = cursor.next(); + var post = { + _id: makeId(8), + topic: topicIds[obj.topic["$id"]], + createdAt: obj.createdAt, + author: obj.authorName, + text: obj.message + }; + if (obj.author) { + post.user = obj.author; + } + coll.insert(post); + nb ++; + } + coll.ensureIndex({topic: 1}); + coll.ensureIndex({topic: 1, createdAt: -1}); + print("Done posts: " + nb); +})(db.forum_post, db.f_post); + +function makeId(size) { + var text = ""; + var possible = "abcdefghijklmnopqrstuvwxyz0123456789"; + + for( var i=0; i < size; i++ ) + text += possible.charAt(Math.floor(Math.random() * possible.length)); + + return text; +} diff --git a/mongo_migration_user.js b/mongo_migration_user.js new file mode 100644 index 0000000000..bc5e236899 --- /dev/null +++ b/mongo_migration_user.js @@ -0,0 +1,10 @@ +db.fos_user_group.drop() +db.user.dropIndex("emailCanonical_1") +db.user.dropIndex("isOnline_-1") +db.user.update({},{$unset:{lastLogin: true}}, false, true) +db.user.update({},{$unset:{isOnline: true}}, false, true) +db.user.update({},{$unset:{gameConfigs: true}}, false, true) +db.user.update({},{$unset:{email: true}}, false, true) +db.user.update({},{$unset:{emailCanonical: true}}, false, true) +db.user.update({},{$unset:{updatedAt: true}}, false, true) +db.user.update({elo: {$lt: 800}}, {$set: {elo: 800}}, false, true) diff --git a/todo b/todo index 2078132920..b75652f02b 100644 --- a/todo +++ b/todo @@ -20,13 +20,8 @@ chess960 confirmation http://fr.lichess.org/forum/lichess-feedback/separate-960- use play-navigator router case class MyRegexStr(value: String); implicit val MyRegexStrPathParam: PathParam[MyRegexStr] = new PathParam[MyRegexStr] { def apply(s: MyRegexStr) = s.value}; def unapply(s: String) = val Rx = "(\w+)".r; s match { case Rx(x) => Some(x); case _ => None } } http://codetunes.com/2012/05/09/scala-dsl-tutorial-writing-web-framework-router use POST instead of GET where it makes sense +endgame sound http://en.lichess.org/forum/lichess-feedback/checkmate-sound-feature?page=1#1 next deploy: -db.user.update({},{$unset:{lastLogin: true}}, false, true) -db.user.update({},{$unset:{isOnline: true}}, false, true) -db.user.update({},{$unset:{gameConfigs: true}}, false, true) -db.user.update({},{$unset:{email: true}}, false, true) -db.user.dropIndex("emailCanonical_1") -db.user.update({},{$unset:{emailCanonical: true}}, false, true) -db.user.update({},{$unset:{updatedAt: true}}, false, true) -db.user.update({elo: {$lt: 800}}, {$set: {elo: 800}}, false, true) +mongo lichess mongo_migration_user.js +mongo lichess mongo_migration_forum.js