allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [5/8] git commit: [#7527] Replaced the migration with a raw mongo migration
Date Thu, 28 Aug 2014 20:27:44 GMT
[#7527] Replaced the migration with a raw mongo migration


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/e3eaaa04
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/e3eaaa04
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/e3eaaa04

Branch: refs/heads/master
Commit: e3eaaa04584c7de514ec3cb6030d5c0e00fd25ad
Parents: d307dca
Author: Alexander Luberg <aluberg@slashdotmedia.com>
Authored: Tue Jul 29 21:52:39 2014 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Thu Aug 28 20:27:01 2014 +0000

----------------------------------------------------------------------
 .../030-email-address-_id-to-email.js           | 20 ++++++++++
 .../030-email-address-_id-to-email.py           | 39 --------------------
 2 files changed, 20 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/e3eaaa04/scripts/migrations/030-email-address-_id-to-email.js
----------------------------------------------------------------------
diff --git a/scripts/migrations/030-email-address-_id-to-email.js b/scripts/migrations/030-email-address-_id-to-email.js
new file mode 100644
index 0000000..f831623
--- /dev/null
+++ b/scripts/migrations/030-email-address-_id-to-email.js
@@ -0,0 +1,20 @@
+//1) Copy to the new collection with data updates
+db.email_address.find().snapshot().forEach(function(e){
+    e.email = e._id;
+    e._id = new ObjectId();
+    db.email_address_new.insert(e);
+    db.email_address.update({'_id': e._id}, {'migrated': true})
+});
+//2) Updated code on production(git pull)
+//3) Rename collections
+db.email_address.renameCollection("email_address_old", {dropTarget: true})
+db.email_address_new.renameCollection("email_address", {dropTarget: true})
+//4) Post Migration - copy/update all the object which were created between 1)&2)
+db.email_address_old.find({'migrated': {'$not': false}}).snapshot().forEach(function(e){
+    e.email = e._id;
+    e._id = new ObjectId();
+    db.email_address.insert(e);
+    db.email_address_old.update({'_id': e._id}, {'migrated': true})
+});
+
+db.email_address_old.drop()

http://git-wip-us.apache.org/repos/asf/allura/blob/e3eaaa04/scripts/migrations/030-email-address-_id-to-email.py
----------------------------------------------------------------------
diff --git a/scripts/migrations/030-email-address-_id-to-email.py b/scripts/migrations/030-email-address-_id-to-email.py
deleted file mode 100644
index e70af50..0000000
--- a/scripts/migrations/030-email-address-_id-to-email.py
+++ /dev/null
@@ -1,39 +0,0 @@
-#       Licensed to the Apache Software Foundation (ASF) under one
-#       or more contributor license agreements.  See the NOTICE file
-#       distributed with this work for additional information
-#       regarding copyright ownership.  The ASF licenses this file
-#       to you under the Apache License, Version 2.0 (the
-#       "License"); you may not use this file except in compliance
-#       with the License.  You may obtain a copy of the License at
-#
-#         http://www.apache.org/licenses/LICENSE-2.0
-#
-#       Unless required by applicable law or agreed to in writing,
-#       software distributed under the License is distributed on an
-#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-#       KIND, either express or implied.  See the License for the
-#       specific language governing permissions and limitations
-#       under the License.
-
-from bson import ObjectId
-
-import logging
-
-from ming.odm import ThreadLocalORMSession
-
-from allura import model as M
-
-log = logging.getLogger(__name__)
-
-
-def main():
-    email_addresses = M.EmailAddress.query.find(dict(email=None)).all()
-    for email in email_addresses:
-        email.email = email._id
-        email._id = ObjectId()
-        ThreadLocalORMSession.flush_all()
-    ThreadLocalORMSession.close_all()
-
-
-if __name__ == '__main__':
-    main()


Mime
View raw message