module ROM::SQL::Migration
Attributes
migrator[R]
@!attribute [r] migrator
@return [Migrator] Migrator instance
Public Class Methods
included(base)
click to toggle source
FIXME: remove in 2.0
@api private
Calls superclass method
# File lib/rom/sql/migration.rb, line 89 def self.included(base) super base.singleton_class.send(:attr_accessor, :instance) end
new(_uri, options = EMPTY_HASH)
click to toggle source
@api private
# File lib/rom/sql/migration.rb, line 102 def initialize(_uri, options = EMPTY_HASH) @migrator = create_migrator(options[:migrator]) self.class.instance ||= self end
Public Instance Methods
auto_migrate!(conf, options = EMPTY_HASH)
click to toggle source
@api public
# 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
migration(&block)
click to toggle source
@see ROM::SQL.migration
@api public
# File lib/rom/sql/migration.rb, line 124 def migration(&block) migrator.migration(&block) end
pending_migrations?()
click to toggle source
Check if there are any pending migrations
@see ROM::SQL::Migration.pending?
@api public
# File lib/rom/sql/migration.rb, line 113 def pending_migrations? ROM::SQL.with_gateway(self) { migrator.pending? } end
run_migrations(options = {})
click to toggle source
Run migrations
@example
rom = ROM.container(:sql, ['sqlite::memory']) rom.gateways[:default].run_migrations
@param [Hash] options The options used by Sequel migrator
@api public
# File lib/rom/sql/migration.rb, line 137 def run_migrations(options = {}) ROM::SQL.with_gateway(self) { migrator.run(options) } end
Private Instance Methods
create_migrator(migrator_option)
click to toggle source
Create a ‘Migrator`. If `migrator_option` is a `Hash`, use it as options to `Migrator.new`.
@api private
# File lib/rom/sql/migration.rb, line 157 def create_migrator(migrator_option) return Migrator.new(connection) unless migrator_option if migrator_option.is_a?(Hash) Migrator.new(connection, **migrator_option) else migrator_option end end