From 5fe6d3747efd37d7d8c6c9d6557d7b623e0398e8 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sat, 26 Jan 2019 20:56:10 +0900 Subject: Fix `t.timestamps` missing `null: false` in `change_table bulk: true` --- activerecord/test/cases/ar_schema_test.rb | 15 +++++++++++++++ activerecord/test/cases/migration/compatibility_test.rb | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'activerecord/test') 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) -- cgit v1.2.3