Created
May 1, 2012 02:08
-
-
Save mirakui/2564415 to your computer and use it in GitHub Desktop.
readonly rails console using Arproxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
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
mysql2 のところは適当に書き換えてください