From 82f9371c714f14ca59efb8d67b20e9c85b5c86d1 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 17 Jun 2024 14:12:53 +0100 Subject: Strip the database dump Of data in tables where the data shouldn't be copied automatically to mirrors. --- nar-herder/database.scm | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/nar-herder/database.scm b/nar-herder/database.scm index a8a043c..e170d64 100644 --- a/nar-herder/database.scm +++ b/nar-herder/database.scm @@ -111,8 +111,6 @@ CREATE TABLE narinfos ( added_at TEXT ); -CREATE UNIQUE INDEX narinfos_store_hash ON narinfos (substr(store_path, 12, 32)); - CREATE TABLE narinfo_files ( narinfo_id INTEGER NOT NULL REFERENCES narinfos (id), size INTEGER NOT NULL, @@ -120,9 +118,6 @@ CREATE TABLE narinfo_files ( url TEXT NOT NULL ); -CREATE INDEX narinfo_files_narinfo_id ON narinfo_files (narinfo_id); -CREATE INDEX narinfo_files_url ON narinfo_files (url); - CREATE TABLE narinfo_references ( narinfo_id INTEGER NOT NULL REFERENCES narinfos (id), store_path TEXT NOT NULL @@ -134,8 +129,6 @@ CREATE TABLE tags ( value TEXT NOT NULL ); -CREATE UNIQUE INDEX tags_index ON tags (key, value); - CREATE TABLE narinfo_tags ( narinfo_id INTEGER NOT NULL REFERENCES narinfos (id), tag_id INTEGER NOT NULL REFERENCES tags (id) @@ -155,9 +148,6 @@ CREATE TABLE cached_narinfo_files ( compression TEXT ); -CREATE INDEX cached_narinfo_files_narinfo_id - ON cached_narinfo_files (narinfo_id); - CREATE TABLE scheduled_narinfo_removal ( narinfo_id INTEGER PRIMARY KEY ASC REFERENCES narinfos (id), removal_datetime TEXT NOT NULL @@ -217,10 +207,7 @@ CREATE TABLE cached_narinfo_files ( narinfo_id INTEGER NOT NULL REFERENCES narinfos (id), size INTEGER NOT NULL, compression TEXT NOT NULL -); - -CREATE INDEX cached_narinfo_files_narinfo_id - ON cached_narinfo_files (narinfo_id);")) +);")) (unless (column-exists? db "narinfos" "added_at") (sqlite-exec @@ -245,6 +232,22 @@ CREATE TABLE scheduled_cached_narinfo_removal ( removal_datetime TEXT NOT NULL );")) + (sqlite-exec + db + " +CREATE UNIQUE INDEX IF NOT EXISTS + narinfos_store_hash ON narinfos (substr(store_path, 12, 32));") + + (sqlite-exec + db + "CREATE UNIQUE INDEX IF NOT EXISTS + tags_index ON tags (key, value);") + + (sqlite-exec + db + "CREATE INDEX IF NOT EXISTS cached_narinfo_files_narinfo_id + ON cached_narinfo_files (narinfo_id);") + (sqlite-exec db "CREATE INDEX IF NOT EXISTS narinfo_tags_narinfo_id @@ -583,12 +586,25 @@ PRAGMA optimize;"))) (apply values vals)))) (define (dump-database database name) + (define (strip-db name) + (let ((db (db-open name))) + (let ((tables-to-clear + '("cached_narinfo_files"))) + (for-each + (lambda (table) + (sqlite-exec db (simple-format #f "DELETE FROM ~A;" table))) + tables-to-clear)) + + (sqlite-close db))) + (call-with-worker-thread (database-reader-thread-channel database) (lambda (db) (sqlite-exec db - (string-append "VACUUM INTO '" name "';"))))) + (string-append "VACUUM INTO '" name "';")) + + (strip-db name)))) (define (last-insert-rowid db) (let ((statement -- cgit v1.2.3