19 |
19 |
20 - synchronize the living schema object with the persistent schema |
20 - synchronize the living schema object with the persistent schema |
21 - perform physical update on the source when necessary |
21 - perform physical update on the source when necessary |
22 |
22 |
23 checking for schema consistency is done in hooks.py |
23 checking for schema consistency is done in hooks.py |
24 |
|
25 """ |
24 """ |
|
25 |
26 __docformat__ = "restructuredtext en" |
26 __docformat__ = "restructuredtext en" |
27 |
27 |
28 from copy import copy |
28 from copy import copy |
29 from yams.schema import BASE_TYPES, RelationSchema, RelationDefinitionSchema |
29 from yams.schema import BASE_TYPES, RelationSchema, RelationDefinitionSchema |
30 from yams import buildobjs as ybo, schema2sql as y2sql |
30 from yams import buildobjs as ybo, schema2sql as y2sql |
281 for etype in rschema.subjects(): |
281 for etype in rschema.subjects(): |
282 table = SQL_PREFIX + str(etype) |
282 table = SQL_PREFIX + str(etype) |
283 sqlexec('INSERT INTO %s_relation SELECT %s, %s FROM %s WHERE NOT %s IS NULL' |
283 sqlexec('INSERT INTO %s_relation SELECT %s, %s FROM %s WHERE NOT %s IS NULL' |
284 % (rtype, eidcolumn, column, table, column)) |
284 % (rtype, eidcolumn, column, table, column)) |
285 # drop existant columns |
285 # drop existant columns |
286 for etype in rschema.subjects(): |
286 if session.repo.system_source.dbhelper.alter_column_support: |
287 DropColumn(session, table=SQL_PREFIX + str(etype), |
287 for etype in rschema.subjects(): |
288 column=SQL_PREFIX + rtype) |
288 DropColumn(session, table=SQL_PREFIX + str(etype), |
|
289 column=SQL_PREFIX + rtype) |
289 else: |
290 else: |
290 for etype in rschema.subjects(): |
291 for etype in rschema.subjects(): |
291 try: |
292 try: |
292 add_inline_relation_column(session, str(etype), rtype) |
293 add_inline_relation_column(session, str(etype), rtype) |
293 except Exception, ex: |
294 except Exception, ex: |
1009 'R eid %%(x)s, X from_entity E, E name %%(name)s' |
1010 'R eid %%(x)s, X from_entity E, E name %%(name)s' |
1010 % rdeftype, {'x': self.eidto, 'name': str(subjschema)}) |
1011 % rdeftype, {'x': self.eidto, 'name': str(subjschema)}) |
1011 if rset[0][0] == 0 and not subjschema.eid in pendings: |
1012 if rset[0][0] == 0 and not subjschema.eid in pendings: |
1012 ptypes = session.transaction_data.setdefault('pendingrtypes', set()) |
1013 ptypes = session.transaction_data.setdefault('pendingrtypes', set()) |
1013 ptypes.add(rschema.type) |
1014 ptypes.add(rschema.type) |
1014 DropColumn(session, table=SQL_PREFIX + subjschema.type, |
1015 if session.repo.system_source.dbhelper.alter_column_support: |
1015 column=SQL_PREFIX + rschema.type) |
1016 DropColumn(session, table=SQL_PREFIX + subjschema.type, |
|
1017 column=SQL_PREFIX + rschema.type) |
1016 elif lastrel: |
1018 elif lastrel: |
1017 DropRelationTable(session, rschema.type) |
1019 DropRelationTable(session, rschema.type) |
1018 # if this is the last instance, drop associated relation type |
1020 # if this is the last instance, drop associated relation type |
1019 if lastrel and not self.eidto in pendings: |
1021 if lastrel and not self.eidto in pendings: |
1020 execute('DELETE CWRType X WHERE X eid %(x)s', {'x': self.eidto}) |
1022 execute('DELETE CWRType X WHERE X eid %(x)s', {'x': self.eidto}) |