hooks/syncschema.py
changeset 3536 f6c9a5df80fb
parent 3531 c095f5f54873
parent 3431 6944a92c16f2
child 3589 a5432f99f2d9
equal deleted inserted replaced
3524:a3431f4e2f40 3536:f6c9a5df80fb
   315         # entity.defaultval is a string or None, but we need a correctly typed
   315         # entity.defaultval is a string or None, but we need a correctly typed
   316         # value
   316         # value
   317         default = entity.defaultval
   317         default = entity.defaultval
   318         if default is not None:
   318         if default is not None:
   319             default = TYPE_CONVERTER[entity.otype.name](default)
   319             default = TYPE_CONVERTER[entity.otype.name](default)
   320         rdef = self.init_rdef(default=default,
   320         props = {'default': default,
   321                               indexed=entity.indexed,
   321                  'indexed': entity.indexed,
   322                               fulltextindexed=entity.fulltextindexed,
   322                  'fulltextindexed': entity.fulltextindexed,
   323                               internationalizable=entity.internationalizable)
   323                  'internationalizable': entity.internationalizable}
       
   324         rdef = self.init_rdef(**props)
   324         sysource = session.pool.source('system')
   325         sysource = session.pool.source('system')
   325         attrtype = type_from_constraints(sysource.dbhelper, rdef.object,
   326         attrtype = type_from_constraints(sysource.dbhelper, rdef.object,
   326                                          rdef.constraints)
   327                                          rdef.constraints)
   327         # XXX should be moved somehow into lgc.adbh: sqlite doesn't support to
   328         # XXX should be moved somehow into lgc.adbh: sqlite doesn't support to
   328         # add a new column with UNIQUE, it should be added after the ALTER TABLE
   329         # add a new column with UNIQUE, it should be added after the ALTER TABLE
   351                 sysource.create_index(session, table, column,
   352                 sysource.create_index(session, table, column,
   352                                       unique=extra_unique_index)
   353                                       unique=extra_unique_index)
   353             except Exception, ex:
   354             except Exception, ex:
   354                 self.error('error while creating index for %s.%s: %s',
   355                 self.error('error while creating index for %s.%s: %s',
   355                            table, column, ex)
   356                            table, column, ex)
       
   357         # final relations are not infered, propagate
       
   358         try:
       
   359             eschema = self.schema.eschema(rdef.subject)
       
   360         except KeyError:
       
   361             return # entity type currently being added
       
   362         rschema = self.schema.rschema(rdef.name)
       
   363         props.update({'constraints': rdef.constraints,
       
   364                       'description': rdef.description,
       
   365                       'cardinality': rdef.cardinality,
       
   366                       'constraints': rdef.constraints,
       
   367                       'order': rdef.order})
       
   368         for specialization in eschema.specialized_by(False):
       
   369             if rschema.has_rdef(specialization, rdef.object):
       
   370                 continue
       
   371             for rql, args in ss.frdef2rql(rschema, str(specialization),
       
   372                                           rdef.object, props):
       
   373                 session.execute(rql, args)
   356 
   374 
   357 
   375 
   358 class SourceDbCWRelationAdd(SourceDbCWAttributeAdd):
   376 class SourceDbCWRelationAdd(SourceDbCWAttributeAdd):
   359     """an actual relation has been added:
   377     """an actual relation has been added:
   360     * if this is an inlined relation, add the necessary column
   378     * if this is an inlined relation, add the necessary column