hooks/syncschema.py
branchstable
changeset 4722 9c13d5db03d9
parent 4721 8f63691ccb7f
child 4763 81b0df087375
child 4806 4f12f59b1a13
equal deleted inserted replaced
4721:8f63691ccb7f 4722:9c13d5db03d9
   417         session = self.session
   417         session = self.session
   418         entity = self.entity
   418         entity = self.entity
   419         rdef = self.init_rdef(composite=entity.composite)
   419         rdef = self.init_rdef(composite=entity.composite)
   420         schema = session.vreg.schema
   420         schema = session.vreg.schema
   421         rtype = rdef.name
   421         rtype = rdef.name
   422         rschema = session.vreg.schema.rschema(rtype)
   422         rschema = schema.rschema(rtype)
   423         # this have to be done before permissions setting
   423         # this have to be done before permissions setting
   424         if rschema.inlined:
   424         if rschema.inlined:
   425             # need to add a column if the relation is inlined and if this is the
   425             # need to add a column if the relation is inlined and if this is the
   426             # first occurence of "Subject relation Something" whatever Something
   426             # first occurence of "Subject relation Something" whatever Something
   427             # and if it has not been added during other event of the same
   427             # and if it has not been added during other event of the same
   439             # schema and if it has not been added during other event of the same
   439             # schema and if it has not been added during other event of the same
   440             # transaction
   440             # transaction
   441             if not (rschema.subjects() or
   441             if not (rschema.subjects() or
   442                     rtype in session.transaction_data.get('createdtables', ())):
   442                     rtype in session.transaction_data.get('createdtables', ())):
   443                 try:
   443                 try:
   444                     rschema = session.vreg.schema.rschema(rtype)
   444                     rschema = schema.rschema(rtype)
   445                     tablesql = rschema2sql(rschema)
   445                     tablesql = rschema2sql(rschema)
   446                 except KeyError:
   446                 except KeyError:
   447                     # fake we add it to the schema now to get a correctly
   447                     # fake we add it to the schema now to get a correctly
   448                     # initialized schema but remove it before doing anything
   448                     # initialized schema but remove it before doing anything
   449                     # more dangerous...
   449                     # more dangerous...
   450                     rschema = session.vreg.schema.add_relation_type(rdef)
   450                     rschema = schema.add_relation_type(rdef)
   451                     tablesql = rschema2sql(rschema)
   451                     tablesql = rschema2sql(rschema)
   452                     session.vreg.schema.del_relation_type(rtype)
   452                     schema.del_relation_type(rtype)
   453                 # create the necessary table
   453                 # create the necessary table
   454                 for sql in tablesql.split(';'):
   454                 for sql in tablesql.split(';'):
   455                     if sql.strip():
   455                     if sql.strip():
   456                         session.system_sql(sql)
   456                         session.system_sql(sql)
   457                 session.transaction_data.setdefault('createdtables', []).append(
   457                 session.transaction_data.setdefault('createdtables', []).append(