From 6a38189ef0d6e4bdef1d2910ce17a50b64cb5795 Mon Sep 17 00:00:00 2001 From: Stefan Hardegger Date: Mon, 20 Oct 2025 12:30:28 +0200 Subject: [PATCH] fix images --- backend/apply_backup_jobs_migration.sh | 54 +++++++++++++++++++ backend/create_backup_jobs_table.sql | 29 ++++++++++ deploy.sh | 19 +++++++ .../src/components/stories/SlateEditor.tsx | 7 +-- 4 files changed, 106 insertions(+), 3 deletions(-) create mode 100755 backend/apply_backup_jobs_migration.sh create mode 100644 backend/create_backup_jobs_table.sql diff --git a/backend/apply_backup_jobs_migration.sh b/backend/apply_backup_jobs_migration.sh new file mode 100755 index 0000000..afc4e0f --- /dev/null +++ b/backend/apply_backup_jobs_migration.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +# Script to apply backup_jobs table migration to all library databases +# This should be run from the backend directory + +set -e + +# Use full docker path +DOCKER="/usr/local/bin/docker" + +echo "Applying backup_jobs table migration..." + +# Get database connection details from environment or use defaults +DB_HOST="${POSTGRES_HOST:-postgres}" +DB_PORT="${POSTGRES_PORT:-5432}" +DB_USER="${POSTGRES_USER:-storycove}" +DB_PASSWORD="${POSTGRES_PASSWORD:-password}" + +# List of databases to update +DATABASES=("storycove" "storycove_afterdark") + +for DB_NAME in "${DATABASES[@]}"; do + echo "" + echo "Applying migration to database: $DB_NAME" + + # Check if database exists + if $DOCKER exec storycove-postgres-1 psql -U "$DB_USER" -lqt | cut -d \| -f 1 | grep -qw "$DB_NAME"; then + echo "Database $DB_NAME exists, applying migration..." + + # Apply migration + $DOCKER exec -i storycove-postgres-1 psql -U "$DB_USER" -d "$DB_NAME" < create_backup_jobs_table.sql + + if [ $? -eq 0 ]; then + echo "✓ Migration applied successfully to $DB_NAME" + else + echo "✗ Failed to apply migration to $DB_NAME" + exit 1 + fi + else + echo "⚠ Database $DB_NAME does not exist, skipping..." + fi +done + +echo "" +echo "Migration complete!" +echo "" +echo "Verifying table creation..." +for DB_NAME in "${DATABASES[@]}"; do + if $DOCKER exec storycove-postgres-1 psql -U "$DB_USER" -lqt | cut -d \| -f 1 | grep -qw "$DB_NAME"; then + echo "" + echo "Checking $DB_NAME:" + $DOCKER exec storycove-postgres-1 psql -U "$DB_USER" -d "$DB_NAME" -c "\d backup_jobs" 2>/dev/null || echo " Table not found in $DB_NAME" + fi +done diff --git a/backend/create_backup_jobs_table.sql b/backend/create_backup_jobs_table.sql new file mode 100644 index 0000000..41de698 --- /dev/null +++ b/backend/create_backup_jobs_table.sql @@ -0,0 +1,29 @@ +-- Create backup_jobs table for async backup job tracking +-- This should be run on all library databases (default and afterdark) + +CREATE TABLE IF NOT EXISTS backup_jobs ( + id UUID PRIMARY KEY, + library_id VARCHAR(255) NOT NULL, + type VARCHAR(50) NOT NULL CHECK (type IN ('DATABASE_ONLY', 'COMPLETE')), + status VARCHAR(50) NOT NULL CHECK (status IN ('PENDING', 'IN_PROGRESS', 'COMPLETED', 'FAILED', 'EXPIRED')), + file_path VARCHAR(1000), + file_size_bytes BIGINT, + progress_percent INTEGER, + error_message VARCHAR(1000), + created_at TIMESTAMP NOT NULL, + started_at TIMESTAMP, + completed_at TIMESTAMP, + expires_at TIMESTAMP +); + +-- Create index on library_id for faster lookups +CREATE INDEX IF NOT EXISTS idx_backup_jobs_library_id ON backup_jobs(library_id); + +-- Create index on status for cleanup queries +CREATE INDEX IF NOT EXISTS idx_backup_jobs_status ON backup_jobs(status); + +-- Create index on expires_at for cleanup queries +CREATE INDEX IF NOT EXISTS idx_backup_jobs_expires_at ON backup_jobs(expires_at); + +-- Create index on created_at for ordering +CREATE INDEX IF NOT EXISTS idx_backup_jobs_created_at ON backup_jobs(created_at DESC); diff --git a/deploy.sh b/deploy.sh index d1a93fc..6af684b 100755 --- a/deploy.sh +++ b/deploy.sh @@ -55,6 +55,25 @@ if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then exit 1 fi +# Apply database migrations +echo -e "${YELLOW}🗄️ Applying database migrations...${NC}" +if [ -f "backend/create_backup_jobs_table.sql" ]; then + echo "Applying backup_jobs table migration..." + + # Get list of databases + DATABASES=$(docker-compose exec -T postgres psql -U storycove -lqt | cut -d \| -f 1 | grep -E '^ storycove' | sed 's/^[ \t]*//') + + # Apply migration to each database + for DB_NAME in $DATABASES; do + echo " - Applying to database: $DB_NAME" + docker-compose exec -T postgres psql -U storycove -d "$DB_NAME" < backend/create_backup_jobs_table.sql 2>&1 | grep -E "(CREATE|ERROR)" || true + done + + echo -e "${GREEN}✅ Database migrations applied${NC}" +else + echo -e "${YELLOW}⚠️ No migration files found, skipping...${NC}" +fi + # Check if Solr is ready echo -e "${YELLOW}🔍 Checking Solr health...${NC}" RETRY_COUNT=0 diff --git a/frontend/src/components/stories/SlateEditor.tsx b/frontend/src/components/stories/SlateEditor.tsx index b60c848..da1a0da 100644 --- a/frontend/src/components/stories/SlateEditor.tsx +++ b/frontend/src/components/stories/SlateEditor.tsx @@ -114,9 +114,10 @@ const htmlToSlate = (html: string): Descendant[] => { const img = element as HTMLImageElement; results.push({ type: 'image', - src: img.src || img.getAttribute('src') || '', - alt: img.alt || img.getAttribute('alt') || '', - caption: img.title || img.getAttribute('title') || '', + // Use getAttribute to preserve relative URLs instead of .src which converts to absolute + src: img.getAttribute('src') || '', + alt: img.getAttribute('alt') || '', + caption: img.getAttribute('title') || '', children: [{ text: '' }] // Images need children in Slate }); break;