changeset 4774:3adff0fb0207

Fixed issue2550595: Allow migrating from roundup 0.x to 1.4 All changes were required to make an upgrade from 0.6 to 1.4, The changes affecting "retired" were required for an upgrade from 0.8 to 1.4.
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 22 Mar 2013 15:53:27 +0100
parents 8ab5d7d63191
children d00a3ede67e4 4f25deb20dfa 6e9b9743de89
files CHANGES.txt roundup/backends/back_sqlite.py roundup/backends/rdbms_common.py
diffstat 3 files changed, 19 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Fri Mar 22 12:09:12 2013 +0100
+++ b/CHANGES.txt	Fri Mar 22 15:53:27 2013 +0100
@@ -39,6 +39,7 @@
   where demo.py listens. (John Rouillard)
 - issue2550802: Fixed date so second fraction can't cause rounding to
   60.000 when serialising. Report and fix by Erik Hanspers. (Bernhard Reiter)
+- issue2550595: Allow migrating from roundup 0.x to 1.4 (Thomas Arendsen Hein)
 
 2012-12-21: 1.4.21
 
--- a/roundup/backends/back_sqlite.py	Fri Mar 22 12:09:12 2013 +0100
+++ b/roundup/backends/back_sqlite.py	Fri Mar 22 15:53:27 2013 +0100
@@ -254,7 +254,7 @@
         self.create_class_table(spec)
 
         if olddata:
-            inscols = ['id', '_actor', '_activity', '_creation', '_creator']
+            inscols = ['id', '_actor', '_activity', '_creation', '_creator', '__retired__']
             for propname,x in new_spec[1]:
                 prop = properties[propname]
                 if isinstance(prop, hyperdb.Multilink):
@@ -273,6 +273,7 @@
             sql = 'insert into _%s (%s) values (%s)'%(cn, cols, args)
             for entry in olddata:
                 d = []
+                retired_id = None
                 for name in inscols:
                     # generate the new value for the Interval int column
                     if name.endswith('_int__'):
@@ -295,6 +296,10 @@
                         v = entry[name]
                     else:
                         v = None
+                    if name == 'id':
+                        retired_id = v
+                    elif name == '__retired__' and retired_id and v not in ['0', 0]:
+                        v = retired_id
                     d.append(v)
                 self.sql(sql, tuple(d))
 
--- a/roundup/backends/rdbms_common.py	Fri Mar 22 12:09:12 2013 +0100
+++ b/roundup/backends/rdbms_common.py	Fri Mar 22 15:53:27 2013 +0100
@@ -274,7 +274,10 @@
             We should now confirm that the schema defined by our "classes"
             attribute actually matches the schema in the database.
         """
-        save = 0
+
+        # upgrade the database for column type changes, new internal
+        # tables, etc.
+        save = self.upgrade_db()
 
         # handle changes in the schema
         tables = self.database_schema['tables']
@@ -295,10 +298,6 @@
                 del tables[classname]
                 save = 1
 
-        # now upgrade the database for column type changes, new internal
-        # tables, etc.
-        save = save | self.upgrade_db()
-
         # update the database version of the schema
         if save:
             self.save_dbschema()
@@ -345,9 +344,11 @@
             self.fix_version_2_tables()
 
         if version < 4:
+            self.log_info('upgrade to version 4')
             self.fix_version_3_tables()
 
         if version < 5:
+            self.log_info('upgrade to version 5')
             self.fix_version_4_tables()
 
         self.database_schema['version'] = self.current_db_version
@@ -645,7 +646,12 @@
     def add_class_key_required_unique_constraint(self, cn, key):
         sql = '''create unique index _%s_key_retired_idx
             on _%s(__retired__, _%s)'''%(cn, cn, key)
-        self.sql(sql)
+        try:
+            self.sql(sql)
+        except StandardError:
+            # XXX catch e.g.:
+            # _sqlite.DatabaseError: index _status_key_retired_idx already exists
+            pass
 
     def drop_class_table_indexes(self, cn, key):
         # drop the old table indexes first

Roundup Issue Tracker: http://roundup-tracker.org/