aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
diff options
context:
space:
mode:
authorGuilherme Mansur <guilherme.mansur@shopify.com>2019-06-10 16:22:29 -0400
committerGuilherme Mansur <guilherme.mansur@shopify.com>2019-06-17 14:00:53 -0400
commitfe30211574648fa21bff958a3cf952fd0c20c3b1 (patch)
treed0f4c8b65fadf52ea0b0474c7b646b216e5b4a9f /activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
parentc65acad0df6b332324c24e725c7d581bd76f9760 (diff)
downloadrails-fe30211574648fa21bff958a3cf952fd0c20c3b1.tar.gz
rails-fe30211574648fa21bff958a3cf952fd0c20c3b1.tar.bz2
rails-fe30211574648fa21bff958a3cf952fd0c20c3b1.zip
Add database_exists? method to connection adapters
When SQLite connects it will silently create a database if the database does not exist. This behaviour causes different issues because of inconsistent behaviour between adapters: #36383, #32914. This commit adds a `database_exists?` method as a way to check the database without creating it. This is a stepping stone to fully resolving the above issues.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 6b18a12bce..82de52de50 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -259,6 +259,12 @@ module ActiveRecord
@use_insert_returning = @config.key?(:insert_returning) ? self.class.type_cast_config_to_boolean(@config[:insert_returning]) : true
end
+ def self.database_exists?(config)
+ !!ActiveRecord::Base.postgresql_connection(config)
+ rescue ActiveRecord::NoDatabaseError
+ false
+ end
+
# Is this connection alive and ready for queries?
def active?
@lock.synchronize do