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:
Hartley McGuire 2023-08-22 23:59:42 -04:00
parent ec67f71b33
commit c793cdc665
No known key found for this signature in database
GPG Key ID: E823FC1403858A82
2 changed files with 33 additions and 77 deletions

@ -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