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
+8 -7
View File
@@ -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?'
-5
View File
@@ -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