You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2014/09/12 12:29:22 UTC

[08/28] git commit: [#7527] Added EmailAddress data migration

[#7527] Added EmailAddress data migration


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

Branch: refs/heads/je/42cc_4905
Commit: 888f60433405b009e681bda4af72b10d2ff8b7a1
Parents: 3e6fdda
Author: Alexander Luberg <al...@slashdotmedia.com>
Authored: Tue Jul 22 19:06:31 2014 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Aug 28 20:27:00 2014 +0000

----------------------------------------------------------------------
 .../030-email-address-_id-to-email.py           | 39 ++++++++++++++++++++
 1 file changed, 39 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/888f6043/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
new file mode 100644
index 0000000..e70af50
--- /dev/null
+++ b/scripts/migrations/030-email-address-_id-to-email.py
@@ -0,0 +1,39 @@
+#       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()