equal
deleted
inserted
replaced
13 from decimal import Decimal |
13 from decimal import Decimal |
14 import yams |
14 import yams |
15 from cubicweb import Binary |
15 from cubicweb import Binary |
16 if default is None: |
16 if default is None: |
17 return |
17 return |
|
18 if isinstance(default, Binary): |
|
19 # partially migrated instance, try to be idempotent |
|
20 return default |
18 atype = cwattr.to_entity[0].name |
21 atype = cwattr.to_entity[0].name |
19 if atype == 'Boolean': |
22 if atype == 'Boolean': |
20 # boolean attributes with default=False were stored as '' |
23 # boolean attributes with default=False were stored as '' |
21 assert default in ('True', 'False', ''), repr(default) |
24 assert default in ('True', 'False', ''), repr(default) |
22 default = default == 'True' |
25 default = default == 'True' |
58 sql("sp_rename 'cw_cwattribute.new_defaultval', 'cw_defaultval', 'COLUMN'") |
61 sql("sp_rename 'cw_cwattribute.new_defaultval', 'cw_defaultval', 'COLUMN'") |
59 |
62 |
60 |
63 |
61 # Set object type to "Bytes" for CWAttribute's "defaultval" attribute |
64 # Set object type to "Bytes" for CWAttribute's "defaultval" attribute |
62 rql('SET X to_entity B WHERE X is CWAttribute, X from_entity Y, Y name "CWAttribute", ' |
65 rql('SET X to_entity B WHERE X is CWAttribute, X from_entity Y, Y name "CWAttribute", ' |
63 'X relation_type Z, Z name "defaultval", B name "Bytes"') |
66 'X relation_type Z, Z name "defaultval", B name "Bytes", NOT X to_entity B') |
64 |
67 |
65 from yams import buildobjs as ybo |
68 from yams import buildobjs as ybo |
66 schema.add_relation_def(ybo.RelationDefinition('CWAttribute', 'defaultval', 'Bytes')) |
69 schema.add_relation_def(ybo.RelationDefinition('CWAttribute', 'defaultval', 'Bytes')) |
67 schema.del_relation_def('CWAttribute', 'defaultval', 'String') |
70 schema.del_relation_def('CWAttribute', 'defaultval', 'String') |
68 |
71 |