diff --git a/lib/mix/tasks/music_library/prod/db_migrate.ex b/lib/mix/tasks/music_library/prod/db_migrate.ex deleted file mode 100644 index 6ec8e2f6..00000000 --- a/lib/mix/tasks/music_library/prod/db_migrate.ex +++ /dev/null @@ -1,19 +0,0 @@ -defmodule Mix.Tasks.MusicLibrary.Prod.DbMigrate do - @shortdoc "Run migrations on the production database" - @moduledoc """ - Run migrations on the production database. - - Requires the `flyctl` CLI to be installed and authenticated. - """ - - use Mix.Task - - import Mix.Tasks.MusicLibrary.Prod.Helpers - - @impl Mix.Task - def run(_args) do - Mix.Shell.IO.info("==> Running migrations on production database") - - fly_ssh("bin/migrate") - end -end diff --git a/lib/mix/tasks/music_library/prod/db_pull.ex b/lib/mix/tasks/music_library/prod/db_pull.ex deleted file mode 100644 index 6cd692fa..00000000 --- a/lib/mix/tasks/music_library/prod/db_pull.ex +++ /dev/null @@ -1,36 +0,0 @@ -defmodule Mix.Tasks.MusicLibrary.Prod.DbPull do - @shortdoc "Pulls the latest database from the production server" - @moduledoc """ - Pulls the latest database from the production server. - - Requires the `flyctl` CLI to be installed and authenticated. - """ - use Mix.Task - - import Mix.Tasks.MusicLibrary.Prod.Helpers - - @impl Mix.Task - def run(_args) do - Mix.Shell.IO.info("==> Pulling the latest database from the production server") - - current_time = DateTime.utc_now() - remote_db = "/mnt/music_library/music_library_prod.db" - local_db = "data/music_library_prod_#{DateTime.to_unix(current_time)}.db" - - case fly_sftp_get(remote_db, local_db) do - {_stream, 1} -> - Mix.Shell.IO.error("Failed to pull the database") - System.halt(1) - - {_stream, 0} -> - Mix.Shell.IO.info("==> Database pulled successfully") - - Mix.Shell.IO.info("==> Restoring as local dev database") - - Path.wildcard("data/music_library_dev.db*") - |> Enum.each(&File.rm!/1) - - File.cp!(local_db, "data/music_library_dev.db") - end - end -end diff --git a/lib/mix/tasks/music_library/prod/db_vacuum.ex b/lib/mix/tasks/music_library/prod/db_vacuum.ex deleted file mode 100644 index 167be801..00000000 --- a/lib/mix/tasks/music_library/prod/db_vacuum.ex +++ /dev/null @@ -1,22 +0,0 @@ -defmodule Mix.Tasks.MusicLibrary.Prod.DbVacuum do - @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. - """ - - use Mix.Task - - import Mix.Tasks.MusicLibrary.Prod.Helpers - - @impl Mix.Task - def run(_args) do - Mix.Shell.IO.info("==> Running VACUUM on the production database") - - command = ~s(bin/music_library rpc 'MusicLibrary.Repo.vacuum\(\)') - - fly_ssh(command) - end -end diff --git a/lib/mix/tasks/music_library/prod/helpers.ex b/lib/mix/tasks/music_library/prod/helpers.ex deleted file mode 100644 index 62f8fce5..00000000 --- a/lib/mix/tasks/music_library/prod/helpers.ex +++ /dev/null @@ -1,23 +0,0 @@ -defmodule Mix.Tasks.MusicLibrary.Prod.Helpers do - def fly_ssh(command) do - if flyctl_installed?() do - System.cmd("flyctl", ["ssh", "console", "--command", command], into: IO.stream()) - else - Mix.Shell.IO.error("Please install flyctl first") - System.halt(1) - end - end - - def fly_sftp_get(remote_path, local_path) do - if flyctl_installed?() do - System.cmd("flyctl", ["ssh", "sftp", "get", remote_path, local_path], into: IO.stream()) - else - Mix.Shell.IO.error("Please install flyctl first") - System.halt(1) - end - end - - defp flyctl_installed? do - System.find_executable("flyctl") - end -end diff --git a/lib/mix/tasks/music_library/prod/ping.ex b/lib/mix/tasks/music_library/prod/ping.ex deleted file mode 100644 index b9773838..00000000 --- a/lib/mix/tasks/music_library/prod/ping.ex +++ /dev/null @@ -1,17 +0,0 @@ -defmodule Mix.Tasks.MusicLibrary.Prod.Ping do - @shortdoc "Ping the production instance" - @moduledoc """ - Ping the production instance - useful to wake it up if suspended. - """ - - use Mix.Task - - @impl Mix.Task - def run(_args) do - Application.ensure_all_started(:req) - Mix.Shell.IO.info("==> Pinging the production instance") - - response = Req.get!("https://music-library.claudio-ortolina.org/health") - if response.status !== 200, do: System.halt(1) - end -end diff --git a/mise.toml b/mise.toml index 68e31ee0..89828932 100644 --- a/mise.toml +++ b/mise.toml @@ -8,7 +8,6 @@ DBUI_URL = 'sqlite:data/music_library_dev.db' [tools] hurl = 'latest' -flyctl = 'latest' sqlite = 'latest' gh = 'latest' @@ -134,15 +133,17 @@ mix usage_rules.sync CLAUDE.md --all \ [tasks."prod:console"] description = 'Open an ssh console to the production env' -run = 'fly ssh console' - -[tasks."prod:migrate"] -description = 'Run migrations against production' -run = 'mix music_library.prod.db_migrate' +run = 'ssh music-library-prod' [tasks."prod:backup"] description = 'Backup the production database to the local development env' -run = 'mix music_library.prod.db_backup' +run = """ +current_date=$(date +%s) +dest_file="data/music_library_prod_$current_date.db" +scp music-library-prod:/data/coolify/applications/music-library/music_library_prod.db "$dest_file" +rm data/music_library_dev.db* +cp "$dest_file" data/music_library_dev.db +""" [tasks."prod:prune-backups"] confirm = 'Are you sure you want to delete all downloaded database backups?' diff --git a/mix.exs b/mix.exs index 5464e7c1..048497cf 100644 --- a/mix.exs +++ b/mix.exs @@ -139,11 +139,6 @@ defmodule MusicLibrary.MixProject do "tailwind music_library --minify", "esbuild music_library --minify", "phx.digest" - ], - "music_library.prod.db_backup": [ - "music_library.prod.ping", - "music_library.prod.db_vacuum", - "music_library.prod.db_pull" ] ] end