I asked here. I don’t know how it works so I would like to know. Why I can't connect AWS RDS with rake. on EKS · Issue #49402 · rails/rails · GitHub.
Steps to reproduce
First, I’m a biginner for ruby.
# database.yml
staging:
primary:
adapter: postgis
encoding: utf8
database: <%= ENV['DATABASE_NAME'] %>
pool: 5
username: <%= ENV['DATABASE_USER'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
host: <%= ENV['DATABASE_HOST'] %>
port: 5432
# migration.yml
apiVersion: batch/v1
kind: Job
metadata:
name: testmigration
spec:
backoffLimit: 3
completions: 1
template:
spec:
containers:
- command:
- bash
- -c
- |
set -e
# db create
rake db:exists || rake db:create
echo "creation completed" # created "test_db"
# migrate
rake db:migrate
echo "migration completed"
env:
- name: DATABASE_PASSWORD
value: <password>
- name: DATABASE_USER
value: "test_user"
- name: DATABASE_HOST
value: "RDS_HOST_NAME"
- name: DATAABSE_NAME
value: "test_db"
- name: RAILS_ENV
value: "staging"
image: "my-image"
name: migration
then, execute kubectl apply -f migration.yml
.
Expected behavior
migration completed with no error.
Actual behavior
I got logs with kubectl logs as follows.
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Couldn't create 'app' database. Please check your configuration.
rake aborted!
ActiveRecord::NoDatabaseError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Caused by:
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Created database 'test_db'
so why rake task has connect local db? In the first place any settings are wrong?
But I can create db successfuly.
System configuration
Rails version: rails (6.1.7.4)
Ruby version: ruby 3.0.6p216