diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-01-18 09:57:10 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-01-26 22:49:14 +0900 |
commit | 57015cdfa2083351f64a82f7566965172a41efcb (patch) | |
tree | d6f859c2cfbc7b8bc7ba85c3de0efb5bba0a70e4 /activerecord/lib/active_record/migration/compatibility.rb | |
parent | 5fe6d3747efd37d7d8c6c9d6557d7b623e0398e8 (diff) | |
download | rails-57015cdfa2083351f64a82f7566965172a41efcb.tar.gz rails-57015cdfa2083351f64a82f7566965172a41efcb.tar.bz2 rails-57015cdfa2083351f64a82f7566965172a41efcb.zip |
Make `t.timestamps` with precision by default
Diffstat (limited to 'activerecord/lib/active_record/migration/compatibility.rb')
-rw-r--r-- | activerecord/lib/active_record/migration/compatibility.rb | 95 |
1 files changed, 47 insertions, 48 deletions
diff --git a/activerecord/lib/active_record/migration/compatibility.rb b/activerecord/lib/active_record/migration/compatibility.rb index 608182e363..94906a2943 100644 --- a/activerecord/lib/active_record/migration/compatibility.rb +++ b/activerecord/lib/active_record/migration/compatibility.rb @@ -16,13 +16,55 @@ module ActiveRecord V6_0 = Current class V5_2 < V6_0 + module TableDefinition + def timestamps(**options) + options[:precision] ||= nil + super + end + end + module CommandRecorder def invert_transaction(args, &block) [:transaction, args, block] end end + def create_table(table_name, **options) + if block_given? + super { |t| yield compatible_table_definition(t) } + else + super + end + end + + def change_table(table_name, **options) + if block_given? + super { |t| yield compatible_table_definition(t) } + else + super + end + end + + def create_join_table(table_1, table_2, **options) + if block_given? + super { |t| yield compatible_table_definition(t) } + else + super + end + end + + def add_timestamps(table_name, **options) + options[:precision] ||= nil + super + end + private + def compatible_table_definition(t) + class << t + prepend TableDefinition + end + t + end def command_recorder recorder = super @@ -87,35 +129,12 @@ module ActiveRecord options[:id] = :integer end - if block_given? - super do |t| - yield compatible_table_definition(t) - end - else - super - end - end - - def change_table(table_name, options = {}) - if block_given? - super do |t| - yield compatible_table_definition(t) - end - else - super - end + super end def create_join_table(table_1, table_2, column_options: {}, **options) column_options.reverse_merge!(type: :integer) - - if block_given? - super do |t| - yield compatible_table_definition(t) - end - else - super - end + super end def add_column(table_name, column_name, type, options = {}) @@ -136,7 +155,7 @@ module ActiveRecord class << t prepend TableDefinition end - t + super end end @@ -154,33 +173,13 @@ module ActiveRecord end end - def create_table(table_name, options = {}) - if block_given? - super do |t| - yield compatible_table_definition(t) - end - else - super - end - end - - def change_table(table_name, options = {}) - if block_given? - super do |t| - yield compatible_table_definition(t) - end - else - super - end - end - - def add_reference(*, **options) + def add_reference(table_name, ref_name, **options) options[:index] ||= false super end alias :add_belongs_to :add_reference - def add_timestamps(_, **options) + def add_timestamps(table_name, **options) options[:null] = true if options[:null].nil? super end |