diff --git a/.env.example b/.env.example index 3b84700..d673cf1 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,3 @@ -PAYLOAD_SECRET=jawliejfilwajefSEANlawefawfewag349jwgo3gj4w -MONGODB_URI=mongodb://127.0.0.1:27017/next-payload-3 -POSTGRES_URI=postgres://127.0.0.1:5432/next-payload-3 +PAYLOAD_SECRET='jawliejfilwajefSEANlawefawfewag349jwgo3gj4w' +MONGODB_URI='mongodb://127.0.0.1:27017/next-payload-3' +POSTGRES_URI='postgresql://postgres:password123@127.0.0.1:5432/next-payload-3' diff --git a/README.md b/README.md index 32ac2fa..7c5d6b8 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ To try out this repo yourself, follow the steps below: 1. `cd` into the new folder by running `cd ./payload-3.0-alpha-demo` 1. Copy the `.env.example` by running `cp .env.example .env` in the repo, then fill out the values including the connection string to your DB 1. Install dependencies with whatever package manager you use (`yarn`, `npm install`, `pnpm i`, etc.) +1. Start your database. For local postgresql use `.\start-database.sh` to start it in docker container. 1. Fire it up (`yarn dev`, `npm run dev`, `pnpm dev`, etc.) 1. Visit https://localhost:3000 and log in with the user created within the config's `onInit` method diff --git a/start-database.sh b/start-database.sh new file mode 100755 index 0000000..cdccb8b --- /dev/null +++ b/start-database.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +DB_CONTAINER_NAME="next-payload-3" + +if ! [ -x "$(command -v docker)" ]; then + echo "Docker is not installed. Please install docker and try again.\nDocker install guide: https://docs.docker.com/engine/install/" + exit 1 +fi + +if [ "$(docker ps -q -f name=$DB_CONTAINER_NAME)" ]; then + docker start $DB_CONTAINER_NAME + echo "Database container started" + exit 0 +fi + +set -a +source .env + +DB_PASSWORD=$(echo $DATABASE_URL | awk -F':' '{print $3}' | awk -F'@' '{print $1}') + +if [ "$DB_PASSWORD" = "password" ]; then + echo "You are using the default database password" +fi + +docker run --name $DB_CONTAINER_NAME -e POSTGRES_PASSWORD=$DB_PASSWORD -e POSTGRES_HOST_AUTH_METHOD=trust -e POSTGRES_DB=next-payload-3 -d -p 5432:5432 docker.io/postgres + +echo "Database container was successfully created" +