server/schemaserial.py
changeset 9959 6047bf8df9e5
parent 9956 19a683a0047c
child 9963 5531f5577b50
equal deleted inserted replaced
9958:3b755c9057fd 9959:6047bf8df9e5
   112             cnx.commit(False)
   112             cnx.commit(False)
   113     ertidx = {}
   113     ertidx = {}
   114     copiedeids = set()
   114     copiedeids = set()
   115     permsidx = deserialize_ertype_permissions(cnx)
   115     permsidx = deserialize_ertype_permissions(cnx)
   116     schema.reading_from_database = True
   116     schema.reading_from_database = True
       
   117     # load every entity types
   117     for eid, etype, desc in cnx.execute(
   118     for eid, etype, desc in cnx.execute(
   118         'Any X, N, D WHERE X is CWEType, X name N, X description D',
   119         'Any X, N, D WHERE X is CWEType, X name N, X description D',
   119         build_descr=False):
   120         build_descr=False):
   120         # base types are already in the schema, skip them
   121         # base types are already in the schema, skip them
   121         if etype in schemamod.BASE_TYPES:
   122         if etype in schemamod.BASE_TYPES:
   160             etype = netype
   161             etype = netype
   161         ertidx[eid] = etype
   162         ertidx[eid] = etype
   162         eschema = schema.add_entity_type(
   163         eschema = schema.add_entity_type(
   163             ybo.EntityType(name=etype, description=desc, eid=eid))
   164             ybo.EntityType(name=etype, description=desc, eid=eid))
   164         set_perms(eschema, permsidx)
   165         set_perms(eschema, permsidx)
       
   166     # load inheritance relations
   165     for etype, stype in cnx.execute(
   167     for etype, stype in cnx.execute(
   166         'Any XN, ETN WHERE X is CWEType, X name XN, X specializes ET, ET name ETN',
   168         'Any XN, ETN WHERE X is CWEType, X name XN, X specializes ET, ET name ETN',
   167         build_descr=False):
   169         build_descr=False):
   168         etype = ETYPE_NAME_MAP.get(etype, etype)
   170         etype = ETYPE_NAME_MAP.get(etype, etype)
   169         stype = ETYPE_NAME_MAP.get(stype, stype)
   171         stype = ETYPE_NAME_MAP.get(stype, stype)
   170         schema.eschema(etype)._specialized_type = stype
   172         schema.eschema(etype)._specialized_type = stype
   171         schema.eschema(stype)._specialized_by.append(etype)
   173         schema.eschema(stype)._specialized_by.append(etype)
       
   174     # load every relation types
   172     for eid, rtype, desc, sym, il, ftc in cnx.execute(
   175     for eid, rtype, desc, sym, il, ftc in cnx.execute(
   173         'Any X,N,D,S,I,FTC WHERE X is CWRType, X name N, X description D, '
   176         'Any X,N,D,S,I,FTC WHERE X is CWRType, X name N, X description D, '
   174         'X symmetric S, X inlined I, X fulltext_container FTC', build_descr=False):
   177         'X symmetric S, X inlined I, X fulltext_container FTC', build_descr=False):
   175         ertidx[eid] = rtype
   178         ertidx[eid] = rtype
   176         rschema = schema.add_relation_type(
   179         rschema = schema.add_relation_type(
   177             ybo.RelationType(name=rtype, description=desc,
   180             ybo.RelationType(name=rtype, description=desc,
   178                              symmetric=bool(sym), inlined=bool(il),
   181                              symmetric=bool(sym), inlined=bool(il),
   179                              fulltext_container=ftc, eid=eid))
   182                              fulltext_container=ftc, eid=eid))
       
   183     # remains to load every relation definitions (ie relations and attributes)
   180     cstrsidx = deserialize_rdef_constraints(cnx)
   184     cstrsidx = deserialize_rdef_constraints(cnx)
   181     pendingrdefs = []
   185     pendingrdefs = []
   182     # closure to factorize common code of attribute/relation rdef addition
   186     # closure to factorize common code of attribute/relation rdef addition
   183     def _add_rdef(rdefeid, seid, reid, oeid, **kwargs):
   187     def _add_rdef(rdefeid, seid, reid, oeid, **kwargs):
   184         rdef = ybo.RelationDefinition(ertidx[seid], ertidx[reid], ertidx[oeid],
   188         rdef = ybo.RelationDefinition(ertidx[seid], ertidx[reid], ertidx[oeid],
   205                 ertidx[rdefeid] = rdefs
   209                 ertidx[rdefeid] = rdefs
   206                 set_perms(rdefs, permsidx)
   210                 set_perms(rdefs, permsidx)
   207     # Get the type parameters for additional base types.
   211     # Get the type parameters for additional base types.
   208     try:
   212     try:
   209         extra_props = dict(cnx.execute('Any X, XTP WHERE X is CWAttribute, '
   213         extra_props = dict(cnx.execute('Any X, XTP WHERE X is CWAttribute, '
   210                                            'X extra_props XTP'))
   214                                        'X extra_props XTP'))
   211     except Exception:
   215     except Exception:
   212         cnx.critical('Previous CRITICAL notification about extra_props is not '
   216         cnx.critical('Previous CRITICAL notification about extra_props is not '
   213                          'a problem if you are migrating to cubicweb 3.17')
   217                      'a problem if you are migrating to cubicweb 3.17')
   214         extra_props = {} # not yet in the schema (introduced by 3.17 migration)
   218         extra_props = {} # not yet in the schema (introduced by 3.17 migration)
   215     for values in cnx.execute(
   219     for values in cnx.execute(
   216         'Any X,SE,RT,OE,CARD,ORD,DESC,IDX,FTIDX,I18N,DFLT WHERE X is CWAttribute,'
   220         'Any X,SE,RT,OE,CARD,ORD,DESC,IDX,FTIDX,I18N,DFLT WHERE X is CWAttribute,'
   217         'X relation_type RT, X cardinality CARD, X ordernum ORD, X indexed IDX,'
   221         'X relation_type RT, X cardinality CARD, X ordernum ORD, X indexed IDX,'
   218         'X description DESC, X internationalizable I18N, X defaultval DFLT,'
   222         'X description DESC, X internationalizable I18N, X defaultval DFLT,'