backend changes

This commit is contained in:
Chandini 2025-09-15 16:58:26 +05:30
parent 7d94569e7e
commit 89cc485734
4 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,37 @@
-- Create pipeline_admin user for existing database
-- This script can be run manually on existing PostgreSQL instances
-- Create pipeline_admin user if it doesn't exist
DO $$
BEGIN
IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = 'pipeline_admin') THEN
CREATE USER pipeline_admin WITH PASSWORD 'secure_pipeline_2024';
RAISE NOTICE 'Created user pipeline_admin';
ELSE
-- Update password in case it's different
ALTER USER pipeline_admin WITH PASSWORD 'secure_pipeline_2024';
RAISE NOTICE 'Updated password for existing user pipeline_admin';
END IF;
END
$$;
-- Ensure pipeline_admin has superuser privileges (needed for migrations)
ALTER USER pipeline_admin WITH SUPERUSER;
-- Grant all privileges on existing databases
GRANT ALL PRIVILEGES ON DATABASE postgres TO pipeline_admin;
GRANT ALL PRIVILEGES ON DATABASE dev_pipeline TO pipeline_admin;
-- Connect to dev_pipeline and grant schema permissions
\c dev_pipeline;
GRANT ALL ON SCHEMA public TO pipeline_admin;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO pipeline_admin;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO pipeline_admin;
GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public TO pipeline_admin;
-- Set default privileges for future objects
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO pipeline_admin;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO pipeline_admin;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON FUNCTIONS TO pipeline_admin;
\echo 'Pipeline admin user setup completed successfully'

View File

@ -6,6 +6,14 @@ CREATE DATABASE dev_pipeline;
-- Create users -- Create users
CREATE USER n8n_user WITH PASSWORD 'n8n_secure_2024'; CREATE USER n8n_user WITH PASSWORD 'n8n_secure_2024';
CREATE USER gitea_user WITH PASSWORD 'gitea_secure_2024'; CREATE USER gitea_user WITH PASSWORD 'gitea_secure_2024';
-- Create pipeline_admin user if it doesn't exist
DO $$
BEGIN
IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = 'pipeline_admin') THEN
CREATE USER pipeline_admin WITH PASSWORD 'secure_pipeline_2024';
END IF;
END
$$;
-- Grant permissions -- Grant permissions
GRANT ALL PRIVILEGES ON DATABASE n8n_db TO n8n_user; GRANT ALL PRIVILEGES ON DATABASE n8n_db TO n8n_user;

View File

@ -12,6 +12,7 @@ services:
POSTGRES_DB: dev_pipeline POSTGRES_DB: dev_pipeline
volumes: volumes:
- postgres_data:/var/lib/postgresql/data - postgres_data:/var/lib/postgresql/data
- ./databases/scripts/init.sql:/docker-entrypoint-initdb.d/init.sql
ports: ports:
- "5432:5432" - "5432:5432"
networks: networks:

View File

@ -0,0 +1,28 @@
#!/bin/bash
# Fix PostgreSQL user creation for existing deployments
# This script creates the pipeline_admin user in an existing PostgreSQL container
echo "🔧 Fixing PostgreSQL user authentication..."
# Wait for PostgreSQL to be ready
echo "⏳ Waiting for PostgreSQL to be ready..."
until docker exec pipeline_postgres pg_isready -U postgres > /dev/null 2>&1; do
echo " PostgreSQL is not ready yet, waiting..."
sleep 2
done
echo "✅ PostgreSQL is ready"
# Execute the user creation script
echo "👤 Creating pipeline_admin user..."
docker exec -i pipeline_postgres psql -U postgres -d postgres < ./databases/scripts/create-pipeline-admin.sql
if [ $? -eq 0 ]; then
echo "✅ Pipeline admin user created successfully"
echo "🚀 You can now restart the migrations service:"
echo " docker compose restart migrations"
else
echo "❌ Failed to create pipeline admin user"
exit 1
fi