Class: ActiveRecord::Migration::Compatibility::V5_0
- Defined in:
- lib/active_record/migration/compatibility.rb
Direct Known Subclasses
Defined Under Namespace
Modules: TableDefinition
Instance Method Summary collapse
- #add_column(table_name, column_name, type, **options) ⇒ Object
- #add_reference(table_name, ref_name, **options) ⇒ Object (also: #add_belongs_to)
- #create_join_table(table_1, table_2, column_options: {}, **options) ⇒ Object
- #create_table(table_name, **options) ⇒ Object
Methods inherited from V5_1
Methods inherited from V5_2
Methods inherited from V6_1
Instance Method Details
#add_column(table_name, column_name, type, **options) ⇒ Object
251 252 253 254 255 256 257 258 259 |
# File 'lib/active_record/migration/compatibility.rb', line 251 def add_column(table_name, column_name, type, **) if type == :primary_key type = :integer [:primary_key] = true elsif type == :datetime [:precision] ||= nil end super end |
#add_reference(table_name, ref_name, **options) ⇒ Object Also known as: add_belongs_to
261 262 263 |
# File 'lib/active_record/migration/compatibility.rb', line 261 def add_reference(table_name, ref_name, **) super(table_name, ref_name, type: :integer, **) end |
#create_join_table(table_1, table_2, column_options: {}, **options) ⇒ Object
246 247 248 249 |
# File 'lib/active_record/migration/compatibility.rb', line 246 def create_join_table(table_1, table_2, column_options: {}, **) .reverse_merge!(type: :integer) super end |
#create_table(table_name, **options) ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/active_record/migration/compatibility.rb', line 223 def create_table(table_name, **) if connection.adapter_name == "PostgreSQL" if [:id] == :uuid && !.key?(:default) [:default] = "uuid_generate_v4()" end end unless connection.adapter_name == "Mysql2" && [:id] == :bigint if [:integer, :bigint].include?([:id]) && !.key?(:default) [:default] = nil end end # Since 5.1 PostgreSQL adapter uses bigserial type for primary # keys by default and MySQL uses bigint. This compat layer makes old migrations utilize # serial/int type instead -- the way it used to work before 5.1. unless .key?(:id) [:id] = :integer end super end |