From c8e138ef68331df47a815954a48f25628113e124 Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Fri, 1 Dec 2023 11:00:43 -0700 Subject: [PATCH] Use `db` for local database instance. --- .gitignore | 2 +- README.md | 26 ++++++++++++++------------ flake.nix | 9 ++------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index f78c443..58f28a5 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,7 @@ npm-debug.log /assets/node_modules/ # The default location of the generated database cluster. -/data/ +/db/ # Directory used by `direnv` to hold `use flake`-generated profiles. /.direnv/ diff --git a/README.md b/README.md index 55a91c3..b3c7a2a 100644 --- a/README.md +++ b/README.md @@ -5,33 +5,35 @@ This is a template for constructing a environment for Elixir development (version 1.7.10) framework. [direnv](https://direnv.net/) can be used to launch a dev shell upon entering this directory (refer to `.envrc`). Otherwise run via: ```bash -$> nix develop +$ nix develop ``` ## Quickstart -An empty Postgres cluster is initialized at `/data`. To start the database, run +An empty Postgres cluster is initialized at `/db`. To start the database, run the following: ```bash -$> pg_ctl start -o --unix_socket_directories="$PWD/data" +$ pg_ctl -D db -l db/logfile -o --unix_socket_directories=@boardwise start ``` -To shut the database down, run: +In the above command, `@boardwise` refers to an [abstract socket name](https://www.postgresql.org/docs/15/runtime-config-connection.html#GUC-UNIX-SOCKET-DIRECTORIES). +Rename to whatever is appropriate for your use case. To then connect to this +database instance, run: ```bash -$> pg_ctl stop +$ psql -h @boardwise ``` -You can connect to this database from the project root directory by running: +To later shut the database down, run: ```bash -$> psql -h "$PWD/data" -d postgres +$ pg_ctl -D db stop ``` Afterward, you can run the Phoenix setup commands: ```bash -$> mix ecto.setup -$> mix assets.setup +$ mix ecto.setup +$ mix assets.setup ``` and then start the local server: ```bash -$> mix phx.server +$ mix phx.server ``` ## Dependencies @@ -39,7 +41,7 @@ $> mix phx.server This project pins Mix dependencies using [mix2nix](https://github.com/ydlr/mix2nix). After updating your `mix.lock` file, make sure to re-run the following: ```bash -mix2nix > deps.nix +$ mix2nix > deps.nix ``` As of now, `mix2nix` cannot handle git dependencies found inside the `mix.lock` file. If you have git dependencies, add them manually or use @@ -56,7 +58,7 @@ Formatting depends on the `mix format` task. A `pre-commit` hook is included in `.githooks` that can be used to format all `*.exs?` files prior to commit. Install via: ```bash -$> git config --local core.hooksPath .githooks/ +$ git config --local core.hooksPath .githooks/ ``` If running [direnv](https://direnv.net/), this hook is installed automatically when entering the directory. diff --git a/flake.nix b/flake.nix index 8e981b6..50862e8 100644 --- a/flake.nix +++ b/flake.nix @@ -1,10 +1,5 @@ { - description = '' - An opinionated pheonix flake. - - To generate a copy of this template elsewhere, run: - $> bootstrap phoenix - ''; + description = "The BoardWise backend/frontend."; inputs = { flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"; @@ -56,7 +51,7 @@ # environment variable whenever `-D` is not specified (for e.g. # `postgres` and `pg_ctl`). # https://www.postgresql.org/docs/15/server-start.html - export PGDATA="$PWD/data" + export PGDATA="$PWD/db" ''; }; });