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

- (Migration) initialize(db)

Set the database associated with this migration.



29
30
31
# File 'lib/sequel/extensions/migration.rb', line 29

def initialize(db)
  @db = db
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method_sym, *args, &block)

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



60
61
62
# File 'lib/sequel/extensions/migration.rb', line 60

def method_missing(method_sym, *args, &block)
  @db.send(method_sym, *args, &block)
end

Class Method Details

+ (Object) apply(db, direction)

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

Raises:

  • (ArgumentError)


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

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

+ (Object) descendants

Returns the list of Migration descendants.



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

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

+ (Object) inherited(base)

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



46
47
48
# File 'lib/sequel/extensions/migration.rb', line 46

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

+ (Object) use_transactions

Don't allow transaction overriding in old migrations.



51
52
53
# File 'lib/sequel/extensions/migration.rb', line 51

def self.use_transactions
  nil
end

Instance Method Details

- (Object) down

The default down action does nothing



56
57
# File 'lib/sequel/extensions/migration.rb', line 56

def down
end

- (Boolean) respond_to_missing?(meth, include_private)

This object responds to all methods the database responds to.

Returns:

  • (Boolean)


65
66
67
# File 'lib/sequel/extensions/migration.rb', line 65

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

- (Object) up

The default up action does nothing



70
71
# File 'lib/sequel/extensions/migration.rb', line 70

def up
end