diff options
author | Dave Lee <davelee.com@gmail.com> | 2013-11-30 16:01:34 -0700 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-04-02 10:47:15 +0200 |
commit | def60710ad74132a322fe8a08b0a6f0bbd3a3eed (patch) | |
tree | 458fe11ba5a735c71426dbe705718610cd8d4beb /activerecord/lib | |
parent | f159b0a5a8e0c43942e8d60eb27a51f2679afa3e (diff) | |
download | rails-def60710ad74132a322fe8a08b0a6f0bbd3a3eed.tar.gz rails-def60710ad74132a322fe8a08b0a6f0bbd3a3eed.tar.bz2 rails-def60710ad74132a322fe8a08b0a6f0bbd3a3eed.zip |
PostgreSQL, Support for materialized views. [Dave Lee & Yves Senn]
Expand the query used in #table_exists? to include materialized views in the
kinds of relations it searches.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb | 5 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 4 |
2 files changed, 5 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index e0afa989cd..50a73aa666 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -104,14 +104,11 @@ module ActiveRecord schema, table = Utils.extract_schema_and_table(name.to_s) return false unless table - binds = [[nil, table]] - binds << [nil, schema] if schema - exec_query(<<-SQL, 'SCHEMA').rows.first[0].to_i > 0 SELECT COUNT(*) FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace - WHERE c.relkind in ('v','r') + WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view AND c.relname = '#{table.gsub(/(^"|"$)/,'')}' AND n.nspname = #{schema ? "'#{schema}'" : 'ANY (current_schemas(false))'} SQL diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 748436de12..9fe8e0497e 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -454,6 +454,10 @@ module ActiveRecord postgresql_version >= 90200 end + def supports_materialized_views? + postgresql_version >= 90300 + end + def enable_extension(name) exec_query("CREATE EXTENSION IF NOT EXISTS \"#{name}\"").tap { reload_type_map |