aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_adapter.rb6
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb19
2 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index cbb6869e66..b2ad4e600d 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -171,6 +171,12 @@ module ActiveRecord
false
end
+ # Does this adapter support database extensions? As of this writing
+ # only postgresql does.
+ def supports_extensions?
+ false
+ end
+
# QUOTING ==================================================
# Returns a bind substitution value given a +column+ and list of current
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 209553b26e..a2b32bf3e2 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -575,11 +575,30 @@ module ActiveRecord
true
end
+ # Returns true.
+ def supports_extensions?
+ postgresql_version >= 90200
+ end
+
# Range datatypes weren't introduced until PostgreSQL 9.2
def supports_ranges?
postgresql_version >= 90200
end
+ def enable_extension(name)
+ exec_query "CREATE EXTENSION IF NOT EXISTS #{name}"
+ end
+
+ def disable_extension(name)
+ exec_query "DROP EXTENSION IF EXISTS #{name} CASCADE"
+ end
+
+ def extension_enabled?(name)
+ res = exec_query "SELECT EXISTS(SELECT * FROM pg_available_extensions WHERE name = '#{name}' AND installed_version IS NOT NULL)",
+ 'SCHEMA'
+ res.column_types['exists'].type_cast res.rows.first.first
+ end
+
# Returns the configured supported identifier length supported by PostgreSQL
def table_alias_length
@table_alias_length ||= query('SHOW max_identifier_length', 'SCHEMA')[0][0].to_i