Rails Remote Database Connection Gives No Tables

112 views Asked by At

after creating a rails new project I have modified database.yml to connect to a remote postgresql read-only database that is mantained from a cardano-db-sync node:

development:
  <<: *default
  adapter: postgresql
  encoding: utf8
  database: cexplorer
  username: <%= ENV['PG_USERNAME'] %>
  password: <%= ENV['PG_PWD'] %>
  host: <%= ENV['IP_PG_SERVER'] %>
  port: 5432
  pool: 3 

after running rake db:create I can launch rails server and visit localhost:3000 with no problems, no errors about the database are given.

connecting to the remote database with psql cexplorer -U bswan -h xx.xxx.xx.xxx -p 5432 I get no problem and I can see the tables populating the database cexplorer.

[backend] $ psql cexplorer -U user -h xx.xxx.xx.xxx -p 5432 
Password for user user: **

cexplorer=# \d
                    List of relations
 Schema |            Name             |   Type   | Owner 
--------+-----------------------------+----------+-------
 public | block                       | table    | user
 public | block_id_seq                | sequence | user
 public | delegation                  | table    | user
 public | delegation_id_seq           | sequence | user
 public | epoch                       | table    | user
...
...

Problem

launching rails console to test the database I get no tables coming back from the connected dabase:

[backend] $ rails console
2.6.1 :001 > ActiveRecord::Base.connection.tables
 => [] 

How come I don't see the tables that I see through psql?

2.6.1 :002 > ActiveRecord::Base.clear_all_connections!
 => [#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x00007f9b034a5628 @mon_mutex=#<Thread::Mutex:0x00007f9b034a54c0>, @mon_mutex_owner_object_id=70151875930900, @mon_owner=nil, @mon_count=0, @query_cache_enabled=#<Concurrent::Map:0x00007f9b034a5498 entries=0 default_proc=#<Proc:0x00007f9b034a5380@/Users/sergio/.rvm/gems/ruby-2.6.1/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/query_cache.rb:32>>, @spec=#<ActiveRecord::ConnectionAdapters::ConnectionSpecification:0x00007f9b034a5ab0 @name="primary", @config={:adapter=>"postgresql", :encoding=>"utf8", :pool=>3, :database=>"cexplorer", :username=>nil, :password=>nil, :host=>nil, :port=>5432}, @adapter_method="postgresql_connection">, @checkout_timeout=5, @idle_timeout=300.0, @size=3, @thread_cached_conns=#<Concurrent::Map:0x00007f9b034a5330 entries=0 default_proc=nil>, @connections=[], @automatic_reconnect=true, @now_connecting=0, @threads_blocking_new_connections=0, @available=#<ActiveRecord::ConnectionAdapters::ConnectionPool::ConnectionLeasingQueue:0x00007f9b034a5150 @lock=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x00007f9b034a5628 ...>, @cond=#<MonitorMixin::ConditionVariable:0x00007f9b034a5128 @monitor=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x00007f9b034a5628 ...>, @cond=#<Thread::ConditionVariable:0x00007f9b034a5038>>, @num_waiting=0, @queue=[]>, @lock_thread=false, @reaper=#<ActiveRecord::ConnectionAdapters::ConnectionPool::Reaper:0x00007f9b034a4b60 @pool=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x00007f9b034a5628 ...>, @frequency=60.0>>] 
2.6.1 :003 > ActiveRecord::Base.connection.tables
 => [] 
0

There are 0 answers