Sha256: 4a93a3aac56246e8cb978cc152870d36e2c2c71ef55f30be6b93db9794b520b7

Contents?: true

Size: 857 Bytes

Versions: 4

Compression:

Stored size: 857 Bytes

Contents

module SaferRailsConsole
  module Patches
    module Sandbox
      module TransactionReadOnly
        module ActiveRecord
          module ConnectionAdapters
            module PostgreSQLAdapter
              def begin_db_transaction
                super
                execute 'SET TRANSACTION READ ONLY'
              end
            end
          end
        end
      end
    end
  end
end

if defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
  ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(SaferRailsConsole::Patches::Sandbox::TransactionReadOnly::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)

  # Ensure transaction is read-only if it was began before this patch was loaded
  connection = ::ActiveRecord::Base.connection
  connection.execute 'SET TRANSACTION READ ONLY' if connection.open_transactions > 0
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
safer_rails_console-0.4.1 lib/safer_rails_console/patches/sandbox/transaction_read_only.rb
safer_rails_console-0.4.0 lib/safer_rails_console/patches/sandbox/transaction_read_only.rb
safer_rails_console-0.3.0 lib/safer_rails_console/patches/sandbox/transaction_read_only.rb
safer_rails_console-0.2.0 lib/safer_rails_console/patches/sandbox/transaction_read_only.rb