This is an automated email from the ASF dual-hosted git repository.

skrawcz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hamilton.git

commit 0952d6570c8c167ab9982629fadf56c278a3b6ff
Author: Stefan Krawczyk <[email protected]>
AuthorDate: Tue Feb 24 18:19:19 2026 -0800

    Fix database credentials in migration scripts
    
    The migration scripts were hardcoded to use 'hamilton' as the database
    user and name, but docker-compose.yml uses 'postgres' for both.
    
    This caused the error:
      psql: error: FATAL: role "hamilton" does not exist
    
    Changes:
    - migrate_postgres.sh: Use -U postgres -d postgres (was hamilton)
    - migrate_postgres_simple.sh: Use -U postgres -d postgres
    - UPGRADE.md: Update all example commands to use postgres credentials
    
    The docker-compose.yml configuration:
    - POSTGRES_USER=postgres
    - POSTGRES_DB=postgres
    - POSTGRES_PASSWORD=password
    
    Backend environment variables match:
    - DB_USER=postgres
    - DB_NAME=postgres
    - DB_PASSWORD=password
    
    Note: start_mini_mode.sh intentionally uses 'hamilton' credentials
    as it creates a separate standalone database container for testing.
    
    Fixes: #1488
---
 ui/UPGRADE.md                 | 20 ++++++++++----------
 ui/migrate_postgres.sh        | 14 +++++++-------
 ui/migrate_postgres_simple.sh |  4 ++--
 3 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/ui/UPGRADE.md b/ui/UPGRADE.md
index d9e4a7cc..7b3d66a6 100644
--- a/ui/UPGRADE.md
+++ b/ui/UPGRADE.md
@@ -81,7 +81,7 @@ cd hamilton/ui
 docker compose up -d
 
 # Export data
-docker compose exec db pg_dump -U hamilton hamilton > hamilton_backup.sql
+docker compose exec db pg_dump -U postgres postgres > hamilton_backup.sql
 
 # Stop containers
 docker compose down
@@ -107,10 +107,10 @@ git pull  # or checkout the latest version
 sleep 10
 
 # Import data
-docker compose exec -T db psql -U hamilton hamilton < hamilton_backup.sql
+docker compose exec -T db psql -U postgres postgres < hamilton_backup.sql
 
 # Verify data
-docker compose exec db psql -U hamilton hamilton -c "\dt"
+docker compose exec db psql -U postgres postgres -c "\dt"
 ```
 
 ##### Step 4: Verify Migration
@@ -130,8 +130,8 @@ The Hamilton UI automatically runs migrations on startup, 
which creates empty ta
 
 ```bash
 # Grant permissions to hamilton user
-docker compose exec db psql -U hamilton hamilton -c "GRANT ALL PRIVILEGES ON 
ALL TABLES IN SCHEMA public TO hamilton;"
-docker compose exec db psql -U hamilton hamilton -c "GRANT ALL PRIVILEGES ON 
ALL SEQUENCES IN SCHEMA public TO hamilton;"
+docker compose exec db psql -U postgres postgres -c "GRANT ALL PRIVILEGES ON 
ALL TABLES IN SCHEMA public TO postgres;"
+docker compose exec db psql -U postgres postgres -c "GRANT ALL PRIVILEGES ON 
ALL SEQUENCES IN SCHEMA public TO postgres;"
 ```
 
 **Issue:** Blob/artifact files missing
@@ -211,7 +211,7 @@ fi
 
 # Backup
 echo "Step 1: Backing up PostgreSQL 12 data..."
-docker compose exec -T db pg_dump -U hamilton hamilton > "$BACKUP_FILE"
+docker compose exec -T db pg_dump -U postgres postgres > "$BACKUP_FILE"
 echo "✓ Backup saved to: $BACKUP_FILE"
 echo ""
 
@@ -231,14 +231,14 @@ echo ""
 
 # Restore
 echo "Step 4: Restoring data..."
-docker compose exec -T db psql -U hamilton hamilton < "$BACKUP_FILE" 2>&1 | 
grep -v "ERROR:.*already exists" || true
+docker compose exec -T db psql -U postgres postgres < "$BACKUP_FILE" 2>&1 | 
grep -v "ERROR:.*already exists" || true
 echo "✓ Data restored"
 echo ""
 
 # Fix permissions
 echo "Step 5: Fixing permissions..."
-docker compose exec -T db psql -U hamilton hamilton -c "GRANT ALL PRIVILEGES 
ON ALL TABLES IN SCHEMA public TO hamilton;" > /dev/null
-docker compose exec -T db psql -U hamilton hamilton -c "GRANT ALL PRIVILEGES 
ON ALL SEQUENCES IN SCHEMA public TO hamilton;" > /dev/null
+docker compose exec -T db psql -U postgres postgres -c "GRANT ALL PRIVILEGES 
ON ALL TABLES IN SCHEMA public TO postgres;" > /dev/null
+docker compose exec -T db psql -U postgres postgres -c "GRANT ALL PRIVILEGES 
ON ALL SEQUENCES IN SCHEMA public TO postgres;" > /dev/null
 echo "✓ Permissions fixed"
 echo ""
 
@@ -288,7 +288,7 @@ docker volume rm ui_postgres_data
 ./run.sh --build
 
 # Restore from backup (if needed)
-docker compose exec -T db psql -U hamilton hamilton < hamilton_backup.sql
+docker compose exec -T db psql -U postgres postgres < hamilton_backup.sql
 ```
 
 **Q: Do I need to update my Hamilton SDK client code?**
diff --git a/ui/migrate_postgres.sh b/ui/migrate_postgres.sh
index 2456c732..b9cf5fd3 100755
--- a/ui/migrate_postgres.sh
+++ b/ui/migrate_postgres.sh
@@ -55,7 +55,7 @@ if ! $DOCKER_COMPOSE ps | grep -q "db"; then
 fi
 
 # Check PostgreSQL version
-PG_VERSION=$($DOCKER_COMPOSE exec -T db psql -U hamilton -d hamilton -c "SHOW 
server_version;" -t | tr -d ' ')
+PG_VERSION=$($DOCKER_COMPOSE exec -T db psql -U postgres -d hamilton -c "SHOW 
server_version;" -t | tr -d ' ')
 if [[ $PG_VERSION == 18* ]]; then
     echo "You are already running PostgreSQL 18. No migration needed."
     exit 0
@@ -67,7 +67,7 @@ echo ""
 
 # Backup
 echo "Step 1: Backing up PostgreSQL data..."
-$DOCKER_COMPOSE exec -T db pg_dump -U hamilton hamilton > "$BACKUP_FILE"
+$DOCKER_COMPOSE exec -T db pg_dump -U postgres postgres > "$BACKUP_FILE"
 echo "✓ Backup saved to: $BACKUP_FILE ($(du -h "$BACKUP_FILE" | cut -f1))"
 echo ""
 
@@ -93,7 +93,7 @@ sleep 20
 
 MAX_RETRIES=30
 RETRY_COUNT=0
-until $DOCKER_COMPOSE exec -T db pg_isready -U hamilton > /dev/null 2>&1; do
+until $DOCKER_COMPOSE exec -T db pg_isready -U postgres > /dev/null 2>&1; do
     RETRY_COUNT=$((RETRY_COUNT + 1))
     if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
         echo "Error: Database failed to start after $MAX_RETRIES attempts"
@@ -110,7 +110,7 @@ echo ""
 # Restore
 echo "Step 4: Restoring data to PostgreSQL 18..."
 echo "   (Ignoring 'already exists' errors - this is normal)"
-$DOCKER_COMPOSE exec -T db psql -U hamilton hamilton < "$BACKUP_FILE" 2>&1 | \
+$DOCKER_COMPOSE exec -T db psql -U postgres postgres < "$BACKUP_FILE" 2>&1 | \
     grep -v "ERROR:.*already exists" | \
     grep -v "^$" || true
 echo "✓ Data restored"
@@ -118,14 +118,14 @@ echo ""
 
 # Fix permissions
 echo "Step 5: Fixing permissions..."
-$DOCKER_COMPOSE exec -T db psql -U hamilton hamilton -c "GRANT ALL PRIVILEGES 
ON ALL TABLES IN SCHEMA public TO hamilton;" > /dev/null
-$DOCKER_COMPOSE exec -T db psql -U hamilton hamilton -c "GRANT ALL PRIVILEGES 
ON ALL SEQUENCES IN SCHEMA public TO hamilton;" > /dev/null
+$DOCKER_COMPOSE exec -T db psql -U postgres postgres -c "GRANT ALL PRIVILEGES 
ON ALL TABLES IN SCHEMA public TO postgres;" > /dev/null
+$DOCKER_COMPOSE exec -T db psql -U postgres postgres -c "GRANT ALL PRIVILEGES 
ON ALL SEQUENCES IN SCHEMA public TO postgres;" > /dev/null
 echo "✓ Permissions fixed"
 echo ""
 
 # Verify
 echo "Step 6: Verifying migration..."
-TABLE_COUNT=$($DOCKER_COMPOSE exec -T db psql -U hamilton hamilton -c "\dt" | 
grep -c "public" || echo "0")
+TABLE_COUNT=$($DOCKER_COMPOSE exec -T db psql -U postgres postgres -c "\dt" | 
grep -c "public" || echo "0")
 echo "✓ Found $TABLE_COUNT tables"
 echo ""
 
diff --git a/ui/migrate_postgres_simple.sh b/ui/migrate_postgres_simple.sh
index 7611cd03..5a5ee144 100755
--- a/ui/migrate_postgres_simple.sh
+++ b/ui/migrate_postgres_simple.sh
@@ -56,7 +56,7 @@ fi
 
 # Check PostgreSQL version
 echo "Checking current PostgreSQL version..."
-PG_VERSION=$($DOCKER_COMPOSE exec -T db psql -U hamilton -d hamilton -At -c 
"SHOW server_version;" | cut -d. -f1)
+PG_VERSION=$($DOCKER_COMPOSE exec -T db psql -U postgres -d postgres -At -c 
"SHOW server_version;" | cut -d. -f1)
 
 if [ "$PG_VERSION" -ge 18 ]; then
     echo "Already on PostgreSQL $PG_VERSION. No migration needed."
@@ -189,7 +189,7 @@ done
 echo "✓ Backend ready"
 
 # Check new PostgreSQL version
-NEW_PG_VERSION=$($DOCKER_COMPOSE exec -T db psql -U hamilton -d hamilton -At 
-c "SHOW server_version;" | cut -d. -f1)
+NEW_PG_VERSION=$($DOCKER_COMPOSE exec -T db psql -U postgres -d postgres -At 
-c "SHOW server_version;" | cut -d. -f1)
 echo "✓ PostgreSQL $NEW_PG_VERSION running"
 
 echo ""

Reply via email to