diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-01-26 20:56:10 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-01-26 21:19:20 +0900 |
commit | 5fe6d3747efd37d7d8c6c9d6557d7b623e0398e8 (patch) | |
tree | 2aa826cf2fbd300e746b0f3e70c60f682d1b01aa /activerecord/test | |
parent | 17901d876460f013c22dd155a148bbf7671433e2 (diff) | |
download | rails-5fe6d3747efd37d7d8c6c9d6557d7b623e0398e8.tar.gz rails-5fe6d3747efd37d7d8c6c9d6557d7b623e0398e8.tar.bz2 rails-5fe6d3747efd37d7d8c6c9d6557d7b623e0398e8.zip |
Fix `t.timestamps` missing `null: false` in `change_table bulk: true`
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/ar_schema_test.rb | 15 | ||||
-rw-r--r-- | activerecord/test/cases/migration/compatibility_test.rb | 17 |
2 files changed, 32 insertions, 0 deletions
diff --git a/activerecord/test/cases/ar_schema_test.rb b/activerecord/test/cases/ar_schema_test.rb index 8e796a6f13..98af75e8ca 100644 --- a/activerecord/test/cases/ar_schema_test.rb +++ b/activerecord/test/cases/ar_schema_test.rb @@ -133,6 +133,21 @@ class ActiveRecordSchemaTest < ActiveRecord::TestCase assert @connection.column_exists?(:has_timestamps, :updated_at, null: false) end + if ActiveRecord::Base.connection.supports_bulk_alter? + def test_timestamps_without_null_set_null_to_false_on_change_table_with_bulk + ActiveRecord::Schema.define do + create_table :has_timestamps + + change_table :has_timestamps, bulk: true do |t| + t.timestamps default: Time.now + end + end + + assert @connection.column_exists?(:has_timestamps, :created_at, null: false) + assert @connection.column_exists?(:has_timestamps, :updated_at, null: false) + end + end + def test_timestamps_without_null_set_null_to_false_on_add_timestamps ActiveRecord::Schema.define do create_table :has_timestamps diff --git a/activerecord/test/cases/migration/compatibility_test.rb b/activerecord/test/cases/migration/compatibility_test.rb index 667c118d9a..418793d1af 100644 --- a/activerecord/test/cases/migration/compatibility_test.rb +++ b/activerecord/test/cases/migration/compatibility_test.rb @@ -107,6 +107,23 @@ module ActiveRecord assert connection.column_exists?(:testings, :updated_at, null: true) end + if ActiveRecord::Base.connection.supports_bulk_alter? + def test_timestamps_have_null_constraints_if_not_present_in_migration_of_change_table_with_bulk + migration = Class.new(ActiveRecord::Migration[4.2]) { + def migrate(x) + change_table :testings, bulk: true do |t| + t.timestamps + end + end + }.new + + ActiveRecord::Migrator.new(:up, [migration]).migrate + + assert connection.column_exists?(:testings, :created_at, null: true) + assert connection.column_exists?(:testings, :updated_at, null: true) + end + end + def test_timestamps_have_null_constraints_if_not_present_in_migration_for_adding_timestamps_to_existing_table migration = Class.new(ActiveRecord::Migration[4.2]) { def migrate(x) |