server/schemahooks.py
branchstable
changeset 3526 dfb2ebb765e2
parent 2967 e7d348134006
child 3531 c095f5f54873
equal deleted inserted replaced
3525:2dc3908f667f 3526:dfb2ebb765e2
   305         # entity.defaultval is a string or None, but we need a correctly typed
   305         # entity.defaultval is a string or None, but we need a correctly typed
   306         # value
   306         # value
   307         default = entity.defaultval
   307         default = entity.defaultval
   308         if default is not None:
   308         if default is not None:
   309             default = TYPE_CONVERTER[entity.otype.name](default)
   309             default = TYPE_CONVERTER[entity.otype.name](default)
   310         rdef = self.init_rdef(default=default,
   310         props = {'default': default,
   311                               indexed=entity.indexed,
   311                  'indexed': entity.indexed,
   312                               fulltextindexed=entity.fulltextindexed,
   312                  'fulltextindexed': entity.fulltextindexed,
   313                               internationalizable=entity.internationalizable)
   313                  'internationalizable': entity.internationalizable}
       
   314         rdef = self.init_rdef(**props)
   314         sysource = session.pool.source('system')
   315         sysource = session.pool.source('system')
   315         attrtype = type_from_constraints(sysource.dbhelper, rdef.object,
   316         attrtype = type_from_constraints(sysource.dbhelper, rdef.object,
   316                                          rdef.constraints)
   317                                          rdef.constraints)
   317         # XXX should be moved somehow into lgc.adbh: sqlite doesn't support to
   318         # XXX should be moved somehow into lgc.adbh: sqlite doesn't support to
   318         # add a new column with UNIQUE, it should be added after the ALTER TABLE
   319         # add a new column with UNIQUE, it should be added after the ALTER TABLE
   341                 sysource.create_index(session, table, column,
   342                 sysource.create_index(session, table, column,
   342                                       unique=extra_unique_index)
   343                                       unique=extra_unique_index)
   343             except Exception, ex:
   344             except Exception, ex:
   344                 self.error('error while creating index for %s.%s: %s',
   345                 self.error('error while creating index for %s.%s: %s',
   345                            table, column, ex)
   346                            table, column, ex)
       
   347         # final relations are not infered, propagate
       
   348         rschema = self.schema.rschema(rdef.name)
       
   349         eschema = self.schema.eschema(rdef.subject)
       
   350         props.update({'constraints': rdef.constraints,
       
   351                       'description': rdef.description,
       
   352                       'cardinality': rdef.cardinality,
       
   353                       'constraints': rdef.constraints,
       
   354                       'order': rdef.order})
       
   355         for specialization in eschema.specialized_by(False):
       
   356             if rschema.has_rdef(specialization, rdef.object):
       
   357                 continue
       
   358             for rql, args in ss.frdef2rql(rschema, str(specialization),
       
   359                                           rdef.object, props):
       
   360                 session.execute(rql, args)
   346 
   361 
   347 
   362 
   348 class SourceDbCWRelationAdd(SourceDbCWAttributeAdd):
   363 class SourceDbCWRelationAdd(SourceDbCWAttributeAdd):
   349     """an actual relation has been added:
   364     """an actual relation has been added:
   350     * if this is an inlined relation, add the necessary column
   365     * if this is an inlined relation, add the necessary column