Jwan622
Jwan622

Reputation: 11659

rakefile questions with Sequel commands

I am looking over some code and I don't understand some lines. Here is the code:

require "bundler"
Bundler.require

namespace :db do
  desc "Setup database"
  task :setup do
    Sequel.extension :migration
    @database = Sequel.postgres "sequel-playground"
  end

  desc "Run migrations"
  task :migrate => [:setup] do
    Sequel::Migrator.run(@database, "db")
  end

  desc "Reset database"
  task :reset => [:setup] do
    Sequel::Migrator.run(@database, "db", :target => 0)
    Sequel::Migrator.run(@database, "db")
  end
end

I understand the lines involvin bundler, namespace, desc, and task. However, I do not understand these things...

-What is the line Sequel.extension :migration doing? -The @database = Sequel.postgres lins "sequel-playground line is just setting up an instance variable that is equal to a Sequel database object? Is that right? -In the line:

Sequel:: Migrator.run(@database, "db")

Is Sequel the module, is Migrator a class and is run a method? What are the two arguments doing?

-What is :target => 0 doing in the reset task?

Upvotes: 0

Views: 155

Answers (1)

Leo Correa
Leo Correa

Reputation: 19829

The line

Sequel.extension :migration

Simple enables the migration extension manually for Sequel as it is not part of the core library.

Migration Extension

The line

Sequel.postgres

Opens up the database giving you an instance with which you can run commands on.

Open Database

As for the

Sequel::Migrator.run(@database, "db", :target => 0)

It simply tells Sequel to migrate the given database to the version 0 of the schema.

Rake Migrations

The documentation usually has all the answers for these things.

Upvotes: 0

Related Questions