This is only a partial answer, but it may be helpful. I've also recently had to deal with the document_id problem in Strapi v5, but I didn't use knex.js, nor do I know anything about knex.js. So at the risk of being completely irrelevant:
I populated my tables by running an SQL file, so for document_id I just generated a random string. I saw that Strapi generates a 24-character document_id and seemed to use numbers and only lower-case letters -- criteria that may not be actually necessary, but I went with it. I was using the default sqlite database, which has limited string functions, but here's one way to get there: lower(hex(randomblob(12)))
If you're using MySQL you could use substring(md5(rand()),1,24)
These are not the most random of all random strings, so it would probably be advisable to add checks for uniqueness. But this works. You get a happy Strapi that recognizes your entries and can play nicely with them.