[migration] fix bootstrap migration of 3.5 : need to support old-style and new-style hooks to migrate from 3.4 to 3.6
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Wed, 23 Sep 2009 09:54:01 +0200
changeset 3395 405f393bcac0
parent 3394 51a25bdd7bdc
child 3396 fb261afd49cd
[migration] fix bootstrap migration of 3.5 : need to support old-style and new-style hooks to migrate from 3.4 to 3.6
misc/migration/bootstrapmigration_repository.py
--- a/misc/migration/bootstrapmigration_repository.py	Wed Sep 23 09:52:52 2009 +0200
+++ b/misc/migration/bootstrapmigration_repository.py	Wed Sep 23 09:54:01 2009 +0200
@@ -35,14 +35,22 @@
     # drop explicit 'State allowed_transition Transition' since it should be
     # infered due to yams inheritance.  However we've to disable the schema
     # sync hook first to avoid to destroy existing data...
-    from cubicweb.server.schemahooks import after_del_relation_type
-    repo.hm.unregister_hook(after_del_relation_type,
-                            'after_delete_relation', 'relation_type')
     try:
-        drop_relation_definition('State', 'allowed_transition', 'Transition')
-    finally:
-        repo.hm.register_hook(after_del_relation_type,
-                              'after_delete_relation', 'relation_type')
+        from cubicweb.hooks import syncschema
+        repo.vreg.unregister(syncschema.AfterDelRelationTypeHook)
+        try:
+            drop_relation_definition('State', 'allowed_transition', 'Transition')
+        finally:
+            repo.vreg.register(syncschema.AfterDelRelationTypeHook)
+    except ImportError: # syncschema is in CW >= 3.6 only
+        from cubicweb.server.schemahooks import after_del_relation_type
+        repo.hm.unregister_hook(after_del_relation_type,
+                                'after_delete_relation', 'relation_type')
+        try:
+            drop_relation_definition('State', 'allowed_transition', 'Transition')
+        finally:
+            repo.hm.register_hook(after_del_relation_type,
+                                  'after_delete_relation', 'relation_type')
     schema.rebuild_infered_relations() # need to be explicitly called once everything is in place
 
     for et in rql('DISTINCT Any ET,ETN WHERE S state_of ET, ET name ETN',