diff --git a/activerecord/test/cases/adapters/postgresql/enum_test.rb b/activerecord/test/cases/adapters/postgresql/enum_test.rb index 47ea79842e..a0559a3a5a 100644 --- a/activerecord/test/cases/adapters/postgresql/enum_test.rb +++ b/activerecord/test/cases/adapters/postgresql/enum_test.rb @@ -122,6 +122,8 @@ def test_schema_dump_renamed_enum end def test_schema_dump_added_enum_value + skip("Adding enum values can not be run in a transaction") if @connection.database_version < 10_00_00 + @connection.add_enum_value :mood, :angry, before: :ok @connection.add_enum_value :mood, :nervous, after: :ok @connection.add_enum_value :mood, :glad @@ -132,6 +134,8 @@ def test_schema_dump_added_enum_value end def test_schema_dump_renamed_enum_value + skip("Renaming enum values is only supported in PostgreSQL 10 or later") if @connection.database_version < 10_00_00 + @connection.rename_enum_value :mood, from: :ok, to: :okay output = dump_table_schema("postgresql_enums") diff --git a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb index f70d38aac8..75faae9b7a 100644 --- a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb +++ b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb @@ -330,19 +330,21 @@ def test_partial_index_on_column_named_like_keyword end end - def test_include_index - with_example_table do - @connection.add_index "ex", %w{ id }, name: "include", include: :number - index = @connection.indexes("ex").find { |idx| idx.name == "include" } - assert_equal ["number"], index.include + if supports_index_include? + def test_include_index + with_example_table do + @connection.add_index "ex", %w{ id }, name: "include", include: :number + index = @connection.indexes("ex").find { |idx| idx.name == "include" } + assert_equal ["number"], index.include + end end - end - def test_include_multiple_columns_index - with_example_table do - @connection.add_index "ex", %w{ id }, name: "include", include: [:number, :data] - index = @connection.indexes("ex").find { |idx| idx.name == "include" } - assert_equal ["number", "data"], index.include + def test_include_multiple_columns_index + with_example_table do + @connection.add_index "ex", %w{ id }, name: "include", include: [:number, :data] + index = @connection.indexes("ex").find { |idx| idx.name == "include" } + assert_equal ["number", "data"], index.include + end end end diff --git a/activerecord/test/cases/adapters/postgresql/referential_integrity_test.rb b/activerecord/test/cases/adapters/postgresql/referential_integrity_test.rb index ee48c5b550..7223dd1874 100644 --- a/activerecord/test/cases/adapters/postgresql/referential_integrity_test.rb +++ b/activerecord/test/cases/adapters/postgresql/referential_integrity_test.rb @@ -108,7 +108,7 @@ def test_all_foreign_keys_valid_having_foreign_keys_in_multiple_schemas CREATE SCHEMA referential_integrity_test_schema; CREATE TABLE referential_integrity_test_schema.nodes ( - id INT GENERATED ALWAYS AS IDENTITY, + id BIGSERIAL, parent_id INT NOT NULL, PRIMARY KEY(id), CONSTRAINT fk_parent_node FOREIGN KEY(parent_id) diff --git a/activerecord/test/cases/adapters/postgresql/schema_test.rb b/activerecord/test/cases/adapters/postgresql/schema_test.rb index e52ee907be..2c94f2aa30 100644 --- a/activerecord/test/cases/adapters/postgresql/schema_test.rb +++ b/activerecord/test/cases/adapters/postgresql/schema_test.rb @@ -785,7 +785,7 @@ def test_schema_dumps_index_included_columns if ActiveRecord::Base.connection.supports_index_include? assert_equal 't.index ["firm_id", "type"], name: "company_include_index", include: ["name", "account_id"]', index_definition else - assert_equal 't.index ["firm_ids", "type"], name: "company_include_index"', index_definition + assert_equal 't.index ["firm_id", "type"], name: "company_include_index"', index_definition end end end diff --git a/activerecord/test/cases/defaults_test.rb b/activerecord/test/cases/defaults_test.rb index 8d281a9a44..3a94d5d6b4 100644 --- a/activerecord/test/cases/defaults_test.rb +++ b/activerecord/test/cases/defaults_test.rb @@ -152,14 +152,16 @@ class PostgresqlDefaultExpressionTest < ActiveRecord::TestCase if ActiveRecord::Base.connection.database_version >= 100000 assert_match %r/t\.date\s+"modified_date",\s+default: -> { "CURRENT_DATE" }/, output assert_match %r/t\.datetime\s+"modified_time",\s+default: -> { "CURRENT_TIMESTAMP" }/, output + assert_match %r/t\.datetime\s+"modified_time_without_precision",\s+precision: nil,\s+default: -> { "CURRENT_TIMESTAMP" }/, output + assert_match %r/t\.datetime\s+"modified_time_with_precision_0",\s+precision: 0,\s+default: -> { "CURRENT_TIMESTAMP" }/, output else assert_match %r/t\.date\s+"modified_date",\s+default: -> { "\('now'::text\)::date" }/, output assert_match %r/t\.datetime\s+"modified_time",\s+default: -> { "now\(\)" }/, output + assert_match %r/t\.datetime\s+"modified_time_without_precision",\s+precision: nil,\s+default: -> { "now\(\)" }/, output + assert_match %r/t\.datetime\s+"modified_time_with_precision_0",\s+precision: 0,\s+default: -> { "now\(\)" }/, output end assert_match %r/t\.date\s+"modified_date_function",\s+default: -> { "now\(\)" }/, output assert_match %r/t\.datetime\s+"modified_time_function",\s+default: -> { "now\(\)" }/, output - assert_match %r/t\.datetime\s+"modified_time_without_precision",\s+precision: nil,\s+default: -> { "CURRENT_TIMESTAMP" }/, output - assert_match %r/t\.datetime\s+"modified_time_with_precision_0",\s+precision: 0,\s+default: -> { "CURRENT_TIMESTAMP" }/, output end end end diff --git a/activerecord/test/cases/migration/index_test.rb b/activerecord/test/cases/migration/index_test.rb index 95e262ec98..0b56300612 100644 --- a/activerecord/test/cases/migration/index_test.rb +++ b/activerecord/test/cases/migration/index_test.rb @@ -277,6 +277,8 @@ def test_add_partial_index end def test_add_index_with_included_column + skip("current adapter doesn't support include indexes") unless supports_index_include? + connection.add_index("testings", "last_name", include: :foo) assert connection.index_exists?("testings", "last_name", include: :foo) @@ -285,6 +287,8 @@ def test_add_index_with_included_column end def test_add_index_with_multiple_included_columns + skip("current adapter doesn't support include indexes") unless supports_index_include? + connection.add_index("testings", "last_name", include: [:foo, :bar]) assert connection.index_exists?("testings", "last_name", include: [:foo, :bar]) @@ -293,6 +297,8 @@ def test_add_index_with_multiple_included_columns end def test_add_index_with_included_column_and_where_clause + skip("current adapter doesn't support include indexes") unless supports_index_include? + connection.add_index("testings", "last_name", include: :foo, where: "first_name = 'john doe'") assert connection.index_exists?("testings", "last_name", include: :foo, where: "first_name = 'john doe'") diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index 5e00aaaa5f..0aa3c0634c 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -47,7 +47,11 @@ def test_fills_auto_populated_columns_on_creation record_with_defaults = Default.create assert_not_nil record_with_defaults.id assert_equal "Ruby on Rails", record_with_defaults.ruby_on_rails - assert_not_nil record_with_defaults.virtual_stored_number if current_adapter?(:PostgreSQLAdapter) + + if current_adapter?(:PostgreSQLAdapter) && ActiveRecord::Base.connection.supports_virtual_columns? + assert_not_nil record_with_defaults.virtual_stored_number + end + assert_not_nil record_with_defaults.random_number assert_not_nil record_with_defaults.modified_date assert_not_nil record_with_defaults.modified_date_function diff --git a/activerecord/test/schema/postgresql_specific_schema.rb b/activerecord/test/schema/postgresql_specific_schema.rb index 1c78c1125e..611f200c40 100644 --- a/activerecord/test/schema/postgresql_specific_schema.rb +++ b/activerecord/test/schema/postgresql_specific_schema.rb @@ -25,7 +25,7 @@ end create_table :defaults, force: true do |t| - t.virtual :virtual_stored_number, type: :integer, as: "random_number * 10", stored: true + t.virtual :virtual_stored_number, type: :integer, as: "random_number * 10", stored: true if supports_virtual_columns? t.integer :random_number, default: -> { "random() * 100" } t.string :ruby_on_rails, default: -> { "concat('Ruby ', 'on ', 'Rails')" } t.date :modified_date, default: -> { "CURRENT_DATE" } @@ -184,7 +184,5 @@ options: "PARTITION OF measurements FOR VALUES IN (2)") end - if supports_index_include? - add_index(:companies, [:firm_id, :type], name: "company_include_index", include: [:name, :account_id]) - end + add_index(:companies, [:firm_id, :type], name: "company_include_index", include: [:name, :account_id]) end diff --git a/activerecord/test/support/adapter_helper.rb b/activerecord/test/support/adapter_helper.rb index a7170949f3..bd14a6e906 100644 --- a/activerecord/test/support/adapter_helper.rb +++ b/activerecord/test/support/adapter_helper.rb @@ -49,6 +49,7 @@ def supports_text_column_with_default? supports_partial_index? supports_partitioned_indexes? supports_expression_index? + supports_index_include? supports_insert_returning? supports_insert_on_duplicate_skip? supports_insert_on_duplicate_update?