lemmy/scripts/start_dev_db.sh

28 lines
898 B
Bash
Raw Normal View History

# This script is meant to be run with `source` so it can set environment variables.
export PGDATA="$PWD/dev_pgdata"
export PGHOST=$PWD
2023-12-23 15:38:29 +00:00
export PGUSER=postgres
2023-12-25 17:00:59 +00:00
export DATABASE_URL="postgresql://lemmy:password@/lemmy?host=$PWD"
export LEMMY_DATABASE_URL=$DATABASE_URL
export PGDATABASE=lemmy
# If cluster exists, stop the server and delete the cluster
if [ -d $PGDATA ]
then
# Prevent `stop` from failing if server already stopped
pg_ctl restart > /dev/null
pg_ctl stop
rm -rf $PGDATA
fi
# Create cluster
initdb --username=postgres --auth=trust --no-instructions
# Start server that only listens to socket in current directory
pg_ctl start --options="-c listen_addresses= -c unix_socket_directories=$PWD" > /dev/null
# Setup database
2023-12-25 17:00:59 +00:00
PGDATABASE=postgres psql -c "CREATE USER lemmy WITH PASSWORD 'password' SUPERUSER;"
PGDATABASE=postgres psql -c "CREATE DATABASE lemmy WITH OWNER lemmy;"