DB Service is built using the Phoenix framework which is based on Elixir programming language. Before setting up this project, there are certain tools required to be installed on your machine.
Install the following packages using your favorite package manager. Links are provided for some
-
-
Once installed, verify the installations using:
elixir --version mix --version
-
-
-
Run the following steps to install Postgres on a Mac device
brew install postgresql brew services start postgresql
-
Once installed, verify the installations using
postgres --version
. You should be able to see:postgres (PostgreSQL) 14.9 (Homebrew)
-
For Postgres, this app defaults to
postgres
as both the username and password. This can be edited inconfig/dev.exs
file. -
Create a new database for the application called
dbservice_dev
. You can do this by running the command:createdb dbservice_dev
-
You can also use interactive postgres terminal
psql
. To open database, use:psql -d dbservice_dev
-
Log into the database created.
-
Open the Postgres CLI and check the enabled extensions:
SELECT * FROM pg_extension;
-
If the
uuid-ossp
module isn't showing up, then run the following command. We require this extension in order to support the Postgres'uuid_generate_v4
function that auto-generate UUIDs.CREATE EXTENSION "uuid-ossp";
-
For development, we recommend using the following versions:
- Elixir: 1.14.2
- Erlang/OTP: 25
Follow the steps below to set up the repo for development
-
Clone the repository and change the working directory
git clone https://github.com/avantifellows/db-service.git cd db-service/
-
Start the Phoenix server:
- Install dependencies with
mix deps.get
- Create and migrate your database with
mix ecto.setup
- Start Phoenix endpoint with
mix phx.server
or inside IEx withiex -S mix phx.server
- Install dependencies with
-
Now you can visit
localhost:4000
from your browser. -
You can see Swagger docs at
http://localhost:4000/docs/swagger/index.html
. -
Please verify that
localhost
is part of whitelisted domains. If not, you can create a filedb-service/config/.env
and add the following lines to it:WHITELISTED_DOMAINS="localhost"
You can add data to local database by running sh ./fetch-data.sh
. This will fetch data from production/staging database and sync with your local database. Please ask repository owners for the following credentials:
production_db_name="xxx"
production_db_user="postgres"
production_db_password="xxx"
For enhanced development experience with Elixir, consider installing ElixirLS: Elixir support and debugger
from the Visual Studio Marketplace.
OTP Versions | Elixir Versions | Supports ElixirLS |
---|---|---|
any | <= 1.12 | No |
22 | 1.12 | Yes |
23 | 1.12 - 1.14 | Yes |
24 | 1.12 - 1.16 | Yes |
25 | 1.13.4 - 1.16 | Yes |
26.0.0 - 26.0.1 | any | No |
26.0.2 - 26.1.2 | 1.14.5 - 1.16 | *nix only |
>= 26.2.0 | 1.14.5 - 1.16 | Yes |
any | 1.15.5 | Yes |