Add a function to backfill missing derivation source file nars

If the file exists in the local store, then read it and add an entry to the
derivation_source_file_nars table. This will help to fill in the missing
entries, as currently entries are only added when the derivation source file
isn't in the database when the load new revision job runs.
This commit is contained in:
Christopher Baines 2019-12-30 11:26:23 +00:00
parent 57ee3c8988
commit 7881eec315

View file

@ -1045,6 +1045,33 @@ INSERT INTO derivation_source_file_nars (
(number->string uncompressed-size)
(string-append "\\x" data-string))))))
(define (backfill-derivation-source-file-nars conn)
(define (missing-batch)
(exec-query
conn
"
SELECT id, store_path
FROM derivation_source_files
WHERE id NOT IN (
SELECT derivation_source_file_id FROM derivation_source_file_nars
)
LIMIT 1000"))
(let loop ((batch (missing-batch)))
(unless (null? batch)
(for-each
(match-lambda
((id source-file)
(if (file-exists? source-file)
(begin
(insert-derivation-source-file-nar conn
(string->number id)
source-file)
(simple-format #t "inserting ~A\n" source-file))
(simple-format #t "missing ~A\n" source-file))))
batch)
(loop (missing-batch)))))
(define (insert-missing-derivations conn
derivation-ids-hash-table
derivations)