Module: ROM::SQL::Migration

Included in:
Gateway
Defined in:
lib/rom/sql/migration.rb,
lib/rom/sql/migration/runner.rb,
lib/rom/sql/migration/writer.rb,
lib/rom/sql/migration/migrator.rb,
lib/rom/sql/migration/recorder.rb,
lib/rom/sql/migration/schema_diff.rb,
lib/rom/sql/migration/inline_runner.rb

Defined Under Namespace

Classes: InlineRunner, Migrator, Recorder, Runner, SchemaDiff, Writer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#migratorObject (readonly)

Returns the value of attribute migrator


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

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


89
90
91
92
93
# File 'lib/rom/sql/migration.rb', line 89

def self.included(base)
  super

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

Instance Method Details

#auto_migrate!(conf, options = EMPTY_HASH) ⇒ Object


144
145
146
147
148
149
150
# File 'lib/rom/sql/migration.rb', line 144

def auto_migrate!(conf, options = EMPTY_HASH)
  schemas = conf.relation_classes(self).map do |klass|
    klass.schema_proc.call.finalize_attributes!(gateway: self)
  end

  migrator.auto_migrate!(self, schemas, options)
end

#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.


102
103
104
105
106
# File 'lib/rom/sql/migration.rb', line 102

def initialize(_uri, options = EMPTY_HASH)
  @migrator = create_migrator(options[:migrator])

  self.class.instance ||= self
end

#migration(&block) ⇒ Object

Migration DSL

See Also:


124
125
126
# File 'lib/rom/sql/migration.rb', line 124

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

#pending_migrations?Boolean

Check if there are any pending migrations

Returns:

  • (Boolean)

See Also:

  • pending?

113
114
115
116
117
# File 'lib/rom/sql/migration.rb', line 113

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


137
138
139
140
141
# File 'lib/rom/sql/migration.rb', line 137

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