461 class SourceDbRDefUpdate(hook.Operation): |
461 class SourceDbRDefUpdate(hook.Operation): |
462 """actually update some properties of a relation definition""" |
462 """actually update some properties of a relation definition""" |
463 rschema = values = None # make pylint happy |
463 rschema = values = None # make pylint happy |
464 |
464 |
465 def precommit_event(self): |
465 def precommit_event(self): |
|
466 session = self.session |
466 etype = self.kobj[0] |
467 etype = self.kobj[0] |
467 table = SQL_PREFIX + etype |
468 table = SQL_PREFIX + etype |
468 column = SQL_PREFIX + self.rschema.type |
469 column = SQL_PREFIX + self.rschema.type |
469 if 'indexed' in self.values: |
470 if 'indexed' in self.values: |
470 sysource = self.session.pool.source('system') |
471 sysource = session.pool.source('system') |
471 if self.values['indexed']: |
472 if self.values['indexed']: |
472 sysource.create_index(self.session, table, column) |
473 sysource.create_index(session, table, column) |
473 else: |
474 else: |
474 sysource.drop_index(self.session, table, column) |
475 sysource.drop_index(session, table, column) |
475 if 'cardinality' in self.values and self.rschema.final: |
476 if 'cardinality' in self.values and self.rschema.final: |
476 adbh = self.session.pool.source('system').dbhelper |
477 adbh = session.pool.source('system').dbhelper |
477 if not adbh.alter_column_support: |
478 if not adbh.alter_column_support: |
478 # not supported (and NOT NULL not set by yams in that case, so |
479 # not supported (and NOT NULL not set by yams in that case, so |
479 # no worry) |
480 # no worry) |
480 return |
481 return |
481 atype = self.rschema.objects(etype)[0] |
482 atype = self.rschema.objects(etype)[0] |
483 coltype = type_from_constraints(adbh, atype, constraints, |
484 coltype = type_from_constraints(adbh, atype, constraints, |
484 creating=False) |
485 creating=False) |
485 # XXX check self.values['cardinality'][0] actually changed? |
486 # XXX check self.values['cardinality'][0] actually changed? |
486 sql = adbh.sql_set_null_allowed(table, column, coltype, |
487 sql = adbh.sql_set_null_allowed(table, column, coltype, |
487 self.values['cardinality'][0] != '1') |
488 self.values['cardinality'][0] != '1') |
488 self.session.system_sql(sql) |
489 session.system_sql(sql) |
489 if 'fulltextindexed' in self.values: |
490 if 'fulltextindexed' in self.values: |
490 UpdateFTIndexOp(self.session) |
491 UpdateFTIndexOp(session) |
491 self.session.transaction_data.setdefault('fti_update_etypes', |
492 session.transaction_data.setdefault( |
492 set()).add(etype) |
493 'fti_update_etypes', set()).add(etype) |
|
494 elif 'fulltext_container' in self.values: |
|
495 ftiupdates = session.transaction_data.setdefault( |
|
496 'fti_update_etypes', set()) |
|
497 ftiupdates.add(etype) |
|
498 ftiupdates.add(self.kobj[1]) |
|
499 UpdateFTIndexOp(session) |
493 |
500 |
494 |
501 |
495 class SourceDbCWConstraintAdd(hook.Operation): |
502 class SourceDbCWConstraintAdd(hook.Operation): |
496 """actually update constraint of a relation definition""" |
503 """actually update constraint of a relation definition""" |
497 entity = None # make pylint happy |
504 entity = None # make pylint happy |