Jacob Crofts
Jacob Crofts

Reputation: 186

How can I allow an external application to connect directly to my Ruby on Rails-integrated PostgreSQL database?

I have one database, and several applications that need to use it (one Ruby on Rails app, with which the database is integrated by default, and a bunch of Minecraft servers running Java plugins). Right now, I am using my web application's REST api to access the database.

So: plugin -> api -> db -> api -> plugin

I am looking for a way for my plugins to access the database directly, without having to first go through the web application.

plugin -> db -> plugin

How can I allow an external application to access my database? How can I ensure that only certain applications are allowed to access the db? (Also: SHOULD I be doing this at all?)

Upvotes: 2

Views: 257

Answers (1)

jefflunt
jefflunt

Reputation: 33954

Take a look into how ActiveRecord connects to the database, and you'll see that it simply uses the same way to connect to Postgres (a login connection string, or set of credentials, etc.), and that same method can be used by any other application.

Basically this means that if another application knows:

  • The URL or IP address where your DB is hosted
  • The username
  • The password
  • The port

... and there are no restrictions in place such as firewall rules that prevent access, then the application should be able to talk to the DB directly. ActiveRecord is basically just a software layer on top of the DB, but it doesn't "own" or "control" the database. Your Rails app is technically a client of the DB server.

Upvotes: 1

Related Questions