42 lines
1.4 KiB
Bash
42 lines
1.4 KiB
Bash
![]() |
#!/bin/bash
|
||
|
# Script to test permissions on the events table
|
||
|
|
||
|
# Load environment variables from .env file
|
||
|
if [ -f .env ]; then
|
||
|
echo "Loading environment variables from .env file..."
|
||
|
export $(grep -v '^#' .env | xargs)
|
||
|
fi
|
||
|
|
||
|
# Default values if not set in .env
|
||
|
DB_NAME=${DB_NAME:-"oedb"}
|
||
|
DB_USER=${DB_USER:-"postgres"}
|
||
|
DB_HOST=${DB_HOST:-"localhost"}
|
||
|
|
||
|
# Set PGPASSWORD for authentication
|
||
|
export PGPASSWORD="${POSTGRES_PASSWORD}"
|
||
|
|
||
|
echo "Testing permissions on the events table for user '${DB_USER}'..."
|
||
|
|
||
|
# Try to select from the events table
|
||
|
PGPASSWORD="${POSTGRES_PASSWORD}" psql -h $DB_HOST -U $DB_USER -d $DB_NAME -c "SELECT COUNT(*) FROM events;"
|
||
|
|
||
|
if [ $? -eq 0 ]; then
|
||
|
echo "✅ Success! User '${DB_USER}' has permission to access the events table."
|
||
|
else
|
||
|
echo "❌ Error: User '${DB_USER}' does not have permission to access the events table."
|
||
|
echo "Running setup_db.sh to fix permissions..."
|
||
|
./setup_db.sh
|
||
|
|
||
|
# Test again after running setup_db.sh
|
||
|
echo "Testing permissions again..."
|
||
|
PGPASSWORD="${POSTGRES_PASSWORD}" psql -h $DB_HOST -U $DB_USER -d $DB_NAME -c "SELECT COUNT(*) FROM events;"
|
||
|
|
||
|
if [ $? -eq 0 ]; then
|
||
|
echo "✅ Success! Permissions fixed. User '${DB_USER}' now has access to the events table."
|
||
|
else
|
||
|
echo "❌ Error: Still unable to access the events table. Please check database configuration."
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
echo "Test completed."
|
||
|
exit 0
|