From 2d251f7bf9a370f1f5c9f2774639349eb9dc3871 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Wed, 14 Oct 2020 14:24:09 +0200 Subject: DB: Vacuum database after schema migrations Migrations may remove data and it doesn't hurt to vacuum afterwards to reduce the file size. Signed-off-by: Florian Pritz --- lib/App/BorgRestore/DB.pm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/App/BorgRestore/DB.pm b/lib/App/BorgRestore/DB.pm index 3d1d6ad..6fb8c7c 100644 --- a/lib/App/BorgRestore/DB.pm +++ b/lib/App/BorgRestore/DB.pm @@ -96,6 +96,7 @@ method _migrate() { $self->{dbh}->do('delete from `files`'); }, }; + my $ran_migrations = 0; for my $target_version (sort { $a <=> $b } keys %$schema) { if ($version < $target_version) { @@ -105,8 +106,13 @@ method _migrate() { $self->_set_db_version($target_version); $self->{dbh}->commit(); $log->debugf("Schema upgrade to version %s complete", $target_version); + $ran_migrations = 1; } } + if ($ran_migrations) { + $log->debug("Vacuuming database"); + $self->{dbh}->do("vacuum"); + } } method _get_db_version() { -- cgit v1.2.3-24-g4f1b