Arca Dbutils is a set of simple database utilities for Elixir projects, focused on PostgreSQL database operations.
- Dump PostgreSQL databases to SQL files with timestamp and hostname
- Load SQL dumps into databases
- Support for both URL-style and individual parameter configuration
- Environment variable support
- Mix tasks for easy command-line usage
- Elixir ~> 1.18
- PostgreSQL client tools (
pg_dump
andpsql
commands must be available on PATH)
If available in Hex, the package can be installed
by adding arca_dbutils
to your list of dependencies in mix.exs
:
def deps do
[
{:arca_dbutils, "~> 0.1.0"}
]
end
Via mix task:
# Using individual parameters
mix arca.dbutils.dump host=localhost user=postgres password=secret dbname=my_db
# Using a database URL
mix arca.dbutils.dump url=postgres://postgres:secret@localhost/my_db
Programmatically:
# Using individual parameters
Arca.Dbutils.Dumper.dump(host: "localhost", user: "postgres", password: "secret", dbname: "my_db")
# Using a database URL
Arca.Dbutils.Dumper.dump(url: "postgres://postgres:secret@localhost/my_db")
Via mix task:
# Using individual parameters
mix arca.dbutils.load file=dump.sql host=localhost user=postgres password=secret dbname=my_db
# Using a database URL
mix arca.dbutils.load file=dump.sql url=postgres://postgres:secret@localhost/my_db
Programmatically:
# Using individual parameters
Arca.Dbutils.Dumper.load(file: "dump.sql", host: "localhost", user: "postgres", password: "secret", dbname: "my_db")
# Using a database URL
Arca.Dbutils.Dumper.load(file: "dump.sql", url: "postgres://postgres:secret@localhost/my_db")
You can also use environment variables:
DB_URL
- Full database URLDB_HOST
- Database hostDB_USER
- Database usernameDB_PASSWORD
- Database passwordDB_NAME
- Database nameDB_FILE
- SQL file path (for load operations)
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/arca_dbutils.