Module: ROM::SQL::Migration

Included in:
Gateway
Defined in:
lib/rom/sql/migration.rb,
lib/rom/sql/migration/migrator.rb

Defined Under Namespace

Classes: Migrator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#migratorObject (readonly)

Returns the value of attribute migrator.



95
96
97
# File 'lib/rom/sql/migration.rb', line 95

def migrator
  @migrator
end

Class Method Details

.included(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

FIXME: remove in 2.0



85
86
87
88
89
# File 'lib/rom/sql/migration.rb', line 85

def self.included(base)
  super

  base.singleton_class.send(:attr_accessor, :instance)
end

Instance Method Details

#initialize(uri, options = EMPTY_HASH) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



98
99
100
101
102
# File 'lib/rom/sql/migration.rb', line 98

def initialize(uri, options = EMPTY_HASH)
  @migrator = options.fetch(:migrator) { Migrator.new(connection) }

  self.class.instance ||= self
end

#migration(&block) ⇒ Object

Migration DSL

See Also:



120
121
122
# File 'lib/rom/sql/migration.rb', line 120

def migration(&block)
  migrator.migration(&block)
end

#pending_migrations?Boolean

Check if there are any pending migrations

Returns:

  • (Boolean)

See Also:

  • pending?


109
110
111
112
113
# File 'lib/rom/sql/migration.rb', line 109

def pending_migrations?
  ROM::SQL.with_gateway(self) {
    migrator.pending?
  }
end

#run_migrations(options = {}) ⇒ Object

Run migrations

Examples:

rom = ROM.container(:sql, ['sqlite::memory'])
rom.gateways[:default].run_migrations

Parameters:

  • options (Hash) (defaults to: {})

    The options used by Sequel migrator



133
134
135
136
137
# File 'lib/rom/sql/migration.rb', line 133

def run_migrations(options = {})
  ROM::SQL.with_gateway(self) {
    migrator.run(options)
  }
end