Remove/replace fly-dependent tasks

This commit is contained in:
Claudio Ortolina
2025-08-25 13:34:05 +03:00
parent 7656945fe8
commit 7ac858fe82
7 changed files with 8 additions and 129 deletions
@@ -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
@@ -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
@@ -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
@@ -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
-17
View File
@@ -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