When generating a new migration using bin/rails g migration CreateUser
the first line will look like this:
class CreateUser < ActiveRecord::Migration[5.1]
What does the [5.1]
stand for and how does it work?
This is a follow up on What’s does the [5.0] in Rails 5’s ActiveRecord::Migration mean? as it does not explain how this is legal ruby and does not show up in search using [5.1]
or brackets
This is the new migration versioning introduced with Rails 5. The number indicates the migration version the migration was created with, in this case version 5.1
and should be used with Rails versions >= 5.0
.
This is a class function def self.[](version)
of the ActiveRecord::Migration
, which calls Compatibility.find(version)
and is used for backward compatibility.
Here are the code references from GitHub:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With