cubicweb/server/migractions.py
branch3.24
changeset 11905 2f36115d38b1
parent 11904 e760c54490b1
child 11906 51057823b528
equal deleted inserted replaced
11904:e760c54490b1 11905:2f36115d38b1
   664             self.cmd_install_custom_sql_scripts(cube)
   664             self.cmd_install_custom_sql_scripts(cube)
   665             self.cmd_exec_event_script('precreate', cube)
   665             self.cmd_exec_event_script('precreate', cube)
   666         # add new entity and relation types
   666         # add new entity and relation types
   667         for rschema in newcubes_schema.relations():
   667         for rschema in newcubes_schema.relations():
   668             if rschema not in self.repo.schema:
   668             if rschema not in self.repo.schema:
   669                 self.cmd_add_relation_type(rschema.type)
   669                 self.cmd_add_relation_type(rschema.type, commit=False)
   670                 new.add(rschema.type)
   670                 new.add(rschema.type)
   671         toadd = [eschema for eschema in newcubes_schema.entities()
   671         toadd = [eschema for eschema in newcubes_schema.entities()
   672                  if eschema not in self.repo.schema]
   672                  if eschema not in self.repo.schema]
   673         for eschema in order_eschemas(toadd):
   673         for eschema in order_eschemas(toadd):
   674             self.cmd_add_entity_type(eschema.type)
   674             self.cmd_add_entity_type(eschema.type)
   871                         continue
   871                         continue
   872                     if not rtypeadded:
   872                     if not rtypeadded:
   873                         # need to add the relation type and to commit to get it
   873                         # need to add the relation type and to commit to get it
   874                         # actually in the schema
   874                         # actually in the schema
   875                         added.append(rschema.type)
   875                         added.append(rschema.type)
   876                         self.cmd_add_relation_type(rschema.type, False, commit=True)
   876                         self.cmd_add_relation_type(rschema.type, False, commit=False)
   877                         rtypeadded = True
   877                         rtypeadded = True
   878                     # register relation definition
   878                     # register relation definition
   879                     # remember this two avoid adding twice non symmetric relation
   879                     # remember this two avoid adding twice non symmetric relation
   880                     # such as "Emailthread forked_from Emailthread"
   880                     # such as "Emailthread forked_from Emailthread"
   881                     added.append((etype, rschema.type, targettype))
   881                     added.append((etype, rschema.type, targettype))
   895                     if targettype not in instschema:
   895                     if targettype not in instschema:
   896                         continue
   896                         continue
   897                     if not rtypeadded:
   897                     if not rtypeadded:
   898                         # need to add the relation type and to commit to get it
   898                         # need to add the relation type and to commit to get it
   899                         # actually in the schema
   899                         # actually in the schema
   900                         self.cmd_add_relation_type(rschema.type, False, commit=True)
   900                         self.cmd_add_relation_type(rschema.type, False, commit=False)
   901                         rtypeadded = True
   901                         rtypeadded = True
   902                     elif (targettype, rschema.type, etype) in added:
   902                     elif (targettype, rschema.type, etype) in added:
   903                         continue
   903                         continue
   904                     # register relation definition
   904                     # register relation definition
   905                     rdef = self._get_rdef(rschema, targetschema, eschema)
   905                     rdef = self._get_rdef(rschema, targetschema, eschema)
  1094         if oldname in self.fs_schema and not force:
  1094         if oldname in self.fs_schema and not force:
  1095             if not self.confirm('Relation %s is still present in the filesystem schema,'
  1095             if not self.confirm('Relation %s is still present in the filesystem schema,'
  1096                                 ' do you really want to drop it?' % oldname,
  1096                                 ' do you really want to drop it?' % oldname,
  1097                                 default='n'):
  1097                                 default='n'):
  1098                 return
  1098                 return
  1099         self.cmd_add_relation_type(newname, commit=True)
  1099         self.cmd_add_relation_type(newname, commit=False)
  1100         if not self.repo.schema[oldname].rule:
  1100         if not self.repo.schema[oldname].rule:
  1101             self.rqlexec('SET X %s Y WHERE X %s Y' % (newname, oldname),
  1101             self.rqlexec('SET X %s Y WHERE X %s Y' % (newname, oldname),
  1102                          ask_confirm=self.verbosity >= 2)
  1102                          ask_confirm=self.verbosity >= 2)
  1103         self.cmd_drop_relation_type(oldname, commit=commit)
  1103         self.cmd_drop_relation_type(oldname, commit=commit)
  1104 
  1104 
  1109         rschema = self.fs_schema.rschema(rtype)
  1109         rschema = self.fs_schema.rschema(rtype)
  1110         if rschema.rule:
  1110         if rschema.rule:
  1111             raise ExecutionError('Cannot add a relation definition for a '
  1111             raise ExecutionError('Cannot add a relation definition for a '
  1112                                  'computed relation (%s)' % rschema)
  1112                                  'computed relation (%s)' % rschema)
  1113         if rtype not in self.repo.schema:
  1113         if rtype not in self.repo.schema:
  1114             self.cmd_add_relation_type(rtype, addrdef=False, commit=True)
  1114             self.cmd_add_relation_type(rtype, addrdef=False, commit=False)
  1115         if (subjtype, objtype) in self.repo.schema.rschema(rtype).rdefs:
  1115         if (subjtype, objtype) in self.repo.schema.rschema(rtype).rdefs:
  1116             print('warning: relation %s %s %s is already known, skip addition' % (
  1116             print('warning: relation %s %s %s is already known, skip addition' % (
  1117                 subjtype, rtype, objtype))
  1117                 subjtype, rtype, objtype))
  1118             return
  1118             return
  1119         rdef = self._get_rdef(rschema, subjtype, objtype)
  1119         rdef = self._get_rdef(rschema, subjtype, objtype)