diff options
author | Matthew Draper <matthew@trebex.net> | 2015-12-15 17:47:28 +1030 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2015-12-15 17:47:28 +1030 |
commit | cd90f4f273071fd20ff6e4ce34c33171923733b4 (patch) | |
tree | f29f9a0aec8432846199ccd69e1f975b95321b4b /activerecord/lib/active_record/migration | |
parent | de2135209f39a4d336916feceab972bc89dc93de (diff) | |
parent | 97c77160cd4c8b32a6572adefa268eb91162e3e1 (diff) | |
download | rails-cd90f4f273071fd20ff6e4ce34c33171923733b4.tar.gz rails-cd90f4f273071fd20ff6e4ce34c33171923733b4.tar.bz2 rails-cd90f4f273071fd20ff6e4ce34c33171923733b4.zip |
Merge pull request #21538 from matthewd/migration-version
Add migration versioning via Migration subclasses
Diffstat (limited to 'activerecord/lib/active_record/migration')
-rw-r--r-- | activerecord/lib/active_record/migration/compatibility.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/migration/compatibility.rb b/activerecord/lib/active_record/migration/compatibility.rb new file mode 100644 index 0000000000..4c8db8a2d5 --- /dev/null +++ b/activerecord/lib/active_record/migration/compatibility.rb @@ -0,0 +1,54 @@ +module ActiveRecord + class Migration + module Compatibility # :nodoc: all + V5_0 = Current + + module FourTwoShared + module TableDefinition + def timestamps(*, **options) + options[:null] = true if options[:null].nil? + super + end + end + + def create_table(table_name, options = {}) + if block_given? + super(table_name, options) do |t| + class << t + prepend TableDefinition + end + yield t + end + else + super + end + end + + def add_timestamps(*, **options) + options[:null] = true if options[:null].nil? + super + end + end + + class V4_2 < V5_0 + # 4.2 is defined as a module because it needs to be shared with + # Legacy. When the time comes, V5_0 should be defined straight + # in its class. + include FourTwoShared + end + + module Legacy + include FourTwoShared + + def run(*) + ActiveSupport::Deprecation.warn \ + "Directly inheriting from ActiveRecord::Migration is deprecated. " \ + "Please specify the Rails release the migration was written for:\n" \ + "\n" \ + " class #{self.class.name} < ActiveRecord::Migration[4.2]" + super + end + end + end + end +end |