def upgrade(ver, session): if ver is None: # Upgrade to version 0 was a failed attempt at cleaning bad entries from our table, better attempt in ver 1 ver = 0 if ver == 0: # Remove any values that are not loadable. table = table_schema('simple_persistence', session) for row in session.execute(select([table.c.id, table.c.plugin, table.c.key, table.c.value])): try: pickle.loads(row['value']) except Exception as e: log.warning('Couldn\'t load %s:%s removing from db: %s' % (row['plugin'], row['key'], e)) session.execute(table.delete().where(table.c.id == row['id'])) ver = 1 if ver == 1: log.info('Creating index on simple_persistence table.') create_index('simple_persistence', session, 'feed', 'plugin', 'key') ver = 2 if ver == 2 or ver == 3: table = table_schema('simple_persistence', session) table_add_column(table, 'json', Unicode, session) # Make sure we get the new schema with the added column table = table_schema('simple_persistence', session) for row in session.execute(select([table.c.id, table.c.value])): try: p = pickle.loads(row['value']) session.execute(table.update().where(table.c.id == row['id']).values( json=json.dumps(p, encode_datetime=True))) except KeyError as e: log.error('Unable error upgrading simple_persistence pickle object due to %s' % str(e)) ver = 4 return ver
def upgrade(ver, session): if ver < 2: # Creates the executions table index create_index('status_execution', session, 'task_id', 'start', 'end', 'succeeded') ver = 2 return ver
def upgrade(ver, session): if ver is None: # Upgrade to version 0 was a failed attempt at cleaning bad entries from our table, better attempt in ver 1 ver = 0 if ver == 0: # Remove any values that are not loadable. table = table_schema('simple_persistence', session) for row in session.execute(select([table.c.id, table.c.plugin, table.c.key, table.c.value])): try: pickle.loads(row['value']) except Exception as e: log.warning('Couldn\'t load %s:%s removing from db: %s' % (row['plugin'], row['key'], e)) session.execute(table.delete().where(table.c.id == row['id'])) ver = 1 if ver == 1: log.info('Creating index on simple_persistence table.') create_index('simple_persistence', session, 'feed', 'plugin', 'key') ver = 2 if ver == 2 or ver == 3: table = table_schema('simple_persistence', session) table_add_column(table, 'json', Unicode, session) # Make sure we get the new schema with the added column table = table_schema('simple_persistence', session) for row in session.execute(select([table.c.id, table.c.value])): p = pickle.loads(row['value']) session.execute(table.update().where(table.c.id == row['id']).values( json=json.dumps(p, encode_datetime=True))) ver = 4 return ver
def upgrade(ver, session): if ver is None: # Upgrade to version 0 was a failed attempt at cleaning bad entries from our table, better attempt in ver 1 ver = 0 if ver == 0: try: # Remove any values that are not loadable. table = table_schema('simple_persistence', session) for row in session.execute( select([ table.c.id, table.c.plugin, table.c.key, table.c.value ])): try: pickle.loads(row['value']) except Exception as e: logger.warning("Couldn't load {}:{} removing from db: {}", row['plugin'], row['key'], e) session.execute( table.delete().where(table.c.id == row['id'])) except Exception as e: logger.warning( "Couldn't upgrade the simple_persistence table. Commencing nuke. Error: {}", e) raise db_schema.UpgradeImpossible ver = 1 if ver == 1: logger.info('Creating index on simple_persistence table.') create_index('simple_persistence', session, 'feed', 'plugin', 'key') ver = 2 if ver == 2 or ver == 3: table = table_schema('simple_persistence', session) table_add_column(table, 'json', Unicode, session) # Make sure we get the new schema with the added column table = table_schema('simple_persistence', session) failures = 0 for row in session.execute(select([table.c.id, table.c.value])): try: p = pickle.loads(row['value']) session.execute( table.update().where(table.c.id == row['id']).values( json=json.dumps(p, encode_datetime=True))) except Exception as e: failures += 1 if failures > 0: logger.error( 'Error upgrading {} simple_persistence pickle objects. Some information has been lost.', failures, ) ver = 4 return ver
def upgrade(ver, session): if ver is None: # Upgrade to version 0 was a failed attempt at cleaning bad entries from our table, better attempt in ver 1 ver = 0 if ver == 0: # Remove any values that are not loadable. table = table_schema('simple_persistence', session) for row in session.execute(select([table.c.id, table.c.plugin, table.c.key, table.c.value])): try: p = pickle.loads(row['value']) except Exception as e: log.warning('Couldn\'t load %s:%s removing from db: %s' % (row['plugin'], row['key'], e)) session.execute(table.delete().where(table.c.id == row['id'])) ver = 1 if ver == 1: log.info('Creating index on simple_persistence table.') create_index('simple_persistence', session, 'feed', 'plugin', 'key') ver = 2 return ver
def upgrade(ver, session): if ver < 2: # Creates the executions table index create_index('status_execution', session, 'task_id', 'start', 'end', 'succeeded') ver = 2 return ver
if ver == 0: # Remove any values that are not loadable. table = table_schema('simple_persistence', session) for row in session.execute( select( [table.c.id, table.c.plugin, table.c.key, table.c.value])): try: p = pickle.loads(row['value']) except Exception, e: log.warning('Couldn\'t load %s:%s removing from db: %s' % (row['plugin'], row['key'], e)) session.execute(table.delete().where(table.c.id == row['id'])) ver = 1 if ver == 1: log.info('Creating index on simple_persistence table.') create_index('simple_persistence', session, 'feed', 'plugin', 'key') ver = 2 return ver class SimpleKeyValue(Base): """Declarative""" __tablename__ = 'simple_persistence' id = Column(Integer, primary_key=True) task = Column('feed', String) plugin = Column(String) key = Column(String) _value = Column('value', PickleType) value = safe_pickle_synonym('_value')
if ver is None: # Upgrade to version 0 was a failed attempt at cleaning bad entries from our table, better attempt in ver 1 ver = 0 if ver == 0: # Remove any values that are not loadable. table = table_schema('simple_persistence', session) for row in session.execute(select([table.c.id, table.c.plugin, table.c.key, table.c.value])): try: p = pickle.loads(row['value']) except Exception, e: log.warning('Couldn\'t load %s:%s removing from db: %s' % (row['plugin'], row['key'], e)) session.execute(table.delete().where(table.c.id == row['id'])) ver = 1 if ver == 1: log.info('Creating index on simple_persistence table.') create_index('simple_persistence', session, 'feed', 'plugin', 'key') ver = 2 return ver class SimpleKeyValue(Base): """Declarative""" __tablename__ = 'simple_persistence' id = Column(Integer, primary_key=True) task = Column('feed', String) plugin = Column(String) key = Column(String) _value = Column('value', PickleType) value = safe_pickle_synonym('_value')