server/migractions.py
branchstable
changeset 2963 12ad88615a12
parent 2962 5e2239672e16
child 2967 e7d348134006
child 3105 b788903e77d5
equal deleted inserted replaced
2962:5e2239672e16 2963:12ad88615a12
    59             assert repo
    59             assert repo
    60         if cnx is not None:
    60         if cnx is not None:
    61             assert repo
    61             assert repo
    62             self._cnx = cnx
    62             self._cnx = cnx
    63             self.repo = repo
    63             self.repo = repo
       
    64             self.session.data['rebuild-infered'] = False
    64         elif connect:
    65         elif connect:
    65             self.repo_connect()
    66             self.repo_connect()
    66         if not schema:
    67         if not schema:
    67             schema = config.load_schema(expand_cubes=True)
    68             schema = config.load_schema(expand_cubes=True)
    68         self.fs_schema = schema
    69         self.fs_schema = schema
   220                     login, pwd = manager_userpasswd()
   221                     login, pwd = manager_userpasswd()
   221                 except (KeyboardInterrupt, EOFError):
   222                 except (KeyboardInterrupt, EOFError):
   222                     print 'aborting...'
   223                     print 'aborting...'
   223                     sys.exit(0)
   224                     sys.exit(0)
   224             self.session.keep_pool_mode('transaction')
   225             self.session.keep_pool_mode('transaction')
       
   226             self.session.data['rebuild-infered'] = False
   225             return self._cnx
   227             return self._cnx
   226 
   228 
   227     @property
   229     @property
   228     def session(self):
   230     def session(self):
   229         return self.repo._get_session(self.cnx.sessionid)
   231         return self.repo._get_session(self.cnx.sessionid)
   624         """register a new entity type
   626         """register a new entity type
   625 
   627 
   626         in auto mode, automatically register entity's relation where the
   628         in auto mode, automatically register entity's relation where the
   627         targeted type is known
   629         targeted type is known
   628         """
   630         """
   629         applschema = self.repo.schema
   631         instschema = self.repo.schema
   630         if etype in applschema:
   632         if etype in instschema:
   631             eschema = applschema[etype]
   633             # XXX (syt) plz explain: if we're adding an entity type, it should
       
   634             # not be there...
       
   635             eschema = instschema[etype]
   632             if eschema.is_final():
   636             if eschema.is_final():
   633                 applschema.del_entity_type(etype)
   637                 instschema.del_entity_type(etype)
   634         else:
   638         else:
   635             eschema = self.fs_schema.eschema(etype)
   639             eschema = self.fs_schema.eschema(etype)
   636         confirm = self.verbosity >= 2
   640         confirm = self.verbosity >= 2
   637         # register the entity into CWEType
   641         # register the entity into CWEType
   638         self.rqlexecall(ss.eschema2rql(eschema), ask_confirm=confirm)
   642         self.rqlexecall(ss.eschema2rql(eschema), ask_confirm=confirm)
   644         # register entity's attributes
   648         # register entity's attributes
   645         for rschema, attrschema in eschema.attribute_definitions():
   649         for rschema, attrschema in eschema.attribute_definitions():
   646             # ignore those meta relations, they will be automatically added
   650             # ignore those meta relations, they will be automatically added
   647             if rschema.type in META_RTYPES:
   651             if rschema.type in META_RTYPES:
   648                 continue
   652                 continue
   649             if not rschema.type in applschema:
   653             if not rschema.type in instschema:
   650                 # need to add the relation type and to commit to get it
   654                 # need to add the relation type and to commit to get it
   651                 # actually in the schema
   655                 # actually in the schema
   652                 self.cmd_add_relation_type(rschema.type, False, commit=True)
   656                 self.cmd_add_relation_type(rschema.type, False, commit=True)
   653             # register relation definition
   657             # register relation definition
   654             self.rqlexecall(ss.rdef2rql(rschema, etype, attrschema.type),
   658             self.rqlexecall(ss.rdef2rql(rschema, etype, attrschema.type),
   655                             ask_confirm=confirm)
   659                             ask_confirm=confirm)
       
   660         # take care to newly introduced base class
       
   661         # XXX some part of this should probably be under the "if auto" block
       
   662         for spschema in eschema.specialized_by(recursive=False):
       
   663             try:
       
   664                 instspschema = instschema[spschema]
       
   665             except KeyError:
       
   666                 # specialized entity type not in schema, ignore
       
   667                 continue
       
   668             if instspschema.specializes() != eschema:
       
   669                 self.rqlexec('SET D specializes P WHERE D eid %(d)s, P name %(pn)s',
       
   670                               {'d': instspschema.eid,
       
   671                                'pn': eschema.type}, ask_confirm=confirm)
       
   672                 for rschema, tschemas, role in spschema.relation_definitions(True):
       
   673                     for tschema in tschemas:
       
   674                         if not tschema in instschema:
       
   675                             continue
       
   676                         if role == 'subject':
       
   677                             subjschema = spschema
       
   678                             objschema = tschema
       
   679                             if rschema.final and instspschema.has_subject_relation(rschema):
       
   680                                 # attribute already set, has_rdef would check if
       
   681                                 # it's of the same type, we don't want this so
       
   682                                 # simply skip here
       
   683                                 continue
       
   684                         elif role == 'object':
       
   685                             subjschema = tschema
       
   686                             objschema = spschema
       
   687                         if (rschema.rproperty(subjschema, objschema, 'infered')
       
   688                             or (instschema.has_relation(rschema) and
       
   689                                 instschema[rschema].has_rdef(subjschema, objschema))):
       
   690                                 continue
       
   691                         self.cmd_add_relation_definition(
       
   692                             subjschema.type, rschema.type, objschema.type)
   656         if auto:
   693         if auto:
   657             # we have commit here to get relation types actually in the schema
   694             # we have commit here to get relation types actually in the schema
   658             self.commit()
   695             self.commit()
   659             added = []
   696             added = []
   660             for rschema in eschema.subject_relations():
   697             for rschema in eschema.subject_relations():
   661                 # attribute relation have already been processed and
   698                 # attribute relation have already been processed and
   662                 # 'owned_by'/'created_by' will be automatically added
   699                 # 'owned_by'/'created_by' will be automatically added
   663                 if rschema.final or rschema.type in META_RTYPES:
   700                 if rschema.final or rschema.type in META_RTYPES:
   664                     continue
   701                     continue
   665                 rtypeadded = rschema.type in applschema
   702                 rtypeadded = rschema.type in instschema
   666                 for targetschema in rschema.objects(etype):
   703                 for targetschema in rschema.objects(etype):
   667                     # ignore relations where the targeted type is not in the
   704                     # ignore relations where the targeted type is not in the
   668                     # current instance schema
   705                     # current instance schema
   669                     targettype = targetschema.type
   706                     targettype = targetschema.type
   670                     if not targettype in applschema and targettype != etype:
   707                     if not targettype in instschema and targettype != etype:
   671                         continue
   708                         continue
   672                     if not rtypeadded:
   709                     if not rtypeadded:
   673                         # need to add the relation type and to commit to get it
   710                         # need to add the relation type and to commit to get it
   674                         # actually in the schema
   711                         # actually in the schema
   675                         added.append(rschema.type)
   712                         added.append(rschema.type)
   680                     # such as "Emailthread forked_from Emailthread"
   717                     # such as "Emailthread forked_from Emailthread"
   681                     added.append((etype, rschema.type, targettype))
   718                     added.append((etype, rschema.type, targettype))
   682                     self.rqlexecall(ss.rdef2rql(rschema, etype, targettype),
   719                     self.rqlexecall(ss.rdef2rql(rschema, etype, targettype),
   683                                     ask_confirm=confirm)
   720                                     ask_confirm=confirm)
   684             for rschema in eschema.object_relations():
   721             for rschema in eschema.object_relations():
   685                 rtypeadded = rschema.type in applschema or rschema.type in added
   722                 rtypeadded = rschema.type in instschema or rschema.type in added
   686                 for targetschema in rschema.subjects(etype):
   723                 for targetschema in rschema.subjects(etype):
   687                     # ignore relations where the targeted type is not in the
   724                     # ignore relations where the targeted type is not in the
   688                     # current instance schema
   725                     # current instance schema
   689                     targettype = targetschema.type
   726                     targettype = targetschema.type
   690                     # don't check targettype != etype since in this case the
   727                     # don't check targettype != etype since in this case the
   691                     # relation has already been added as a subject relation
   728                     # relation has already been added as a subject relation
   692                     if not targettype in applschema:
   729                     if not targettype in instschema:
   693                         continue
   730                         continue
   694                     if not rtypeadded:
   731                     if not rtypeadded:
   695                         # need to add the relation type and to commit to get it
   732                         # need to add the relation type and to commit to get it
   696                         # actually in the schema
   733                         # actually in the schema
   697                         self.cmd_add_relation_type(rschema.type, False, commit=True)
   734                         self.cmd_add_relation_type(rschema.type, False, commit=True)