Class: Sequel::Migration

Inherits:
Object show all
Defined in:
lib/sequel/extensions/migration.rb

Overview

Sequel’s older migration class, available for backward compatibility. Uses subclasses with up and down instance methods for each migration:

Class.new(Sequel::Migration) do
  def up
    create_table(:artists) do
      primary_key :id
      String :name
    end
  end

  def down
    drop_table(:artists)
  end
end

Part of the migration extension.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db) ⇒ Migration

Set the database associated with this migration.



36
37
38
# File 'lib/sequel/extensions/migration.rb', line 36

def initialize(db)
  @db = db
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *args, &block) ⇒ Object

Intercepts method calls intended for the database and sends them along.



67
68
69
70
# File 'lib/sequel/extensions/migration.rb', line 67

def method_missing(method_sym, *args, &block)
  # Allow calling private methods for backwards compatibility
  @db.send(method_sym, *args, &block)
end

Class Method Details

.apply(db, direction) ⇒ Object

Applies the migration to the supplied database in the specified direction.

Raises:

  • (ArgumentError)


42
43
44
45
# File 'lib/sequel/extensions/migration.rb', line 42

def self.apply(db, direction)
  raise(ArgumentError, "Invalid migration direction specified (#{direction.inspect})") unless [:up, :down].include?(direction)
  new(db).public_send(direction)
end

.descendantsObject

Returns the list of Migration descendants.



48
49
50
# File 'lib/sequel/extensions/migration.rb', line 48

def self.descendants
  @descendants ||= []
end

.inherited(base) ⇒ Object

Adds the new migration class to the list of Migration descendants.



53
54
55
# File 'lib/sequel/extensions/migration.rb', line 53

def self.inherited(base)
  descendants << base
end

.use_transactionsObject

Don’t allow transaction overriding in old migrations.



58
59
60
# File 'lib/sequel/extensions/migration.rb', line 58

def self.use_transactions
  nil
end

Instance Method Details

#downObject

The default down action does nothing



63
64
# File 'lib/sequel/extensions/migration.rb', line 63

def down
end

#respond_to_missing?(meth, include_private) ⇒ Boolean

This object responds to all methods the database responds to.

Returns:

  • (Boolean)


76
77
78
# File 'lib/sequel/extensions/migration.rb', line 76

def respond_to_missing?(meth, include_private)
  @db.respond_to?(meth, include_private)
end

#upObject

The default up action does nothing



81
82
# File 'lib/sequel/extensions/migration.rb', line 81

def up
end