Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Support ActiveRecord::ReadOnlyError #1898

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,23 @@ module DatabaseStatements
#
# see: abstract/database_statements.rb

READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(:commit, :explain, :select, :savepoint, :rollback) # :nodoc:
private_constant :READ_QUERY

def write_query?(sql) # :nodoc:
!READ_QUERY.match?(sql)
end

# Executes a SQL statement
def execute(sql, name = nil)
p '=========================================='
p "preventing_writes?: #{preventing_writes?}"
p "write_query?: #{write_query?(sql)}"
p "sql: #{sql}"
if preventing_writes? && write_query?(sql)
raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
end

log(sql, name) { @connection.exec(sql) }
end

Expand Down Expand Up @@ -189,6 +204,8 @@ def exec_rollback_db_transaction #:nodoc:
end

def create_savepoint(name = current_savepoint_name) #:nodoc:
pp '------------------------------------------------------------'
pp caller
execute("SAVEPOINT #{name}", "TRANSACTION")
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ def build_statement_pool
StatementPool.new(self.class.type_cast_config_to_integer(@config[:statement_limit]))
end

def supports_lazy_transactions?
true
end

def supports_savepoints? #:nodoc:
true
end
Expand Down