diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-01-28 16:47:20 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-01-28 16:47:40 -0800 |
commit | 439ac72013fc1b819e711d66642b0b5b563fd72e (patch) | |
tree | 6050295500b3a28522f884206164f20f6a91c510 /activerecord/lib | |
parent | ba6cae4cc571fdf36a7a3cc5a2e6cdcdf3aaced4 (diff) | |
download | rails-439ac72013fc1b819e711d66642b0b5b563fd72e.tar.gz rails-439ac72013fc1b819e711d66642b0b5b563fd72e.tar.bz2 rails-439ac72013fc1b819e711d66642b0b5b563fd72e.zip |
add API to pg for enabling / disabling hstore
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 19 |
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 |