Skip to content

Instantly share code, notes, and snippets.

@mirakui
Created May 1, 2012 02:08
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mirakui/2564415 to your computer and use it in GitHub Desktop.
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)
@mirakui
Copy link
Author

mirakui commented May 1, 2012

mysql2 のところは適当に書き換えてください

@sankalp-khare
Copy link

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