483 creating=False) |
483 creating=False) |
484 # XXX check self.values['cardinality'][0] actually changed? |
484 # XXX check self.values['cardinality'][0] actually changed? |
485 sql = adbh.sql_set_null_allowed(table, column, coltype, |
485 sql = adbh.sql_set_null_allowed(table, column, coltype, |
486 self.values['cardinality'][0] != '1') |
486 self.values['cardinality'][0] != '1') |
487 self.session.system_sql(sql) |
487 self.session.system_sql(sql) |
|
488 if 'fulltextindexed' in self.values: |
|
489 UpdateFTIndexOp(self.session) |
|
490 self.session.transaction_data.setdefault('fti_update_etypes', |
|
491 set()).add(etype) |
488 |
492 |
489 |
493 |
490 class SourceDbCWConstraintAdd(hook.Operation): |
494 class SourceDbCWConstraintAdd(hook.Operation): |
491 """actually update constraint of a relation definition""" |
495 """actually update constraint of a relation definition""" |
492 entity = None # make pylint happy |
496 entity = None # make pylint happy |
1133 expr = self._cw.entity_from_eid(self.eidto).expression |
1137 expr = self._cw.entity_from_eid(self.eidto).expression |
1134 MemSchemaPermissionDel(self._cw, action=action, eid=self.eidfrom, |
1138 MemSchemaPermissionDel(self._cw, action=action, eid=self.eidfrom, |
1135 expr=expr) |
1139 expr=expr) |
1136 |
1140 |
1137 |
1141 |
|
1142 |
|
1143 class UpdateFTIndexOp(hook.SingleLastOperation): |
|
1144 """operation to update full text indexation of entity whose schema change |
|
1145 |
|
1146 We wait after the commit to as the schema in memory is only updated after the commit. |
|
1147 """ |
|
1148 |
|
1149 def postcommit_event(self): |
|
1150 session = self.session |
|
1151 source = session.repo.system_source |
|
1152 to_reindex = session.transaction_data.get('fti_update_etypes',()) |
|
1153 self.info('%i etypes need full text indexed reindexation', len(to_reindex)) |
|
1154 schema = self.session.repo.vreg.schema |
|
1155 for etype in to_reindex: |
|
1156 rset = session.execute('Any X WHERE X is %s' % etype) |
|
1157 self.info('Reindexing full text index for %i entity of type %s', len(rset), etype) |
|
1158 still_fti = list(schema[etype].indexable_attributes()) |
|
1159 for entity in rset.entities(): |
|
1160 try: |
|
1161 source.fti_unindex_entity(session, entity.eid) |
|
1162 for container in entity.fti_containers(): |
|
1163 if still_fti or container is not entity: |
|
1164 session.repo.index_entity(session, container) |
|
1165 except Exception, ex: |
|
1166 self.critical('Error while updating Full Text Index for' |
|
1167 ' entity %s', entity.eid, exc_info=True) |
|
1168 if len(to_reindex): |
|
1169 # Transaction have already been committed |
|
1170 session.pool.commit() |
|
1171 |
|
1172 |
|
1173 |
|
1174 |
1138 # specializes synchronization hooks ############################################ |
1175 # specializes synchronization hooks ############################################ |
1139 |
1176 |
1140 |
1177 |
1141 class AfterAddSpecializesHook(SyncSchemaHook): |
1178 class AfterAddSpecializesHook(SyncSchemaHook): |
1142 __regid__ = 'syncaddspecializes' |
1179 __regid__ = 'syncaddspecializes' |