# HG changeset patch # User Julien Cristau # Date 1415871464 -3600 # Node ID 7b72ecc3f4d24ddf55b862fc59894e9e1c6389b7 # Parent 2a08247b57fbb03a4748d06466deaf6ee264b673 [migration] hackish black magic to bootstrap addition of formula attr during migration Turns out we can't add an attribute to CWAttribute before the attribute exists. add_attribute generates rql with a 'formula' relation, which CW doesn't know about yet, so things get unhappy. Once that is fixed, we need to make the CWAttribute addition operation deal with CWAttribute entities that don't have a formula yet. Finally, move the migration to bootstrapmigration_repository so it happens early on, and use add_entity_type rather than add_relation_type for CWComputedRType. diff -r 2a08247b57fb -r 7b72ecc3f4d2 hooks/syncschema.py --- a/hooks/syncschema.py Tue Nov 04 14:10:02 2014 +0100 +++ b/hooks/syncschema.py Thu Nov 13 10:37:44 2014 +0100 @@ -449,9 +449,11 @@ default = default.unzpickle() props = {'default': default, 'indexed': entity.indexed, - 'formula': entity.formula, 'fulltextindexed': entity.fulltextindexed, 'internationalizable': entity.internationalizable} + # entity.formula may not exist yet if we're migrating to 3.20 + if hasattr(entity, 'formula'): + props['formula'] = entity.formula # update the in-memory schema first rdefdef = self.init_rdef(**props) # then make necessary changes to the system source database @@ -505,7 +507,7 @@ cnx.system_sql('UPDATE %s SET %s=%%(default)s' % (table, column), {'default': default}) # if attribute is computed, compute it - if entity.formula: + if getattr(entity, 'formula', None): # add rtype attribute for RelationDefinitionSchema api compat, this # is what RecomputeAttributeOperation expect rdefdef.rtype = rdefdef.name diff -r 2a08247b57fb -r 7b72ecc3f4d2 misc/migration/3.20.0_Any.py --- a/misc/migration/3.20.0_Any.py Tue Nov 04 14:10:02 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -add_relation_type('CWComputedRType') -add_attribute('CWAttribute', 'formula') diff -r 2a08247b57fb -r 7b72ecc3f4d2 misc/migration/bootstrapmigration_repository.py --- a/misc/migration/bootstrapmigration_repository.py Tue Nov 04 14:10:02 2014 +0100 +++ b/misc/migration/bootstrapmigration_repository.py Thu Nov 13 10:37:44 2014 +0100 @@ -57,6 +57,14 @@ replace_eid_sequence_with_eid_numrange(session) +if applcubicwebversion < (3, 20, 0) and cubicwebversion >= (3, 20, 0): + ss._IGNORED_PROPS.append('formula') + add_attribute('CWAttribute', 'formula', commit=False) + ss._IGNORED_PROPS.remove('formula') + commit() + add_entity_type('CWComputedRType') + commit() + if applcubicwebversion < (3, 17, 0) and cubicwebversion >= (3, 17, 0): try: add_cube('sioc', update_database=False) diff -r 2a08247b57fb -r 7b72ecc3f4d2 server/schemaserial.py --- a/server/schemaserial.py Tue Nov 04 14:10:02 2014 +0100 +++ b/server/schemaserial.py Thu Nov 13 10:37:44 2014 +0100 @@ -556,12 +556,14 @@ for rql, args in _erperms2rql(rdef, groupmap): yield rql, args +_IGNORED_PROPS = ['eid', 'constraints', 'uid', 'infered', 'permissions'] + def _rdef_values(rdef): amap = {'order': 'ordernum', 'default': 'defaultval'} values = {} extra = {} for prop in rdef.rproperty_defs(rdef.object): - if prop in ('eid', 'constraints', 'uid', 'infered', 'permissions'): + if prop in _IGNORED_PROPS: continue value = getattr(rdef, prop) if prop not in KNOWN_RPROPERTIES: