Ensure all migration versions use TableDefinition
This is similar to a [previous commit][1] which ensures that versioned migrations always call `super` in `compatible_table_definition`. In this case, these methods are being pulled up to `Current` so that all subclasses will use a `TableDefinition` class and future developers do not have to remember to add all of these methods to new versioned classes when a new one is created. [1]: 16f8bd79444a512dfebf2d77bd2fd3075041475b
This commit is contained in:
parent
ec67f71b33
commit
c793cdc665
@ -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
|
||||
|
@ -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)
|
||||
@ -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)
|
||||
@ -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
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user