[Checkins] SVN: zope.generations/trunk/ Generations key (stored in database root) has been changed from ``zope.app.generations`` to ``zope.generations``. Migration is done when ``evolve`` is run the first time by coping the exisiting generations data over to the new key. So the old and the new key can be used in parallel.

Michael Howitz mh at gocept.com
Sat Sep 18 06:53:02 EDT 2010


Log message for revision 116562:
  Generations key (stored in database root) has been changed from ``zope.app.generations`` to ``zope.generations``.  Migration is done when ``evolve`` is run the first time by coping the exisiting generations data over to the new key. So the old and the new key can be used in parallel.
  

Changed:
  U   zope.generations/trunk/CHANGES.txt
  U   zope.generations/trunk/src/zope/generations/generations.py
  A   zope.generations/trunk/src/zope/generations/tests/test_backwardcompat.py

-=-
Modified: zope.generations/trunk/CHANGES.txt
===================================================================
--- zope.generations/trunk/CHANGES.txt	2010-09-18 10:21:08 UTC (rev 116561)
+++ zope.generations/trunk/CHANGES.txt	2010-09-18 10:53:01 UTC (rev 116562)
@@ -5,4 +5,9 @@
 3.7.0 (unreleased)
 ------------------
 
-- Initial release extracted from `zope.app.generations`.
\ No newline at end of file
+- Initial release extracted from `zope.app.generations`.
+
+- Generations key (stored in database root) has been changed from
+  ``zope.app.generations`` to ``zope.generations``.  Migration is done when
+  ``evolve`` is run the first time by coping the exisiting generations data
+  over to the new key. So the old and the new key can be used in parallel.
\ No newline at end of file

Modified: zope.generations/trunk/src/zope/generations/generations.py
===================================================================
--- zope.generations/trunk/src/zope/generations/generations.py	2010-09-18 10:21:08 UTC (rev 116561)
+++ zope.generations/trunk/src/zope/generations/generations.py	2010-09-18 10:53:01 UTC (rev 116562)
@@ -428,11 +428,18 @@
         context = Context()
         context.connection = conn
         root = conn.root()
-        generations = root.get(generations_key) #, root.get(old_generations_key))
+        generations = root.get(generations_key)
         if generations is None:
-            generations = root[generations_key] = PersistentDict()
+            # backward compatibility with zope.app.generations
+            generations = root.get(old_generations_key)
+            if generations is not None:
+                # switch over to new generations_key
+                root[generations_key] = generations
+            else:
+                generations = root[generations_key] = PersistentDict()
             transaction.commit()
 
+
         for key, manager in sorted(findManagers()):
             generation = generations.get(key)
 

Added: zope.generations/trunk/src/zope/generations/tests/test_backwardcompat.py
===================================================================
--- zope.generations/trunk/src/zope/generations/tests/test_backwardcompat.py	                        (rev 0)
+++ zope.generations/trunk/src/zope/generations/tests/test_backwardcompat.py	2010-09-18 10:53:01 UTC (rev 116562)
@@ -0,0 +1,55 @@
+##############################################################################
+#
+# Copyright (c) 2010 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Backward compatibility tests."""
+
+import unittest
+
+class BackwardCompatibilityTests(unittest.TestCase):
+
+    def setUp(self):
+        from zope.generations.generations import old_generations_key
+        import ZODB.tests.util
+        import persistent.mapping
+        import transaction
+
+        self.db = ZODB.tests.util.DB(database_name='testdb')
+        self.conn = self.db.open()
+        self.root = self.conn.root()
+        generation_data = persistent.mapping.PersistentMapping()
+        generation_data['app1'] = 3
+        # Create a database using the old generations key:
+        self.root[old_generations_key] = generation_data
+        transaction.commit()
+
+    def tearDown(self):
+        import transaction
+
+        transaction.abort()
+        self.conn.close()
+        self.db.close()
+
+    def test_upgrade(self):
+        # When evolve is called on a database which contains the old
+        # generations key, it gets copied over to the new one:
+        from zope.generations.generations import (
+            evolve, generations_key, old_generations_key)
+
+        evolve(self.db)
+        self.assertEqual(self.root[old_generations_key],
+                         self.root[generations_key])
+
+        # The two dicts are the same, so changing one changes the other one,
+        # too:
+        self.root[old_generations_key]['app2'] = 2411
+        self.assertEqual(2411, self.root[generations_key]['app2'])


Property changes on: zope.generations/trunk/src/zope/generations/tests/test_backwardcompat.py
___________________________________________________________________
Added: svn:keywords
   + Id Rev Date
Added: svn:eol-style
   + native



More information about the checkins mailing list