Skip to content

Instantly share code, notes, and snippets.

@mirakui
Created May 1, 2012 02:08
Show Gist options
  • Select an option

  • Save mirakui/2564415 to your computer and use it in GitHub Desktop.

Select an option

Save mirakui/2564415 to your computer and use it in GitHub Desktop.
readonly rails console using Arproxy
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands/console'
require APP_PATH
Rails.application.require_environment!
require "arproxy"
module Arproxy
class Readonly < Base
def execute(sql, name=nil)
if sql =~ /^(SELECT|SET|SHOW|DESCRIBE)\b/
super sql, name
else
Rails.logger.warn "\e[31m #{name} (BLOCKED) #{sql}\e[0m"
end
end
end
end
Arproxy.configure do |config|
config.adapter = "mysql2"
config.use Arproxy::Readonly
end
Arproxy.enable!
Rails::Console.start(Rails.application)
@sankalp-khare

Copy link
Copy Markdown

is there something similar one could do for mongodb?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment