This guide provides comprehensive instructions for setting up your ex_pgflow development environment. Choose the method that best fits your workflow.
The easiest way to get started:
./scripts/setup-dev-environment.shThis interactive script will guide you through the setup process.
Benefits:
- All dependencies managed automatically (Elixir 1.19, Erlang, PostgreSQL 18, pgmq)
- Reproducible environment across all platforms
- Zero version conflicts
- Auto-starts PostgreSQL in dev shell
Prerequisites:
- None! The setup script will install Nix for you
Setup:
-
Run the setup script:
./scripts/setup-dev-environment.sh --method nix
-
Or manually install Nix with flakes support:
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
-
Enter the development shell:
nix develop
-
Alternatively, use direnv for automatic environment loading:
# Install direnv nix-env -iA nixpkgs.direnv # Add to your shell rc file (~/.bashrc, ~/.zshrc, etc.) eval "$(direnv hook bash)" # or zsh, fish, etc. # Allow direnv for this project direnv allow # Now the environment loads automatically when you cd into the directory!
What you get:
- Elixir 1.19.x
- Erlang/OTP 28
- PostgreSQL 18 with pgmq extension
- All build tools (mix, rebar3, etc.)
- PostgreSQL auto-starts and auto-stops with the shell
Benefits:
- Isolated PostgreSQL environment
- No PostgreSQL installation needed on host
- Easy to reset/clean
Prerequisites:
- Docker and docker-compose installed
- Elixir and Erlang installed separately (see Method 3)
Setup:
-
Start PostgreSQL with pgmq:
docker-compose up -d
-
Verify PostgreSQL is running:
docker-compose ps
-
Set database URL:
export DATABASE_URL="postgresql://postgres:postgres@localhost:5433/postgres"
-
Add to your shell rc file to persist:
echo 'export DATABASE_URL="postgresql://postgres:postgres@localhost:5433/postgres"' >> ~/.bashrc
Managing Docker:
# Start PostgreSQL
docker-compose up -d
# Stop PostgreSQL
docker-compose down
# View logs
docker-compose logs -f
# Reset database (delete all data)
docker-compose down -vNote: You still need to install Elixir and Erlang separately (see Method 3).
Benefits:
- No additional tools required
- Direct access to all components
- Full control over versions
Prerequisites:
- Package manager (apt, brew, dnf, etc.)
macOS (using Homebrew):
brew install elixirUbuntu/Debian:
# Add Erlang Solutions repository
wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb
sudo dpkg -i erlang-solutions_2.0_all.deb
sudo apt update
# Install Elixir and Erlang
sudo apt install elixir erlangUsing asdf (version manager - recommended for multiple projects):
# Install asdf
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0
# Add to your shell rc file
echo '. "$HOME/.asdf/asdf.sh"' >> ~/.bashrc
# Install plugins
asdf plugin add erlang
asdf plugin add elixir
# Install versions
asdf install erlang 27.0
asdf install elixir 1.17.0-otp-27
# Set versions for this project
asdf local erlang 27.0
asdf local elixir 1.17.0-otp-27macOS (using Homebrew):
brew install postgresql@18
brew services start postgresql@18Ubuntu/Debian:
sudo apt update
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresqlOption A: Using Docker image (easiest)
docker run -d --name pgmq-postgres \
-e POSTGRES_PASSWORD=postgres \
-p 5432:5432 \
ghcr.io/pgmq/pg18-pgmq:latestOption B: Build from source
git clone https://github.com/tembo-io/pgmq.git
cd pgmq
make installOption C: Using PGXN
pgxn install pgmq# Create database
createdb ex_pgflow
# Install pgmq extension
psql ex_pgflow -c "CREATE EXTENSION IF NOT EXISTS pgmq;"
# Set environment variable
export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/ex_pgflow"After choosing your installation method, run these steps:
mix deps.get# Create database (if not exists)
mix ecto.create
# Run migrations
mix ecto.migrate# Run tests
mix test
# Should see all tests passing# Format code
mix format
# Run linter
mix credo
# Type checking
mix dialyzer
# Security analysis
mix sobelowEnsure your environment is properly set up:
- Elixir installed (
elixir --versionshows 1.14+) - Mix available (
mix --version) - PostgreSQL running (
pg_isready -h localhost) - pgmq extension installed (check in psql:
\dx pgmq) - Database created (
psql ex_pgflow -c "SELECT 1") - Dependencies installed (
mix deps.getcompletes) - Tests pass (
mix testall green) - Code compiles (
mix compileno errors)
Solution:
# Check if Elixir is in PATH
which elixir
# If using Nix, ensure you're in the dev shell
nix develop
# If using asdf, ensure versions are set
asdf currentSolution:
# Check if PostgreSQL is running
pg_isready -h localhost
# Start PostgreSQL
# macOS: brew services start postgresql@18
# Linux: sudo systemctl start postgresql
# Check DATABASE_URL is set
echo $DATABASE_URL
# Test connection
psql $DATABASE_URL -c "SELECT 1"Error: ERROR: extension "pgmq" is not available
Solution:
# Option 1: Use Docker with pre-installed pgmq
docker run -d --name pgmq-postgres \
-e POSTGRES_PASSWORD=postgres \
-p 5432:5432 \
ghcr.io/pgmq/pg18-pgmq:latest
# Option 2: Install pgmq manually
# Follow instructions at: https://github.com/tembo-io/pgmq
# Option 3: Use Nix (includes everything)
nix developSolution:
# Clean build artifacts
mix deps.clean --all
mix clean
# Rebuild
mix deps.get
mix compileSolution:
# Dialyzer builds PLTs on first run (can take 10+ minutes)
# Subsequent runs are much faster
# Clean and rebuild PLTs if needed
rm -rf priv/plts
mix dialyzerSolution:
# Ensure PostgreSQL is running
pg_isready -h localhost
# Reset test database
MIX_ENV=test mix ecto.reset
# Run tests again
mix test
# Run tests with detailed output
mix test --traceKey environment variables for development:
# Database connection
export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/ex_pgflow"
# Test database (optional, defaults to ex_pgflow_test)
export TEST_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/ex_pgflow_test"
# Mix environment
export MIX_ENV=dev # or test, prod
# Elixir/Erlang paths (usually set automatically)
export ERL_AFLAGS="-kernel shell_history enabled"Recommended extensions:
{
"recommendations": [
"jakebecker.elixir-ls",
"pantajoe.vscode-elixir-credo",
"direnv.direnv"
]
}Use alchemist or lsp-mode with elixir-ls.
Use vim-elixir with coc-elixir or nvim-lspconfig with elixir-ls.
Once your environment is set up:
- Read GETTING_STARTED.md for your first workflow
- Review ARCHITECTURE.md for technical details
- Check CONTRIBUTING.md for development guidelines
- Start coding! 🚀
- Issues with setup? Open a GitHub issue with the "question" label
- Documentation unclear? Submit a PR with improvements
- Need help? Check existing issues or discussions
# Development workflow
mix test # Run tests
mix test.watch # Auto-run tests on file changes
mix quality # Run all quality checks
mix format # Format code
mix credo --strict # Lint code
mix dialyzer # Type check
mix docs # Generate documentation
# Database management
mix ecto.create # Create database
mix ecto.migrate # Run migrations
mix ecto.rollback # Rollback last migration
mix ecto.reset # Drop, create, and migrate
# Docker (if using docker-compose)
docker-compose up -d # Start PostgreSQL
docker-compose down # Stop PostgreSQL
docker-compose logs -f # View logs
# Nix (if using Nix)
nix develop # Enter dev shell
direnv allow # Allow auto-loading