diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-03-10 02:06:48 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-03-10 03:10:51 +0900 |
commit | 1cd150d2417ff750d75002e2fe4866cd1c651896 (patch) | |
tree | b40dbd1aa2b7e7c5a1b657c6550ebb0f8ec8e71c /activerecord/lib | |
parent | 6fc1bd6eea4373d869acc25354e5b4adfecc5758 (diff) | |
download | rails-1cd150d2417ff750d75002e2fe4866cd1c651896.tar.gz rails-1cd150d2417ff750d75002e2fe4866cd1c651896.tar.bz2 rails-1cd150d2417ff750d75002e2fe4866cd1c651896.zip |
Fix `reconnect!` to work after `disconnect!`
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb | 18 |
2 files changed, 16 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 05d8d5ac00..3990c0a71a 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -281,6 +281,8 @@ module ActiveRecord super @connection.reset configure_connection + rescue PG::ConnectionBad + connect end end diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index cb3d34a740..5e9b3afae4 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -95,8 +95,6 @@ module ActiveRecord def initialize(connection, logger, connection_options, config) super(connection, logger, config) - - @active = true configure_connection end @@ -144,14 +142,18 @@ module ActiveRecord alias supports_insert_conflict_target? supports_insert_on_conflict? def active? - @active + !@connection.closed? + end + + def reconnect! + super + connect if @connection.closed? end # Disconnects from the database if already connected. Otherwise, this # method does nothing. def disconnect! super - @active = false @connection.close rescue nil end @@ -611,6 +613,14 @@ module ActiveRecord StatementPool.new(self.class.type_cast_config_to_integer(@config[:statement_limit])) end + def connect + @connection = ::SQLite3::Database.new( + @config[:database].to_s, + @config.merge(results_as_hash: true) + ) + configure_connection + end + def configure_connection execute("PRAGMA foreign_keys = ON", "SCHEMA") end |