class MotionRecord::Schema::Migrator

Attributes

migrations[R]

Public Class Methods

new(migrations) click to toggle source
# File lib/motion_record/schema/migrator.rb, line 7
def initialize(migrations)
  @migrations = migrations
  @migrated_versions = nil

  initialize_schema_table
end

Public Instance Methods

migrated() click to toggle source
# File lib/motion_record/schema/migrator.rb, line 26
def migrated
  @migrated_versions ||= Schema::Migration.pluck(:version).sort
end
pending_migrations() click to toggle source
# File lib/motion_record/schema/migrator.rb, line 22
def pending_migrations
  @migrations.reject { |migration| migrated.include?(migration.version) }
end
run() click to toggle source
# File lib/motion_record/schema/migrator.rb, line 14
def run
  pending_migrations.each do |migration|
    migration.execute
    @migrated_versions << migration.version
    Schema::Migration.create(version: migration.version)
  end 
end

Protected Instance Methods

initialize_schema_table() click to toggle source
# File lib/motion_record/schema/migrator.rb, line 32
def initialize_schema_table
  unless Schema::Migration.table_exists?
    Schema::Migration.create_table
  end
end