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 | |
| 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')
| -rwxr-xr-x[-rw-r--r--] | makima/sh/download-models.sh | 0 | ||||
| -rwxr-xr-x | makima/sh/run-migrations.sh | 11 | ||||
| -rwxr-xr-x | makima/sh/setup-db.sh | 22 | ||||
| -rwxr-xr-x | makima/sh/start-postgres.sh | 32 |
4 files changed, 65 insertions, 0 deletions
diff --git a/makima/sh/download-models.sh b/makima/sh/download-models.sh index 0381e15..0381e15 100644..100755 --- a/makima/sh/download-models.sh +++ b/makima/sh/download-models.sh diff --git a/makima/sh/run-migrations.sh b/makima/sh/run-migrations.sh new file mode 100755 index 0000000..d34d6b1 --- /dev/null +++ b/makima/sh/run-migrations.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# Run sqlx migrations + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +MAKIMA_DIR="$(dirname "${SCRIPT_DIR}")" + +POSTGRES_CONNECTION_URI="${POSTGRES_CONNECTION_URI:-postgres://makima:makima_dev@localhost:5432/makima}" + +echo "Running migrations from ${MAKIMA_DIR}/migrations..." +sqlx migrate run --source "${MAKIMA_DIR}/migrations" --database-url "${POSTGRES_CONNECTION_URI}" +echo "Migrations complete!" diff --git a/makima/sh/setup-db.sh b/makima/sh/setup-db.sh new file mode 100755 index 0000000..95e35ac --- /dev/null +++ b/makima/sh/setup-db.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# Combined database setup script + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +echo "=== Setting up Makima Database ===" +echo "" + +# Start PostgreSQL +echo "Step 1: Starting PostgreSQL..." +bash "${SCRIPT_DIR}/start-postgres.sh" +echo "" + +# Wait a moment for full initialization +sleep 2 + +# Run migrations +echo "Step 2: Running migrations..." +bash "${SCRIPT_DIR}/run-migrations.sh" +echo "" + +echo "=== Database setup complete! ===" 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}" |
