Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What’s does the [5.0] in Rails 5’s ActiveRecord::Migration mean?

Tags:

A migration I created in a Rails 5 application had 5.0 passed into a method:

class CreateVariableKeys < ActiveRecord::Migration[5.0]   ... end 

I would like to know what the [5.0] means.

like image 310
gnerkus Avatar asked Feb 09 '16 21:02

gnerkus


People also ask

What does migration do in rails?

A Rails migration is a tool for changing an application's database schema. Instead of managing SQL scripts, you define database changes in a domain-specific language (DSL). The code is database-independent, so you can easily move your app to a new platform.

What is Activerecord in Ruby on rails?

Active Record is the M in MVC - the model - which is the layer of the system responsible for representing business data and logic. Active Record facilitates the creation and use of business objects whose data requires persistent storage to a database.

What are migrations in Ruby on rails?

Migrations are a convenient way to alter your database schema over time in a consistent way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent. You can think of each migration as being a new 'version' of the database.

How do rails track migrations?

Every time a migration is generated using the rails g migration command, Rails generates the migration file with a unique timestamp. The timestamp is in the format YYYYMMDDHHMMSS . Whenever a migration is run, Rails inserts the migration timestamp into an internal table schema_migrations .


2 Answers

It is a class method of ActiveRecord::Migration and is defined here.

It allows us to select the version of migrations we wish to use between 4.2 and 5.0. The method throws a:

"Unknown migration version ... "

error if an incompatible version is passed as an argument.

Production ready versions of ActiveRecord don’t have that method so it should go away as soon as Rails 5 goes out of beta.

like image 115
gnerkus Avatar answered Sep 18 '22 17:09

gnerkus


This blog has more info too

It seems to be there so that you don't have to upgrade old migrations, when moving from rails 4 to rails 5. (There are some small changes in the migrations API).

like image 25
Andrew Avatar answered Sep 18 '22 17:09

Andrew