remove unused
This commit is contained in:
@@ -1,75 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Script to fix PostgreSQL permissions using sudo (no password prompt for postgres user)
|
|
||||||
# This script reads DB_USER and DB_NAME from .env and grants necessary permissions
|
|
||||||
|
|
||||||
# Function to load .env file properly (handles comments and special characters)
|
|
||||||
load_env() {
|
|
||||||
if [ -f .env ]; then
|
|
||||||
while IFS= read -r line || [ -n "$line" ]; do
|
|
||||||
[[ "$line" =~ ^[[:space:]]*# ]] && continue
|
|
||||||
[[ -z "${line// }" ]] && continue
|
|
||||||
|
|
||||||
if [[ "$line" =~ ^[[:space:]]*([^#=]+)=(.*)$ ]]; then
|
|
||||||
key="${BASH_REMATCH[1]%% *}"
|
|
||||||
value="${BASH_REMATCH[2]}"
|
|
||||||
key=$(echo "$key" | xargs)
|
|
||||||
value=$(echo "$value" | sed -e 's/^["'\'']//' -e 's/["'\'']$//' | xargs)
|
|
||||||
export "$key=$value"
|
|
||||||
fi
|
|
||||||
done < .env
|
|
||||||
else
|
|
||||||
echo "Error: .env file not found"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Load environment variables
|
|
||||||
load_env
|
|
||||||
|
|
||||||
# Check if required variables are set
|
|
||||||
if [ -z "$DB_USER" ] || [ -z "$DB_NAME" ]; then
|
|
||||||
echo "Error: DB_USER or DB_NAME not set in .env file"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Fixing PostgreSQL permissions for user: $DB_USER on database: $DB_NAME"
|
|
||||||
echo "Using sudo to connect as postgres user (no password needed)"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# Connect as postgres superuser using sudo (no password prompt)
|
|
||||||
sudo -u postgres psql -d postgres <<EOF
|
|
||||||
-- Make the user the owner of the database (PostgreSQL 15+ requirement)
|
|
||||||
ALTER DATABASE $DB_NAME OWNER TO $DB_USER;
|
|
||||||
|
|
||||||
-- Connect to the target database to grant schema permissions
|
|
||||||
\c $DB_NAME
|
|
||||||
|
|
||||||
-- Make the user the owner of the public schema (PostgreSQL 15+ requirement)
|
|
||||||
ALTER SCHEMA public OWNER TO $DB_USER;
|
|
||||||
|
|
||||||
-- Grant all necessary permissions (redundant but safe)
|
|
||||||
GRANT CONNECT ON DATABASE $DB_NAME TO $DB_USER;
|
|
||||||
GRANT USAGE ON SCHEMA public TO $DB_USER;
|
|
||||||
GRANT CREATE ON SCHEMA public TO $DB_USER;
|
|
||||||
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO $DB_USER;
|
|
||||||
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO $DB_USER;
|
|
||||||
GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public TO $DB_USER;
|
|
||||||
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO $DB_USER;
|
|
||||||
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO $DB_USER;
|
|
||||||
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON FUNCTIONS TO $DB_USER;
|
|
||||||
|
|
||||||
-- For PostgreSQL 15+ - ensure full database access
|
|
||||||
GRANT ALL ON DATABASE $DB_NAME TO $DB_USER;
|
|
||||||
EOF
|
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
echo ""
|
|
||||||
echo "✓ Permissions granted successfully!"
|
|
||||||
echo "You can now run: npm run db:create"
|
|
||||||
else
|
|
||||||
echo ""
|
|
||||||
echo "✗ Failed to grant permissions. Please check the error above."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Script to fix PostgreSQL permissions for schema creation
|
|
||||||
# This script reads DB_USER, DB_NAME, DB_HOST, and DB_PORT from .env and grants necessary permissions
|
|
||||||
|
|
||||||
# Function to load .env file properly (handles comments and special characters)
|
|
||||||
load_env() {
|
|
||||||
if [ -f .env ]; then
|
|
||||||
# Read .env file line by line, skipping comments and empty lines
|
|
||||||
while IFS= read -r line || [ -n "$line" ]; do
|
|
||||||
# Skip comments and empty lines
|
|
||||||
[[ "$line" =~ ^[[:space:]]*# ]] && continue
|
|
||||||
[[ -z "${line// }" ]] && continue
|
|
||||||
|
|
||||||
# Export variable if it contains =
|
|
||||||
if [[ "$line" =~ ^[[:space:]]*([^#=]+)=(.*)$ ]]; then
|
|
||||||
key="${BASH_REMATCH[1]%% *}"
|
|
||||||
value="${BASH_REMATCH[2]}"
|
|
||||||
# Remove leading/trailing whitespace and quotes
|
|
||||||
key=$(echo "$key" | xargs)
|
|
||||||
value=$(echo "$value" | sed -e 's/^["'\'']//' -e 's/["'\'']$//' | xargs)
|
|
||||||
export "$key=$value"
|
|
||||||
fi
|
|
||||||
done < .env
|
|
||||||
else
|
|
||||||
echo "Error: .env file not found"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Load environment variables
|
|
||||||
load_env
|
|
||||||
|
|
||||||
# Check if required variables are set
|
|
||||||
if [ -z "$DB_USER" ] || [ -z "$DB_NAME" ]; then
|
|
||||||
echo "Error: DB_USER or DB_NAME not set in .env file"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Set defaults for host and port if not set
|
|
||||||
DB_HOST=${DB_HOST:-localhost}
|
|
||||||
DB_PORT=${DB_PORT:-5432}
|
|
||||||
|
|
||||||
echo "Fixing PostgreSQL permissions for user: $DB_USER on database: $DB_NAME"
|
|
||||||
echo "Connecting to PostgreSQL at $DB_HOST:$DB_PORT"
|
|
||||||
echo "You will be prompted for the PostgreSQL superuser password (usually 'postgres')"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# Connect as postgres superuser and grant permissions
|
|
||||||
# Use -h for host and -p for port to force TCP/IP connection (password auth)
|
|
||||||
psql -h "$DB_HOST" -p "$DB_PORT" -U postgres -d postgres <<EOF
|
|
||||||
-- Grant usage on the database
|
|
||||||
GRANT CONNECT ON DATABASE $DB_NAME TO $DB_USER;
|
|
||||||
|
|
||||||
-- Grant usage on the public schema
|
|
||||||
GRANT USAGE ON SCHEMA public TO $DB_USER;
|
|
||||||
|
|
||||||
-- Grant create privileges on the public schema
|
|
||||||
GRANT CREATE ON SCHEMA public TO $DB_USER;
|
|
||||||
|
|
||||||
-- Grant all privileges on all tables in public schema (current and future)
|
|
||||||
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO $DB_USER;
|
|
||||||
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO $DB_USER;
|
|
||||||
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO $DB_USER;
|
|
||||||
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO $DB_USER;
|
|
||||||
|
|
||||||
-- For PostgreSQL 15+
|
|
||||||
GRANT ALL ON DATABASE $DB_NAME TO $DB_USER;
|
|
||||||
EOF
|
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
echo ""
|
|
||||||
echo "✓ Permissions granted successfully!"
|
|
||||||
echo "You can now run: npm run db:create"
|
|
||||||
else
|
|
||||||
echo ""
|
|
||||||
echo "✗ Failed to grant permissions. Please check the error above."
|
|
||||||
echo ""
|
|
||||||
echo "Alternative: You can run the SQL commands manually:"
|
|
||||||
echo " psql -h $DB_HOST -p $DB_PORT -U postgres -d postgres"
|
|
||||||
echo " Then execute the GRANT commands from fix-db-permissions.sql"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
-- Fix PostgreSQL permissions for schema creation
|
|
||||||
-- Run this script as a PostgreSQL superuser (usually 'postgres')
|
|
||||||
--
|
|
||||||
-- Option 1: Run with psql (replace dmenuuser and dmenutest with your values):
|
|
||||||
-- psql -U postgres -d postgres -f fix-db-permissions.sql
|
|
||||||
--
|
|
||||||
-- Option 2: Run with sudo (no password needed):
|
|
||||||
-- sudo -u postgres psql -d postgres -f fix-db-permissions.sql
|
|
||||||
--
|
|
||||||
-- Option 3: Copy and paste these commands into psql after connecting
|
|
||||||
|
|
||||||
-- Replace 'dmenuuser' and 'dmenutest' with your actual DB_USER and DB_NAME from .env
|
|
||||||
-- Current values from your .env: DB_USER=dmenuuser, DB_NAME=dmenutest
|
|
||||||
--
|
|
||||||
-- IMPORTANT: For PostgreSQL 15+, we need to make the user the owner of the database and schema
|
|
||||||
|
|
||||||
-- Make the user the owner of the database (PostgreSQL 15+ requirement)
|
|
||||||
ALTER DATABASE dmenutest OWNER TO dmenuuser;
|
|
||||||
|
|
||||||
-- Connect to the target database (run this in psql, then continue with schema commands)
|
|
||||||
-- \c dmenutest
|
|
||||||
|
|
||||||
-- Make the user the owner of the public schema (PostgreSQL 15+ requirement)
|
|
||||||
ALTER SCHEMA public OWNER TO dmenuuser;
|
|
||||||
|
|
||||||
-- Grant all necessary permissions (redundant but safe)
|
|
||||||
GRANT CONNECT ON DATABASE dmenutest TO dmenuuser;
|
|
||||||
GRANT USAGE ON SCHEMA public TO dmenuuser;
|
|
||||||
GRANT CREATE ON SCHEMA public TO dmenuuser;
|
|
||||||
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO dmenuuser;
|
|
||||||
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO dmenuuser;
|
|
||||||
GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public TO dmenuuser;
|
|
||||||
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO dmenuuser;
|
|
||||||
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO dmenuuser;
|
|
||||||
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON FUNCTIONS TO dmenuuser;
|
|
||||||
|
|
||||||
-- For PostgreSQL 15+ - ensure full database access
|
|
||||||
GRANT ALL ON DATABASE dmenutest TO dmenuuser;
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user