Skip to content

Commit

Permalink
Merge pull request #49012 from skipkayhil/hm-migration-table-def-methods
Browse files Browse the repository at this point in the history
Ensure all migration versions use TableDefinition
  • Loading branch information
rafaelfranca committed Aug 23, 2023
2 parents dd6d931 + c793cdc commit c70ac1d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 77 deletions.
32 changes: 32 additions & 0 deletions activerecord/lib/active_record/migration.rb
Expand Up @@ -559,6 +559,38 @@ class Migration

# This must be defined before the inherited hook, below
class Current < Migration # :nodoc:
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 drop_table(table_name, **options)
if block_given?
super { |t| yield compatible_table_definition(t) }
else
super
end
end

def compatible_table_definition(t)
t
end
Expand Down
78 changes: 1 addition & 77 deletions activerecord/lib/active_record/migration/compatibility.rb
Expand Up @@ -99,19 +99,7 @@ def create_table(table_name, **options)
options[:_uses_legacy_table_name] = true
options[:_skip_validate_options] = true

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
super
end

def rename_table(table_name, new_name, **options)
Expand Down Expand Up @@ -187,22 +175,6 @@ def change_column(table_name, column_name, type, **options)
super
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

module TableDefinition
def new_column_definition(name, type, **options)
type = PostgreSQLCompat.compatible_timestamp_type(type, @conn)
Expand Down Expand Up @@ -257,30 +229,6 @@ def raise_on_if_exist_options(options)
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_reference(table_name, ref_name, **options)
if connection.adapter_name == "SQLite"
options[:type] = :integer
Expand Down Expand Up @@ -334,30 +282,6 @@ def invert_change_table_comment(args)
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
Expand Down

0 comments on commit c70ac1d

Please sign in to comment.