From a32dc56d2e5447ef8988cb98b8686476cc94e70c Mon Sep 17 00:00:00 2001 From: soryu Date: Tue, 23 Dec 2025 02:14:58 +0000 Subject: Add Postgres for persistence and File cabinet Migrations are local only currently, and must be run manually by setting POSTGRES_CONNECTION_URI --- makima/sh/download-models.sh | 0 makima/sh/run-migrations.sh | 11 +++++++++++ makima/sh/setup-db.sh | 22 ++++++++++++++++++++++ makima/sh/start-postgres.sh | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+) mode change 100644 => 100755 makima/sh/download-models.sh create mode 100755 makima/sh/run-migrations.sh create mode 100755 makima/sh/setup-db.sh create mode 100755 makima/sh/start-postgres.sh (limited to 'makima/sh') diff --git a/makima/sh/download-models.sh b/makima/sh/download-models.sh old mode 100644 new mode 100755 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}" -- cgit v1.2.3