diff --git a/docs/src/administration_configuration.md b/docs/src/administration_configuration.md index 600fc3d2..55f93f05 100644 --- a/docs/src/administration_configuration.md +++ b/docs/src/administration_configuration.md @@ -6,3 +6,12 @@ Additionally, you can override any config files with environment variables. Thes `LEMMY__DATABASE__POOL_SIZE=10`. An additional option `LEMMY_DATABASE_URL` is available, which can be used with a PostgreSQL connection string like `postgres://lemmy:password@lemmy_db:5432/lemmy`, passing all connection details at once. + +If the Docker container is not used, manually create the database specified above by running the following commands: + +```bash +# Start at the root of the Lemmy repository + +cd server +./db-init.sh +``` diff --git a/docs/src/contributing_local_development.md b/docs/src/contributing_local_development.md index c19bcba8..7d782925 100644 --- a/docs/src/contributing_local_development.md +++ b/docs/src/contributing_local_development.md @@ -7,9 +7,18 @@ #### Set up Postgres DB ```bash - psql -c "create user lemmy with password 'password' superuser;" -U postgres - psql -c 'create database lemmy with owner lemmy;' -U postgres - export LEMMY_DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy +# Start at the root of the Lemmy repository + +cd server +./db-init.sh +``` + +Or run the commands manually: + +```bash +psql -c "create user lemmy with password 'password' superuser;" -U postgres +psql -c 'create database lemmy with owner lemmy;' -U postgres +export LEMMY_DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy ``` #### Running diff --git a/server/db-init.sh b/server/db-init.sh new file mode 100644 index 00000000..c9150e9d --- /dev/null +++ b/server/db-init.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +username=lemmy +dbname=lemmy +port=5432 + +password="" +password_confirm="" +password_valid=0 + +while [ "$password_valid" == 0 ] +do + read -p "Enter database password: " -s password + echo + + read -p "Verify database password: " -s password_confirm + echo + echo + + # Start the loop from the top if either check fails + if [ -z "$password" ] + then + echo "Error: Password cannot be empty." 1>&2 + echo + continue + fi + if [ "$password" != "$password_confirm" ] + then + echo "Error: Passwords don't match." 1>&2 + echo + continue + fi + + # Set the password_valid variable to break out of the loop + password_valid=1 +done + + +psql -c "CREATE USER $username WITH PASSWORD '$password' SUPERUSER;" -U postgres +psql -c 'CREATE DATABASE $dbname WITH OWNER $username;' -U postgres +export LEMMY_DATABASE_URL=postgres://$username:$password@localhost:$port/$dbname + +echo $LEMMY_DATABASE_URL