[migration] don't attempt to carry over values when renaming a computed relation
Without the fix in migractions.py, the introduced test crashes with an
operational error because of an attempt to write to a non-existing
relation table (computed relations are not materialized).
Closes #6304946
--- a/server/migractions.py Fri Aug 21 11:01:08 2015 +0200
+++ b/server/migractions.py Tue Aug 25 11:11:34 2015 +0200
@@ -1085,8 +1085,9 @@
default='n'):
raise SystemExit(1)
self.cmd_add_relation_type(newname, commit=True)
- self.rqlexec('SET X %s Y WHERE X %s Y' % (newname, oldname),
- ask_confirm=self.verbosity>=2)
+ if not self.repo.schema[oldname].rule:
+ self.rqlexec('SET X %s Y WHERE X %s Y' % (newname, oldname),
+ ask_confirm=self.verbosity>=2)
self.cmd_drop_relation_type(oldname, commit=commit)
def cmd_add_relation_definition(self, subjtype, rtype, objtype, commit=True):
--- a/server/test/datacomputed/migratedapp/schema.py Fri Aug 21 11:01:08 2015 +0200
+++ b/server/test/datacomputed/migratedapp/schema.py Tue Aug 25 11:11:34 2015 +0200
@@ -55,3 +55,7 @@
class whatever(ComputedRelation):
rule = 'S employees E, O associates E'
+
+
+class renamed(ComputedRelation):
+ rule = 'S employees E, O concerns E'
--- a/server/test/datacomputed/schema.py Fri Aug 21 11:01:08 2015 +0200
+++ b/server/test/datacomputed/schema.py Tue Aug 25 11:11:34 2015 +0200
@@ -52,3 +52,7 @@
class whatever(ComputedRelation):
rule = 'S employees E, O concerns E'
+
+
+class to_be_renamed(ComputedRelation):
+ rule = 'S employees E, O concerns E'
--- a/server/test/unittest_migractions.py Fri Aug 21 11:01:08 2015 +0200
+++ b/server/test/unittest_migractions.py Tue Aug 25 11:11:34 2015 +0200
@@ -763,6 +763,12 @@
'Cannot synchronize a relation definition for a computed '
'relation (whatever)')
+ def test_computed_relation_rename_relation_type(self):
+ with self.mh() as (cnx, mh):
+ mh.cmd_rename_relation_type('to_be_renamed', 'renamed')
+ self.assertIn('renamed', self.schema)
+ self.assertNotIn('to_be_renamed', self.schema)
+
# computed attributes migration ############################################
def setup_add_score(self):