Class: Sequel::Migration
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
-
.apply(db, direction) ⇒ Object
Applies the migration to the supplied database in the specified direction.
-
.descendants ⇒ Object
Returns the list of Migration descendants.
-
.inherited(base) ⇒ Object
Adds the new migration class to the list of Migration descendants.
Instance Method Summary collapse
-
#down ⇒ Object
The default down action does nothing.
-
#initialize(db) ⇒ Migration
constructor
Creates a new instance of the migration and sets the @db attribute.
-
#method_missing(method_sym, *args, &block) ⇒ Object
Intercepts method calls intended for the database and sends them along.
-
#up ⇒ Object
The default up action does nothing.
Constructor Details
#initialize(db) ⇒ Migration
Creates a new instance of the migration and sets the @db attribute.
26 27 28 |
# File 'lib/sequel/extensions/migration.rb', line 26 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.
52 53 54 |
# File 'lib/sequel/extensions/migration.rb', line 52 def method_missing(method_sym, *args, &block) @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.
32 33 34 35 |
# File 'lib/sequel/extensions/migration.rb', line 32 def self.apply(db, direction) raise(ArgumentError, "Invalid migration direction specified (#{direction.inspect})") unless [:up, :down].include?(direction) new(db).send(direction) end |
.descendants ⇒ Object
Returns the list of Migration descendants.
38 39 40 |
# File 'lib/sequel/extensions/migration.rb', line 38 def self.descendants @descendants ||= [] end |
.inherited(base) ⇒ Object
Adds the new migration class to the list of Migration descendants.
43 44 45 |
# File 'lib/sequel/extensions/migration.rb', line 43 def self.inherited(base) descendants << base end |