ActiveRecord::Migration deprecation warning - asks for Rails version, but I'm not using Rails

Viewed 5122

This is a Ruby non-web project that uses ActiveRecord to talk to the database.

There is a single file which contains the db connection code, migration, and model. See here (but it's not necessary to read this to answer the question)

require 'sqlite3'
require 'active_record'
require 'yaml'
require 'active_support/all'
require 'securerandom'

BasePath = "#{File.dirname(__FILE__)}/.."
DATABASE_FILENAME = "database.sqlite"
DATABASE_PATH = "#{BasePath}/#{DATABASE_FILENAME}"
SQLite3::Database.new(DATABASE_PATH)
ActiveRecord::Base.establish_connection(
  adapter: 'sqlite3',
  database: DATABASE_PATH
)

class Migrations < ActiveRecord::Migration
  def up
    create_table :todos do |t|
      t.string :content
      t.boolean :completed
      t.timestamps null: false
    end
  end
  def down
    puts "backing up database".red_on_black if File.file?(DATABASE_PATH)
    loop { (`cp #{DATABASE_PATH} #{DATABASE_PATH}-#{SecureRandom.urlsafe_base64}.backup`; break) rescue next }
    sleep 0.5
    drop_table :todos
    puts "dropped todos table"
  end
end # Migrations

class Todo < ActiveRecord::Base
end

The question is about this line:

class Migrations < ActiveRecord::Migration

When I run the migration with Migrations.migrate(:up), I get a deprecation warning:

DEPRECATION WARNING: Directly inheriting from ActiveRecord::Migration is deprecated.
Please specify the Rails release the migration was written for:

  class Migrations < ActiveRecord::Migration[4.2]

Like it advises I change my class definition to

  class Migrations < ActiveRecord::Migration[4.2]

And then I no longer get the warning.

I'm wondering if anyone can explain the purpose of this.

My app doesn't depend on any version of Rails. Why would I need

to specify a Rails version?

2 Answers
Related