diff --git a/specs/phoenix/runner b/specs/phoenix/runner index 9689d79..9d3a01a 100755 --- a/specs/phoenix/runner +++ b/specs/phoenix/runner @@ -68,6 +68,15 @@ sed -i "s//$APP/g" "$BUILD/flake.nix" # `$(whoami)`. Reflect this in the config. sed -i "s/username: \"postgres\"/username: \"$(whoami)\"/g" "$BUILD/config/dev.exs" +# Create a new database cluster. +nix develop "$BUILD" --command bash -c "pg_ctl initdb -D $BUILD/data" + +# Append an additional rule to `.gitignore` to ignore the database cluster. +cat <> "$BUILD"/.gitignore +# The default location of the generated database cluster. +/data/ +EOF + # ============================================================ # EPILOGUE # ============================================================ diff --git a/specs/phoenix/template/README.md b/specs/phoenix/template/README.md index 6ed16bc..02e2a22 100644 --- a/specs/phoenix/template/README.md +++ b/specs/phoenix/template/README.md @@ -10,12 +10,8 @@ $> nix develop ## Quickstart -To begin, create a new database: -```bash -$> pg_ctl initdb -``` -If the flake's default `devShell` is loaded, this will create a database cluster -at `$PWD/data`. To start the database, run the following: +An empty Postgres cluster is initialized at `/data`. To start the database, run +the following: ```bash $> pg_ctl start -o --unix_socket_directories="$PGDATA" ``` @@ -23,8 +19,10 @@ To shut the database down, run: ```bash $> pg_ctl stop ``` -You can also specify a different location for the database cluster using the -`-D` option in each of the above commands. +You can connect to this database from the project root directory by running: +```bash +$> psql -h "$PWD"/data -d postgres +``` Afterward, you can run the Phoenix setup commands: ```bash diff --git a/specs/postgres/runner b/specs/postgres/runner index b68eb88..069e294 100755 --- a/specs/postgres/runner +++ b/specs/postgres/runner @@ -42,6 +42,9 @@ trap cleanup EXIT # Copy template contents over to the intermediate build directory. cp -r template/* "$BUILD" +# Create a new database cluster. +nix develop "$BUILD" --command bash -c "pg_ctl initdb -D $BUILD/data" + # Explicitly set permissions on all copied files. find "$BUILD" -type f -execdir chmod 644 {} + diff --git a/specs/postgres/template/.gitignore b/specs/postgres/template/.gitignore index ff9b393..54fe298 100644 --- a/specs/postgres/template/.gitignore +++ b/specs/postgres/template/.gitignore @@ -1,2 +1,2 @@ -# The default location of a generated database cluster. +# The default location of the generated database cluster. /data/ diff --git a/specs/postgres/template/README.md b/specs/postgres/template/README.md index 0428032..c7887f3 100644 --- a/specs/postgres/template/README.md +++ b/specs/postgres/template/README.md @@ -10,12 +10,8 @@ $> nix develop ## Quickstart -To begin, create a new database: -```bash -$> pg_ctl initdb -``` -If the flake's default `devShell` is loaded, this will create a database cluster -at `$PWD/data`. To start the database, run the following: +An empty Postgres cluster is initialized at `/data`. To start the database, run +the following: ```bash $> pg_ctl start -o --unix_socket_directories="$PGDATA" ``` @@ -23,5 +19,7 @@ To shut the database down, run: ```bash $> pg_ctl stop ``` -You can also specify a different location for the database cluster using the -`-D` option in each of the above commands. +You can connect to this database from the project root directory by running: +```bash +$> psql -h "$PWD"/data -d postgres +```