提交 36f28fd8 编写于 作者: Y Yannick Schutz 提交者: Ryuta Kamizono

PostgreSQL 10 new relkind for partitioned tables (#31336)

* PostgreSQL 10 new relkind for partitioned tables

Starting with PostgreSQL 10, we can now have partitioned tables natively

* Add comment

* Remove extra space

* Add test for partition table in postgreSQL10

* Select 'p' for "BASE TABLE" and add a test case
to support PostgreSQL 10 partition tables

* Address RuboCop offense

* Addressed incorrect `postgresql_version`

Fixes #33008.

[Yannick Schutz & Yasuo Honda & Ryuta Kamizono]
上级 b4d91bb4
...@@ -751,7 +751,7 @@ def add_options_for_index_columns(quoted_columns, **options) ...@@ -751,7 +751,7 @@ def add_options_for_index_columns(quoted_columns, **options)
def data_source_sql(name = nil, type: nil) def data_source_sql(name = nil, type: nil)
scope = quoted_scope(name, type: type) scope = quoted_scope(name, type: type)
scope[:type] ||= "'r','v','m','f'" # (r)elation/table, (v)iew, (m)aterialized view, (f)oreign table scope[:type] ||= "'r','v','m','p','f'" # (r)elation/table, (v)iew, (m)aterialized view, (p)artitioned table, (f)oreign table
sql = "SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace".dup 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]}" sql << " WHERE n.nspname = #{scope[:schema]}"
...@@ -765,7 +765,7 @@ def quoted_scope(name = nil, type: nil) ...@@ -765,7 +765,7 @@ def quoted_scope(name = nil, type: nil)
type = \ type = \
case type case type
when "BASE TABLE" when "BASE TABLE"
"'r'" "'r','p'"
when "VIEW" when "VIEW"
"'v','m'" "'v','m'"
when "FOREIGN TABLE" when "FOREIGN TABLE"
......
# frozen_string_literal: true
require "cases/helper"
class PostgreSQLPartitionsTest < ActiveRecord::PostgreSQLTestCase
def setup
@connection = ActiveRecord::Base.connection
end
def teardown
@connection.drop_table "partitioned_events", if_exists: true
end
def test_partitions_table_exists
skip unless ActiveRecord::Base.connection.postgresql_version >= 100000
@connection.create_table :partitioned_events, force: true, id: false,
options: "partition by range (issued_at)" do |t|
t.timestamp :issued_at
end
assert @connection.table_exists?("partitioned_events")
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册