'Merge items into the container table.
:param item_list: list of dictionaries of {\'name\', \'put_timestamp\',
\'delete_timestamp\', \'object_count\', \'bytes_used\',
\'deleted\', \'storage_policy_index\'}
:param source: if defined, update incoming_sync with the source'

def merge_items(self, item_list, source=None):

    def _really_merge_items(conn):
        max_rowid = (-1)
        curs = conn.cursor()
        for rec in item_list:
            rec.setdefault('storage_policy_index', 0)
            record = [rec['name'], rec['put_timestamp'], rec['delete_timestamp'], rec['object_count'], rec['bytes_used'], rec['deleted'], rec['storage_policy_index']]
            query = '\n                                                                                SELECT    name,    put_timestamp,    delete_timestamp,\n                                                                                                            object_count,    bytes_used,    deleted,\n                                                                                                            storage_policy_index\n                                                                                FROM    container    WHERE    name    =    ?\n                                                                '
            if (self.get_db_version(conn) >= 1):
                query += '    AND    deleted    IN    (0,    1)'
            curs_row = curs.execute(query, (rec['name'],))
            curs_row.row_factory = None
            row = curs_row.fetchone()
            if row:
                row = list(row)
                for i in range(5):
                    if ((record[i] is None) and (row[i] is not None)):
                        record[i] = row[i]
                if (Timestamp(row[1]) > Timestamp(record[1])):
                    record[1] = row[1]
                if (Timestamp(row[2]) > Timestamp(record[2])):
                    record[2] = row[2]
                if ((Timestamp(record[2]) > Timestamp(record[1])) and (record[3] in (None, '', 0, '0'))):
                    record[5] = 1
                else:
                    record[5] = 0
            curs.execute('\n                                                                                DELETE    FROM    container    WHERE    name    =    ?    AND\n                                                                                                                                                                                                deleted    IN    (0,    1)\n                                                                ', (record[0],))
            curs.execute('\n                                                                                INSERT    INTO    container    (name,    put_timestamp,\n                                                                                                delete_timestamp,    object_count,    bytes_used,\n                                                                                                deleted,    storage_policy_index)\n                                                                                VALUES    (?,    ?,    ?,    ?,    ?,    ?,    ?)\n                                                                ', record)
            if source:
                max_rowid = max(max_rowid, rec['ROWID'])
        if source:
            try:
                curs.execute('\n                                                                                                INSERT    INTO    incoming_sync    (sync_point,    remote_id)\n                                                                                                VALUES    (?,    ?)\n                                                                                ', (max_rowid, source))
            except sqlite3.IntegrityError:
                curs.execute('\n                                                                                                UPDATE    incoming_sync\n                                                                                                SET    sync_point=max(?,    sync_point)\n                                                                                                WHERE    remote_id=?\n                                                                                ', (max_rowid, source))
        conn.commit()
    with self.get() as conn:
        try:
            _really_merge_items(conn)
        except sqlite3.OperationalError as err:
            if ('no    such    column:    storage_policy_index' not in str(err)):
                raise
            self._migrate_add_storage_policy_index(conn)
            _really_merge_items(conn)
