438 # rdef has been infered then explicitly added (current consensus is |
438 # rdef has been infered then explicitly added (current consensus is |
439 # not clear at all versus infered relation handling (and much |
439 # not clear at all versus infered relation handling (and much |
440 # probably buggy) |
440 # probably buggy) |
441 rdef = self.cnx.vreg.schema.rschema(rdefdef.name).rdefs[rdefdef.subject, rdefdef.object] |
441 rdef = self.cnx.vreg.schema.rschema(rdefdef.name).rdefs[rdefdef.subject, rdefdef.object] |
442 assert rdef.infered |
442 assert rdef.infered |
|
443 else: |
|
444 rdef = self.cnx.vreg.schema.rschema(rdefdef.name).rdefs[rdefdef.subject, rdefdef.object] |
|
445 |
443 self.cnx.execute('SET X ordernum Y+1 ' |
446 self.cnx.execute('SET X ordernum Y+1 ' |
444 'WHERE X from_entity SE, SE eid %(se)s, X ordernum Y, ' |
447 'WHERE X from_entity SE, SE eid %(se)s, X ordernum Y, ' |
445 'X ordernum >= %(order)s, NOT X eid %(x)s', |
448 'X ordernum >= %(order)s, NOT X eid %(x)s', |
446 {'x': entity.eid, 'se': fromentity.eid, |
449 {'x': entity.eid, 'se': fromentity.eid, |
447 'order': entity.ordernum or 0}) |
450 'order': entity.ordernum or 0}) |
448 return rdefdef |
451 return rdefdef, rdef |
449 |
452 |
450 def precommit_event(self): |
453 def precommit_event(self): |
451 cnx = self.cnx |
454 cnx = self.cnx |
452 entity = self.entity |
455 entity = self.entity |
453 # entity.defaultval is a Binary or None, but we need a correctly typed |
456 # entity.defaultval is a Binary or None, but we need a correctly typed |
463 props.update(json.load(entity.extra_props)) |
466 props.update(json.load(entity.extra_props)) |
464 # entity.formula may not exist yet if we're migrating to 3.20 |
467 # entity.formula may not exist yet if we're migrating to 3.20 |
465 if hasattr(entity, 'formula'): |
468 if hasattr(entity, 'formula'): |
466 props['formula'] = entity.formula |
469 props['formula'] = entity.formula |
467 # update the in-memory schema first |
470 # update the in-memory schema first |
468 rdefdef = self.init_rdef(**props) |
471 rdefdef, rdef = self.init_rdef(**props) |
469 # then make necessary changes to the system source database |
472 # then make necessary changes to the system source database |
470 syssource = cnx.repo.system_source |
473 syssource = cnx.repo.system_source |
471 attrtype = y2sql.type_from_constraints( |
474 attrtype = y2sql.type_from_rdef(syssource.dbhelper, rdef) |
472 syssource.dbhelper, rdefdef.object, rdefdef.constraints) |
|
473 # XXX should be moved somehow into lgdb: sqlite doesn't support to |
475 # XXX should be moved somehow into lgdb: sqlite doesn't support to |
474 # add a new column with UNIQUE, it should be added after the ALTER TABLE |
476 # add a new column with UNIQUE, it should be added after the ALTER TABLE |
475 # using ADD INDEX |
477 # using ADD INDEX |
476 if syssource.dbdriver == 'sqlite' and 'UNIQUE' in attrtype: |
478 if syssource.dbdriver == 'sqlite' and 'UNIQUE' in attrtype: |
477 extra_unique_index = True |
479 extra_unique_index = True |
547 |
549 |
548 def precommit_event(self): |
550 def precommit_event(self): |
549 cnx = self.cnx |
551 cnx = self.cnx |
550 entity = self.entity |
552 entity = self.entity |
551 # update the in-memory schema first |
553 # update the in-memory schema first |
552 rdefdef = self.init_rdef(composite=entity.composite) |
554 rdefdef, rdef = self.init_rdef(composite=entity.composite) |
553 # then make necessary changes to the system source database |
555 # then make necessary changes to the system source database |
554 schema = cnx.vreg.schema |
556 schema = cnx.vreg.schema |
555 rtype = rdefdef.name |
557 rtype = rdefdef.name |
556 rschema = schema.rschema(rtype) |
558 rschema = schema.rschema(rtype) |
557 # this have to be done before permissions setting |
559 # this have to be done before permissions setting |