aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-01-28 16:47:20 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2013-01-28 16:47:40 -0800
commit439ac72013fc1b819e711d66642b0b5b563fd72e (patch)
tree6050295500b3a28522f884206164f20f6a91c510 /activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
parentba6cae4cc571fdf36a7a3cc5a2e6cdcdf3aaced4 (diff)
downloadrails-439ac72013fc1b819e711d66642b0b5b563fd72e.tar.gz
rails-439ac72013fc1b819e711d66642b0b5b563fd72e.tar.bz2
rails-439ac72013fc1b819e711d66642b0b5b563fd72e.zip
add API to pg for enabling / disabling hstore
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb19
1 files changed, 19 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 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