Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the brackets [5.1] after ActiveRecord Migration and how does it work? [duplicate]

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

like image 667
dfherr Avatar asked Mar 07 '23 16:03

dfherr


1 Answers

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:

  • ActiveRecord::Migration::[]
  • ActiveRecord::Migration::Compatibility
like image 117
dfherr Avatar answered May 03 '23 13:05

dfherr