provide a new add_cubes() migration function for cases where the new cubes are linked together by new relations
In this case, we need to add all new cubes at once.
--- a/common/migration.py Tue Feb 17 16:20:53 2009 +0100
+++ b/common/migration.py Tue Feb 17 16:33:52 2009 +0100
@@ -312,12 +312,18 @@
"""a configuration option's type has changed"""
self._option_changes.append(('typechanged', optname, oldtype, newvalue))
- def cmd_add_cube(self, cube):
+ def cmd_add_cubes(self, cubes):
+ """modify the list of used cubes in the in-memory config
+ returns newly inserted cubes, including dependencies
+ """
+ if isinstance(cubes, basestring):
+ cubes = (cubes,)
origcubes = self.config.cubes()
- newcubes = [p for p in self.config.expand_cubes([cube])
+ newcubes = [p for p in self.config.expand_cubes(cubes)
if not p in origcubes]
if newcubes:
- assert cube in newcubes
+ for cube in cubes:
+ assert cube in newcubes
self.config.add_cubes(newcubes)
return newcubes
--- a/server/migractions.py Tue Feb 17 16:20:53 2009 +0100
+++ b/server/migractions.py Tue Feb 17 16:33:52 2009 +0100
@@ -264,13 +264,15 @@
self.commit()
def cmd_add_cube(self, cube, update_database=True):
+ self.cmd_add_cubes( (cube,), update_database)
+
+ def cmd_add_cubes(self, cubes, update_database=True):
"""update_database is telling if the database schema should be updated
or if only the relevant eproperty should be inserted (for the case where
a cube has been extracted from an existing application, so the
cube schema is already in there)
"""
- newcubes = super(ServerMigrationHelper, self).cmd_add_cube(
- cube)
+ newcubes = super(ServerMigrationHelper, self).cmd_add_cubes(cubes)
if not newcubes:
return
for pack in newcubes:
@@ -279,22 +281,22 @@
if not update_database:
self.commit()
return
- self.new_schema = self.config.load_schema()
+ with_new_cubes = self.config.load_schema()
new = set()
# execute pre-create files
for pack in reversed(newcubes):
self.exec_event_script('precreate', self.config.cube_dir(pack))
# add new entity and relation types
- for rschema in self.new_schema.relations():
+ for rschema in with_new_cubes.relations():
if not rschema in self.repo.schema:
self.cmd_add_relation_type(rschema.type)
new.add(rschema.type)
- for eschema in self.new_schema.entities():
+ for eschema in with_new_cubes.entities():
if not eschema in self.repo.schema:
self.cmd_add_entity_type(eschema.type)
new.add(eschema.type)
# check if attributes has been added to existing entities
- for rschema in self.new_schema.relations():
+ for rschema in with_new_cubes.relations():
existingschema = self.repo.schema.rschema(rschema.type)
for (fromtype, totype) in rschema.iter_rdefs():
if existingschema.has_rdef(fromtype, totype):