diff options
| author | soryu <soryu@soryu.co> | 2025-12-23 02:14:58 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2025-12-23 14:47:18 +0000 |
| commit | a32dc56d2e5447ef8988cb98b8686476cc94e70c (patch) | |
| tree | 61307503c4af82103cea2360fe95d3ea324968d6 /makima/sh/start-postgres.sh | |
| parent | 73649d135efccda7e446775db773e21b458de202 (diff) | |
| download | soryu-a32dc56d2e5447ef8988cb98b8686476cc94e70c.tar.gz soryu-a32dc56d2e5447ef8988cb98b8686476cc94e70c.zip | |
Add Postgres for persistence and File cabinet
Migrations are local only currently, and must be run manually by setting POSTGRES_CONNECTION_URI
Diffstat (limited to 'makima/sh/start-postgres.sh')
| -rwxr-xr-x | makima/sh/start-postgres.sh | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/makima/sh/start-postgres.sh b/makima/sh/start-postgres.sh new file mode 100755 index 0000000..203b178 --- /dev/null +++ b/makima/sh/start-postgres.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# Start PostgreSQL via Docker for local development + +CONTAINER_NAME="makima-postgres" +POSTGRES_USER="makima" +POSTGRES_PASSWORD="makima_dev" +POSTGRES_DB="makima" +POSTGRES_PORT="5432" + +# Check if container already exists +if docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then + echo "Container ${CONTAINER_NAME} exists. Starting..." + docker start ${CONTAINER_NAME} +else + echo "Creating new PostgreSQL container..." + docker run -d \ + --name ${CONTAINER_NAME} \ + -e POSTGRES_USER=${POSTGRES_USER} \ + -e POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \ + -e POSTGRES_DB=${POSTGRES_DB} \ + -p ${POSTGRES_PORT}:5432 \ + -v makima_postgres_data:/var/lib/postgresql/data \ + postgres:16-alpine +fi + +echo "Waiting for PostgreSQL to be ready..." +until docker exec ${CONTAINER_NAME} pg_isready -U ${POSTGRES_USER} 2>/dev/null; do + sleep 1 +done + +echo "PostgreSQL is ready!" +echo "Connection URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:${POSTGRES_PORT}/${POSTGRES_DB}" |
