diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-01-23 05:44:16 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-23 05:44:16 +0900 |
commit | 742c9ba92ac5aaa3adcbdc9bf708b1e578ce66f6 (patch) | |
tree | ece940d1e4268839092dbcec2998c0746c2418f2 /activerecord/lib | |
parent | 7ca3ab415d409ba39b07ff5a96da06d68098069b (diff) | |
parent | 3ad2f9921a10397090882de23f3e8fb971b8f027 (diff) | |
download | rails-742c9ba92ac5aaa3adcbdc9bf708b1e578ce66f6.tar.gz rails-742c9ba92ac5aaa3adcbdc9bf708b1e578ce66f6.tar.bz2 rails-742c9ba92ac5aaa3adcbdc9bf708b1e578ce66f6.zip |
Merge pull request #31549 from fatkodima/foreign_tables
Support for PostgreSQL foreign tables
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb | 12 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 4 |
2 files changed, 15 insertions, 1 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 c6e5122daf..b9d2f4da39 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -527,6 +527,14 @@ module ActiveRecord end end + def foreign_tables + query_values(data_source_sql(type: "FOREIGN TABLE"), "SCHEMA") + end + + def foreign_table_exists?(table_name) + query_values(data_source_sql(table_name, type: "FOREIGN TABLE"), "SCHEMA").any? if table_name.present? + end + # Maps logical Rails types to PostgreSQL-specific data types. def type_to_sql(type, limit: nil, precision: nil, scale: nil, array: nil, **) # :nodoc: sql = \ @@ -739,7 +747,7 @@ module ActiveRecord def data_source_sql(name = nil, type: nil) scope = quoted_scope(name, type: type) - scope[:type] ||= "'r','v','m'" # (r)elation/table, (v)iew, (m)aterialized view + scope[:type] ||= "'r','v','m','f'" # (r)elation/table, (v)iew, (m)aterialized view, (f)oreign table sql = "SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace".dup sql << " WHERE n.nspname = #{scope[:schema]}" @@ -756,6 +764,8 @@ module ActiveRecord "'r'" when "VIEW" "'v','m'" + when "FOREIGN TABLE" + "'f'" end scope = {} scope[:schema] = schema ? quote(schema) : "ANY (current_schemas(false))" diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 9ac5a8760e..ddc5a91286 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -318,6 +318,10 @@ module ActiveRecord postgresql_version >= 90300 end + def supports_foreign_tables? + postgresql_version >= 90300 + end + def supports_pgcrypto_uuid? postgresql_version >= 90400 end |