loadit/database.py
def restore(self, batch_name):
        """
        Restore database to a previous batch. This operation is not reversible.

        Parameters
        ----------
        batch_name : str
            Batch name.
        """
        restore_points = [batch[0] for batch in self.header.batches]

        if batch_name not in restore_points:
            raise ValueError(f"'{batch_name}' is not a valid restore point")

        log.info(f"Restoring database to '{batch_name}'...")
        self._close()
        batch_index = 0

        for name, header in self.header.tables.items():

            try:
                index = [batch_name for batch_name, _, _ in header['batches']].index(batch_name)
                batch_index = max(batch_index, index)
                header['batches'] = header['batches'][:index + 1]
                position = header['batches'][index][1]
                header['LIDs'] = header['LIDs'][:position]

                truncate_file(os.path.join(self.path, name, 'LID.bin'),
                              position * np.dtype(header['columns'][0][1]).itemsize)

                for field, dtype in header['columns'][2:]:
                    truncate_file(os.path.join(self.path, name, field + '.bin'),
                                  position * np.dtype(dtype).itemsize * len(header['IDs']))

                header['path'] = os.path.join(self.path, name)

            except ValueError:
                del self.tables[name]
                shutil.rmtree(os.path.join(self.path, name))

        batch_hash_old = self.header.batches[batch_index][1]
        assembly_database(self.path, {name: self.header.tables[name] for name in self.tables},
                          self.header.batches[:batch_index + 1], self.max_memory,
                          self.header.hash_function, self.header.attachments)
        self.load()

        if self.header.batches[-1][1] != batch_hash_old:
            raise ValueError('Database header is corrupted!')

        log.info(f"Database restored to '{batch_name}'")

        Restore database to a previous batch. This operation is not reversible.

        Parameters
        ----------
        batch_name : str
            Batch name.
        
Restore database to a previous batch. This operation is not reversible.
Parameters

batch_name : str
Batch name.
Restore database to a previous batch . This operation is not reversible . Parameters batch_name : str Batch name .
def restore(self, batch_name):
        restore_points = [batch[0] for batch in self.header.batches]
        if batch_name not in restore_points:
            raise ValueError(f"'{batch_name}' is not a valid restore point")
        log.info(f"Restoring database to '{batch_name}'...")
        self._close()
        batch_index = 0
        for name, header in self.header.tables.items():
            try:
                index = [batch_name for batch_name, _, _ in header['batches']].index(batch_name)
                batch_index = max(batch_index, index)
                header['batches'] = header['batches'][:index + 1]
                position = header['batches'][index][1]
                header['LIDs'] = header['LIDs'][:position]
                truncate_file(os.path.join(self.path, name, 'LID.bin'),
                              position * np.dtype(header['columns'][0][1]).itemsize)
                for field, dtype in header['columns'][2:]:
                    truncate_file(os.path.join(self.path, name, field + '.bin'),
                                  position * np.dtype(dtype).itemsize * len(header['IDs']))
                header['path'] = os.path.join(self.path, name)
            except ValueError:
                del self.tables[name]
                shutil.rmtree(os.path.join(self.path, name))
        batch_hash_old = self.header.batches[batch_index][1]
        assembly_database(self.path, {name: self.header.tables[name] for name in self.tables},
                          self.header.batches[:batch_index + 1], self.max_memory,
                          self.header.hash_function, self.header.attachments)
        self.load()
        if self.header.batches[-1][1] != batch_hash_old:
            raise ValueError('Database header is corrupted!')
        log.info(f"Database restored to '{batch_name}'")
def restore ( self , batch_name ) : restore_points = [ batch [ 0 ] for batch in self . header . batches ] if batch_name not in restore_points : raise ValueError ( f"'{batch_name}' is not a valid restore point" ) log . info ( f"Restoring database to '{batch_name}'..." ) self . _close ( ) batch_index = 0 for name , header in self . header . tables . items ( ) : try : index = [ batch_name for batch_name , _ , _ in header [ 'batches' ] ] . index ( batch_name ) batch_index = max ( batch_index , index ) header [ 'batches' ] = header [ 'batches' ] [ : index + 1 ] position = header [ 'batches' ] [ index ] [ 1 ] header [ 'LIDs' ] = header [ 'LIDs' ] [ : position ] truncate_file ( os . path . join ( self . path , name , 'LID.bin' ) , position * np . dtype ( header [ 'columns' ] [ 0 ] [ 1 ] ) . itemsize ) for field , dtype in header [ 'columns' ] [ 2 : ] : truncate_file ( os . path . join ( self . path , name , field + '.bin' ) , position * np . dtype ( dtype ) . itemsize * len ( header [ 'IDs' ] ) ) header [ 'path' ] = os . path . join ( self . path , name ) except ValueError : del self . tables [ name ] shutil . rmtree ( os . path . join ( self . path , name ) ) batch_hash_old = self . header . batches [ batch_index ] [ 1 ] assembly_database ( self . path , { name : self . header . tables [ name ] for name in self . tables } , self . header . batches [ : batch_index + 1 ] , self . max_memory , self . header . hash_function , self . header . attachments ) self . load ( ) if self . header . batches [ - 1 ] [ 1 ] != batch_hash_old : raise ValueError ( 'Database header is corrupted!' ) log . info ( f"Database restored to '{batch_name}'" )
Restore database to a previous batch.
Restore database to a previous batch .
"""
        Restore database to a previous batch. This operation is not reversible.

        Parameters
        ----------
        batch_name : str
            Batch name.
        """
self
batch_name