From 4229c5953c7953e67519729cea0b4834c8a4a601 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Tue, 15 Oct 2024 17:19:27 +0100 Subject: [PATCH] Add mix task to vacuum the production database --- lib/mix/tasks/music_library/prod/db_vacuum.ex | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 lib/mix/tasks/music_library/prod/db_vacuum.ex diff --git a/lib/mix/tasks/music_library/prod/db_vacuum.ex b/lib/mix/tasks/music_library/prod/db_vacuum.ex new file mode 100644 index 00000000..4c385a13 --- /dev/null +++ b/lib/mix/tasks/music_library/prod/db_vacuum.ex @@ -0,0 +1,19 @@ +defmodule Mix.Tasks.MusicLibrary.Prod.DbVacuum do + use Mix.Task + @shortdoc "Force VACUUM the production database" + @moduledoc """ + Force VACUUM the production database. This is necessary to make sure that all + changes currently in the WAL are persisted to the sqlite database file. + + Requires the `flyctl` CLI to be installed and authenticated. + """ + + @impl Mix.Task + def run(_args) do + IO.puts("Running VACUUM on the production database") + + command = ~s(bin/music_library rpc 'MusicLibrary.Repo.query\("VACUUM"\)') + + System.cmd("flyctl", ["ssh", "console", "--command", command], into: IO.stream()) + end +end