100 # create index before alter table which may expectingly fail during test |
100 # create index before alter table which may expectingly fail during test |
101 # (sqlite) while index creation should never fail (test for index existence |
101 # (sqlite) while index creation should never fail (test for index existence |
102 # is done by the dbhelper) |
102 # is done by the dbhelper) |
103 session.pool.source('system').create_index(session, table, column) |
103 session.pool.source('system').create_index(session, table, column) |
104 session.info('added index on %s(%s)', table, column) |
104 session.info('added index on %s(%s)', table, column) |
|
105 |
|
106 |
|
107 def insert_rdef_on_subclasses(session, eschema, rschema, rdefdef, props): |
|
108 # XXX 'infered': True/False, not clear actually |
|
109 props.update({'constraints': rdefdef.constraints, |
|
110 'description': rdefdef.description, |
|
111 'cardinality': rdefdef.cardinality, |
|
112 'permissions': rdefdef.get_permissions(), |
|
113 'order': rdefdef.order, |
|
114 'infered': False, 'eid': None |
|
115 }) |
|
116 cstrtypemap = ss.cstrtype_mapping(session) |
|
117 groupmap = group_mapping(session) |
|
118 object = rschema.schema.eschema(rdefdef.object) |
|
119 for specialization in eschema.specialized_by(False): |
|
120 if (specialization, rdefdef.object) in rschema.rdefs: |
|
121 continue |
|
122 print 'adding infered', specialization, rschema.type, object |
|
123 sperdef = RelationDefinitionSchema(specialization, rschema, |
|
124 object, props) |
|
125 ss.execschemarql(session.execute, sperdef, |
|
126 ss.rdef2rql(sperdef, cstrtypemap, groupmap)) |
105 |
127 |
106 |
128 |
107 def check_valid_changes(session, entity, ro_attrs=('name', 'final')): |
129 def check_valid_changes(session, entity, ro_attrs=('name', 'final')): |
108 errors = {} |
130 errors = {} |
109 # don't use getattr(entity, attr), we would get the modified value if any |
131 # don't use getattr(entity, attr), we would get the modified value if any |
452 # propagate attribute to children classes |
474 # propagate attribute to children classes |
453 rschema = schema.rschema(rdefdef.name) |
475 rschema = schema.rschema(rdefdef.name) |
454 # if relation type has been inserted in the same transaction, its final |
476 # if relation type has been inserted in the same transaction, its final |
455 # attribute is still set to False, so we've to ensure it's False |
477 # attribute is still set to False, so we've to ensure it's False |
456 rschema.final = True |
478 rschema.final = True |
457 # XXX 'infered': True/False, not clear actually |
479 insert_rdef_on_subclasses(session, eschema, rschema, rdefdef, props) |
458 props.update({'constraints': rdefdef.constraints, |
|
459 'description': rdefdef.description, |
|
460 'cardinality': rdefdef.cardinality, |
|
461 'constraints': rdefdef.constraints, |
|
462 'permissions': rdefdef.get_permissions(), |
|
463 'order': rdefdef.order, |
|
464 'infered': False, 'eid': None |
|
465 }) |
|
466 cstrtypemap = ss.cstrtype_mapping(session) |
|
467 groupmap = group_mapping(session) |
|
468 object = schema.eschema(rdefdef.object) |
|
469 for specialization in eschema.specialized_by(False): |
|
470 if (specialization, rdefdef.object) in rschema.rdefs: |
|
471 continue |
|
472 sperdef = RelationDefinitionSchema(specialization, rschema, |
|
473 object, props) |
|
474 ss.execschemarql(session.execute, sperdef, |
|
475 ss.rdef2rql(sperdef, cstrtypemap, groupmap)) |
|
476 # set default value, using sql for performance and to avoid |
480 # set default value, using sql for performance and to avoid |
477 # modification_date update |
481 # modification_date update |
478 if default: |
482 if default: |
479 session.system_sql('UPDATE %s SET %s=%%(default)s' % (table, column), |
483 session.system_sql('UPDATE %s SET %s=%%(default)s' % (table, column), |
480 {'default': default}) |
484 {'default': default}) |
512 if rschema.inlined: |
516 if rschema.inlined: |
513 # need to add a column if the relation is inlined and if this is the |
517 # need to add a column if the relation is inlined and if this is the |
514 # first occurence of "Subject relation Something" whatever Something |
518 # first occurence of "Subject relation Something" whatever Something |
515 if len(rschema.objects(rdefdef.subject)) == 1: |
519 if len(rschema.objects(rdefdef.subject)) == 1: |
516 add_inline_relation_column(session, rdefdef.subject, rtype) |
520 add_inline_relation_column(session, rdefdef.subject, rtype) |
|
521 eschema = schema[rdefdef.subject] |
|
522 insert_rdef_on_subclasses(session, eschema, rschema, rdefdef, |
|
523 {'composite': entity.composite}) |
517 else: |
524 else: |
518 # need to create the relation if no relation definition in the |
525 # need to create the relation if no relation definition in the |
519 # schema and if it has not been added during other event of the same |
526 # schema and if it has not been added during other event of the same |
520 # transaction |
527 # transaction |
521 if not (len(rschema.rdefs) > 1 or |
528 if not (len(rschema.rdefs) > 1 or |