Class: HTM::Migration

Inherits:
Object
  • Object
show all
Defined in:
lib/htm/migration.rb

Overview

Base class for Sequel migrations

Provides a simple interface for writing migrations compatible with HTM’s migration runner.

Examples:

class CreateUsers < HTM::Migration
  def up
    create_table(:users) do
      primary_key :id
      String :name, null: false
      DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
    end
  end

  def down
    drop_table(:users)
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db) ⇒ Migration

Returns a new instance of Migration.



27
28
29
# File 'lib/htm/migration.rb', line 27

def initialize(db)
  @db = db
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



25
26
27
# File 'lib/htm/migration.rb', line 25

def db
  @db
end

Instance Method Details

#downObject

Override in subclass (optional for irreversible migrations)

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/htm/migration.rb', line 37

def down
  raise NotImplementedError, "#{self.class}#down must be implemented"
end

#upObject

Override in subclass

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/htm/migration.rb', line 32

def up
  raise NotImplementedError, "#{self.class}#up must be implemented"
end