igorkasyanchuk / rails_db

Rails Database Viewer and SQL Query Runner
https://www.railsjazz.com/
MIT License
1.46k stars 111 forks source link

[Feature Request] Support for read-only connections #118

Closed dbelling closed 3 years ago

dbelling commented 3 years ago

Let me start by saying - thank you for this library. It has filled a need for my team to provide visibility for data, not only in Postgres - but Redshift as well.

Which brings me to a current use-case - have you given any thought to adding support for read-only mode as a configuration option for rails_db?

I was thinking something to the effect of extending the existing Connection class to be wrapped in a READ_ONLY transaction, i.e.

def with_read_only_connection(configuration)
  ActiveRecord::Base.establish_connection(configuration)
  ActiveRecord::Base.connection.execute("SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY")
end
dbelling commented 3 years ago

Another thought would be to allow the gem to be initialized such that the SQL editor allows connection via a readonly DB user that is different than that used by the runtime context for the application.