Module: ActiveRecord::ConnectionAdapters::ColumnDumper
- Included in:
- AbstractAdapter
- Defined in:
- lib/active_record/connection_adapters/abstract/schema_dumper.rb
Overview
The goal of this module is to move Adapter specific column definitions to the Adapter instead of having it in the schema dumper itself. This code represents the normal case. We can then redefine how certain data types may be handled in the schema dumper on the Adapter level by over-writing this code inside the database specific adapters
Instance Method Summary collapse
- #column_spec(column, types) ⇒ Object
-
#migration_keys ⇒ Object
Lists the valid migration options.
-
#prepare_column_options(column, types) ⇒ Object
This can be overridden on a Adapter level basis to support other extended datatypes (Example: Adding an array option in the PostgreSQLAdapter).
Instance Method Details
#column_spec(column, types) ⇒ Object
11 12 13 14 15 |
# File 'lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 11 def column_spec(column, types) spec = (column, types) (spec.keys - [:name, :type]).each{ |k| spec[k].insert(0, "#{k.to_s}: ")} spec end |
#migration_keys ⇒ Object
Lists the valid migration options
40 41 42 |
# File 'lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 40 def migration_keys [:name, :limit, :precision, :scale, :default, :null] end |
#prepare_column_options(column, types) ⇒ Object
This can be overridden on a Adapter level basis to support other extended datatypes (Example: Adding an array option in the PostgreSQLAdapter)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 20 def (column, types) spec = {} spec[:name] = column.name.inspect # AR has an optimization which handles zero-scale decimals as integers. This # code ensures that the dumper still dumps the column as a decimal. spec[:type] = if column.type == :integer && /^(numeric|decimal)/ =~ column.sql_type 'decimal' else column.type.to_s end spec[:limit] = column.limit.inspect if column.limit != types[column.type][:limit] && spec[:type] != 'decimal' spec[:precision] = column.precision.inspect if column.precision spec[:scale] = column.scale.inspect if column.scale spec[:null] = 'false' unless column.null spec[:default] = default_string(column.default) if column.has_default? spec end |