467 class SourceDbRDefUpdate(hook.Operation): |
467 class SourceDbRDefUpdate(hook.Operation): |
468 """actually update some properties of a relation definition""" |
468 """actually update some properties of a relation definition""" |
469 rschema = values = None # make pylint happy |
469 rschema = values = None # make pylint happy |
470 |
470 |
471 def precommit_event(self): |
471 def precommit_event(self): |
|
472 session = self.session |
472 etype = self.kobj[0] |
473 etype = self.kobj[0] |
473 table = SQL_PREFIX + etype |
474 table = SQL_PREFIX + etype |
474 column = SQL_PREFIX + self.rschema.type |
475 column = SQL_PREFIX + self.rschema.type |
475 if 'indexed' in self.values: |
476 if 'indexed' in self.values: |
476 sysource = self.session.pool.source('system') |
477 sysource = session.pool.source('system') |
477 if self.values['indexed']: |
478 if self.values['indexed']: |
478 sysource.create_index(self.session, table, column) |
479 sysource.create_index(session, table, column) |
479 else: |
480 else: |
480 sysource.drop_index(self.session, table, column) |
481 sysource.drop_index(session, table, column) |
481 if 'cardinality' in self.values and self.rschema.final: |
482 if 'cardinality' in self.values and self.rschema.final: |
482 adbh = self.session.pool.source('system').dbhelper |
483 adbh = session.pool.source('system').dbhelper |
483 if not adbh.alter_column_support: |
484 if not adbh.alter_column_support: |
484 # not supported (and NOT NULL not set by yams in that case, so |
485 # not supported (and NOT NULL not set by yams in that case, so |
485 # no worry) |
486 # no worry) |
486 return |
487 return |
487 atype = self.rschema.objects(etype)[0] |
488 atype = self.rschema.objects(etype)[0] |
489 coltype = y2sql.type_from_constraints(adbh, atype, constraints, |
490 coltype = y2sql.type_from_constraints(adbh, atype, constraints, |
490 creating=False) |
491 creating=False) |
491 # XXX check self.values['cardinality'][0] actually changed? |
492 # XXX check self.values['cardinality'][0] actually changed? |
492 notnull = self.values['cardinality'][0] != '1' |
493 notnull = self.values['cardinality'][0] != '1' |
493 sql = adbh.sql_set_null_allowed(table, column, coltype, notnull) |
494 sql = adbh.sql_set_null_allowed(table, column, coltype, notnull) |
494 self.session.system_sql(sql) |
495 session.system_sql(sql) |
495 if 'fulltextindexed' in self.values: |
496 if 'fulltextindexed' in self.values: |
496 UpdateFTIndexOp(self.session) |
497 UpdateFTIndexOp(session) |
497 self.session.transaction_data.setdefault('fti_update_etypes', |
498 session.transaction_data.setdefault( |
498 set()).add(etype) |
499 'fti_update_etypes', set()).add(etype) |
|
500 elif 'fulltext_container' in self.values: |
|
501 ftiupdates = session.transaction_data.setdefault( |
|
502 'fti_update_etypes', set()) |
|
503 ftiupdates.add(etype) |
|
504 ftiupdates.add(self.kobj[1]) |
|
505 UpdateFTIndexOp(session) |
499 |
506 |
500 |
507 |
501 class SourceDbCWConstraintAdd(hook.Operation): |
508 class SourceDbCWConstraintAdd(hook.Operation): |
502 """actually update constraint of a relation definition""" |
509 """actually update constraint of a relation definition""" |
503 entity = None # make pylint happy |
510 entity = None # make pylint happy |
1159 for entity in rset.entities(): |
1166 for entity in rset.entities(): |
1160 try: |
1167 try: |
1161 source.fti_unindex_entity(session, entity.eid) |
1168 source.fti_unindex_entity(session, entity.eid) |
1162 for container in entity.fti_containers(): |
1169 for container in entity.fti_containers(): |
1163 if still_fti or container is not entity: |
1170 if still_fti or container is not entity: |
1164 session.repo.index_entity(session, container) |
1171 source.fti_unindex_entity(session, entity.eid) |
|
1172 source.fti_index_entity(session, container) |
1165 except Exception: |
1173 except Exception: |
1166 self.critical('Error while updating Full Text Index for' |
1174 self.critical('Error while updating Full Text Index for' |
1167 ' entity %s', entity.eid, exc_info=True) |
1175 ' entity %s', entity.eid, exc_info=True) |
1168 if len(to_reindex): |
1176 if len(to_reindex): |
1169 # Transaction have already been committed |
1177 # Transaction have already been committed |