366 column=SQL_PREFIX + rtype) |
366 column=SQL_PREFIX + rtype) |
367 else: |
367 else: |
368 for etype in rschema.subjects(): |
368 for etype in rschema.subjects(): |
369 try: |
369 try: |
370 add_inline_relation_column(session, str(etype), rtype) |
370 add_inline_relation_column(session, str(etype), rtype) |
371 except Exception, ex: |
371 except Exception as ex: |
372 # the column probably already exists. this occurs when the |
372 # the column probably already exists. this occurs when the |
373 # entity's type has just been added or if the column has not |
373 # entity's type has just been added or if the column has not |
374 # been previously dropped (eg sqlite) |
374 # been previously dropped (eg sqlite) |
375 self.error('error while altering table %s: %s', etype, ex) |
375 self.error('error while altering table %s: %s', etype, ex) |
376 # copy existant data. |
376 # copy existant data. |
457 try: |
457 try: |
458 session.system_sql(str('ALTER TABLE %s ADD %s %s' |
458 session.system_sql(str('ALTER TABLE %s ADD %s %s' |
459 % (table, column, attrtype)), |
459 % (table, column, attrtype)), |
460 rollback_on_failure=False) |
460 rollback_on_failure=False) |
461 self.info('added column %s to table %s', table, column) |
461 self.info('added column %s to table %s', table, column) |
462 except Exception, ex: |
462 except Exception as ex: |
463 # the column probably already exists. this occurs when |
463 # the column probably already exists. this occurs when |
464 # the entity's type has just been added or if the column |
464 # the entity's type has just been added or if the column |
465 # has not been previously dropped |
465 # has not been previously dropped |
466 self.error('error while altering table %s: %s', table, ex) |
466 self.error('error while altering table %s: %s', table, ex) |
467 if extra_unique_index or entity.indexed: |
467 if extra_unique_index or entity.indexed: |
468 try: |
468 try: |
469 syssource.create_index(session, table, column, |
469 syssource.create_index(session, table, column, |
470 unique=extra_unique_index) |
470 unique=extra_unique_index) |
471 except Exception, ex: |
471 except Exception as ex: |
472 self.error('error while creating index for %s.%s: %s', |
472 self.error('error while creating index for %s.%s: %s', |
473 table, column, ex) |
473 table, column, ex) |
474 # final relations are not infered, propagate |
474 # final relations are not infered, propagate |
475 schema = session.vreg.schema |
475 schema = session.vreg.schema |
476 try: |
476 try: |
755 cols = ['%s%s' % (prefix, c) for c in self.cols] |
755 cols = ['%s%s' % (prefix, c) for c in self.cols] |
756 sqls = dbhelper.sqls_drop_multicol_unique_index(table, cols) |
756 sqls = dbhelper.sqls_drop_multicol_unique_index(table, cols) |
757 for sql in sqls: |
757 for sql in sqls: |
758 try: |
758 try: |
759 session.system_sql(sql) |
759 session.system_sql(sql) |
760 except Exception, exc: # should be ProgrammingError |
760 except Exception as exc: # should be ProgrammingError |
761 if sql.startswith('DROP'): |
761 if sql.startswith('DROP'): |
762 self.error('execute of `%s` failed (cause: %s)', sql, exc) |
762 self.error('execute of `%s` failed (cause: %s)', sql, exc) |
763 continue |
763 continue |
764 raise |
764 raise |
765 |
765 |