aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql/column.rb20
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql/type_metadata.rb7
-rw-r--r--activerecord/lib/active_record/schema_dumper.rb48
4 files changed, 43 insertions, 34 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
index f09c9c9e7f..3a28879c15 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -709,7 +709,7 @@ module ActiveRecord
end
def fetch_type_metadata(sql_type, extra = "")
- MySQL::TypeMetadata.new(super(sql_type), extra: extra, strict: strict_mode?)
+ MySQL::TypeMetadata.new(super(sql_type), extra: extra)
end
def add_index_length(quoted_columns, **options)
diff --git a/activerecord/lib/active_record/connection_adapters/mysql/column.rb b/activerecord/lib/active_record/connection_adapters/mysql/column.rb
index 5452e44c84..72b57f4b8f 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql/column.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql/column.rb
@@ -2,17 +2,7 @@ module ActiveRecord
module ConnectionAdapters
module MySQL
class Column < ConnectionAdapters::Column # :nodoc:
- delegate :strict, :extra, to: :sql_type_metadata, allow_nil: true
-
- def initialize(*)
- super
- extract_default
- end
-
- def has_default?
- return false if blob_or_text_column? # MySQL forbids defaults on blob and text columns
- super
- end
+ delegate :extra, to: :sql_type_metadata, allow_nil: true
def blob_or_text_column?
/\A(?:tiny|medium|long)?blob\b/ === sql_type || type == :text
@@ -29,14 +19,6 @@ module ActiveRecord
def auto_increment?
extra == "auto_increment"
end
-
- private
-
- def extract_default
- if blob_or_text_column?
- @default = null || strict ? nil : ""
- end
- end
end
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/mysql/type_metadata.rb b/activerecord/lib/active_record/connection_adapters/mysql/type_metadata.rb
index 1be5cb4740..24dcf852e1 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql/type_metadata.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql/type_metadata.rb
@@ -2,13 +2,12 @@ module ActiveRecord
module ConnectionAdapters
module MySQL
class TypeMetadata < DelegateClass(SqlTypeMetadata) # :nodoc:
- attr_reader :extra, :strict
+ attr_reader :extra
- def initialize(type_metadata, extra: "", strict: false)
+ def initialize(type_metadata, extra: "")
super(type_metadata)
@type_metadata = type_metadata
@extra = extra
- @strict = strict
end
def ==(other)
@@ -24,7 +23,7 @@ module ActiveRecord
protected
def attributes_for_hash
- [self.class, @type_metadata, extra, strict]
+ [self.class, @type_metadata, extra]
end
end
end
diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb
index 01f788a424..be74922453 100644
--- a/activerecord/lib/active_record/schema_dumper.rb
+++ b/activerecord/lib/active_record/schema_dumper.rb
@@ -16,6 +16,22 @@ module ActiveRecord
cattr_accessor :ignore_tables
@@ignore_tables = []
+ ##
+ # :singleton-method:
+ # Define whether column arguments are lined up in dump.
+ # Acceptable values are true or false.
+ # This setting is only used if ActiveRecord::Base.schema_format == :ruby
+ cattr_accessor :standardized_argument_widths
+ @@standardized_argument_widths = true
+
+ ##
+ # :singleton-method:
+ # Define whether columns types are lined up in dump.
+ # Acceptable values are true or false.
+ # This setting is only used if ActiveRecord::Base.schema_format == :ruby
+ cattr_accessor :standardized_type_widths
+ @@standardized_type_widths = true
+
class << self
def dump(connection=ActiveRecord::Base.connection, stream=STDOUT, config = ActiveRecord::Base)
new(connection, generate_options(config)).dump(stream)
@@ -146,20 +162,32 @@ HEADER
keys = @connection.migration_keys
# figure out the lengths for each column based on above keys
- lengths = keys.map { |key|
- column_specs.map { |spec|
- spec[key] ? spec[key].length + 2 : 0
- }.max
- }
+ lengths = if standardized_argument_widths
+ keys.map { |key|
+ column_specs.map { |spec|
+ spec[key] ? spec[key].length + 2 : 0
+ }.max
+ }
+ else
+ [0] * keys.length
+ end
# the string we're going to sprintf our values against, with standardized column widths
- format_string = lengths.map { |len| "%-#{len}s" }
-
- # find the max length for the 'type' column, which is special
- type_length = column_specs.map { |column| column[:type].length }.max
+ format_string = if standardized_argument_widths
+ lengths.map { |len| "%-#{len}s" }
+ else
+ ["%s"] * keys.length
+ end
# add column type definition to our format string
- format_string.unshift " t.%-#{type_length}s "
+ if standardized_type_widths
+ # find the max length for the 'type' column, which is special
+ type_length = column_specs.map { |column| column[:type].length }.max
+
+ format_string.unshift " t.%-#{type_length}s "
+ else
+ format_string.unshift " t.%s "
+ end
format_string *= ""