Initialize database clusters on bootstrap.

pull/10/head
Joshua Potter 2023-11-28 10:21:56 -07:00
parent 5e62a13543
commit 2cecfa42d1
5 changed files with 25 additions and 17 deletions

View File

@ -68,6 +68,15 @@ sed -i "s/<APP_NAME>/$APP/g" "$BUILD/flake.nix"
# `$(whoami)`. Reflect this in the config. # `$(whoami)`. Reflect this in the config.
sed -i "s/username: \"postgres\"/username: \"$(whoami)\"/g" "$BUILD/config/dev.exs" 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 <<EOF >> "$BUILD"/.gitignore
# The default location of the generated database cluster.
/data/
EOF
# ============================================================ # ============================================================
# EPILOGUE # EPILOGUE
# ============================================================ # ============================================================

View File

@ -10,12 +10,8 @@ $> nix develop
## Quickstart ## Quickstart
To begin, create a new database: An empty Postgres cluster is initialized at `/data`. To start the database, run
```bash the following:
$> 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:
```bash ```bash
$> pg_ctl start -o --unix_socket_directories="$PGDATA" $> pg_ctl start -o --unix_socket_directories="$PGDATA"
``` ```
@ -23,8 +19,10 @@ To shut the database down, run:
```bash ```bash
$> pg_ctl stop $> pg_ctl stop
``` ```
You can also specify a different location for the database cluster using the You can connect to this database from the project root directory by running:
`-D` option in each of the above commands. ```bash
$> psql -h "$PWD"/data -d postgres
```
Afterward, you can run the Phoenix setup commands: Afterward, you can run the Phoenix setup commands:
```bash ```bash

View File

@ -42,6 +42,9 @@ trap cleanup EXIT
# Copy template contents over to the intermediate build directory. # Copy template contents over to the intermediate build directory.
cp -r template/* "$BUILD" 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. # Explicitly set permissions on all copied files.
find "$BUILD" -type f -execdir chmod 644 {} + find "$BUILD" -type f -execdir chmod 644 {} +

View File

@ -1,2 +1,2 @@
# The default location of a generated database cluster. # The default location of the generated database cluster.
/data/ /data/

View File

@ -10,12 +10,8 @@ $> nix develop
## Quickstart ## Quickstart
To begin, create a new database: An empty Postgres cluster is initialized at `/data`. To start the database, run
```bash the following:
$> 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:
```bash ```bash
$> pg_ctl start -o --unix_socket_directories="$PGDATA" $> pg_ctl start -o --unix_socket_directories="$PGDATA"
``` ```
@ -23,5 +19,7 @@ To shut the database down, run:
```bash ```bash
$> pg_ctl stop $> pg_ctl stop
``` ```
You can also specify a different location for the database cluster using the You can connect to this database from the project root directory by running:
`-D` option in each of the above commands. ```bash
$> psql -h "$PWD"/data -d postgres
```