def clean_database(self, delete_folders=True): """ Deletes data from all tables """ self.cancel_all_operations() LOGGER.warning("Your Database content will be deleted.") try: session = SessionMaker() for table in reversed(model.Base.metadata.sorted_tables): # We don't delete data from some tables, because those are # imported only during introspection which is done one time if table.name not in self.EXCLUDE_TABLES: try: session.open_session() con = session.connection() LOGGER.debug("Executing Delete From Table " + table.name) con.execute(table.delete()) session.commit() except Exception, e: # We cache exception here, in case some table does not exists and # to allow the others to be deleted LOGGER.warning(e) session.rollback() finally: session.close_session()
def clean_database(self, delete_folders=True): """ Deletes data from all tables """ self.cancel_all_operations() LOGGER.warning("Your Database content will be deleted.") try: session = SessionMaker() for table in reversed(model.Base.metadata.sorted_tables): # We don't delete data from some tables, because those are # imported only during introspection which is done one time if table.name not in self.EXCLUDE_TABLES: try: session.open_session() con = session.connection() LOGGER.debug("Executing Delete From Table " + table.name) con.execute(table.delete()) session.commit() except Exception as e: # We cache exception here, in case some table does not exists and # to allow the others to be deleted LOGGER.warning(e) session.rollback() finally: session.close_session() LOGGER.info("Database was cleanup!") except Exception as excep: LOGGER.warning(excep) raise # Now if the database is clean we can delete also project folders on disk if delete_folders: self.delete_project_folders() dao.store_entity(model.User(TvbProfile.current.web.admin.SYSTEM_USER_NAME, None, None, True, None))