Class: MonarchMigrate::Migrator
- Inherits:
-
Object
- Object
- MonarchMigrate::Migrator
- Defined in:
- lib/monarch_migrate/migrator.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(path, version: nil) ⇒ Migrator
constructor
A new instance of Migrator.
- #migrations ⇒ Object
- #migrations_status ⇒ Object
- #pending_migrations ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(path, version: nil) ⇒ Migrator
Returns a new instance of Migrator.
8 9 10 11 |
# File 'lib/monarch_migrate/migrator.rb', line 8 def initialize(path, version: nil) @path = path.to_s @version = version end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/monarch_migrate/migrator.rb', line 5 def path @path end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
6 7 8 |
# File 'lib/monarch_migrate/migrator.rb', line 6 def version @version end |
Instance Method Details
#migrations ⇒ Object
13 14 15 16 17 |
# File 'lib/monarch_migrate/migrator.rb', line 13 def migrations migration_files.sort.map do |f| Migration.new(f) end end |
#migrations_status ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/monarch_migrate/migrator.rb', line 33 def migrations_status db_list = MigrationRecord.normalized_versions file_list = migrations.filter_map do |migration| version = migration.version status = db_list.delete(version) ? "up" : "down" [status, version, migration.name] end db_list.map! do |version| ["up", version, "***** NO FILE *****"] end (db_list + file_list).sort_by { |_, version, _| version.to_i } end |
#pending_migrations ⇒ Object
19 20 21 |
# File 'lib/monarch_migrate/migrator.rb', line 19 def pending_migrations migrations.select(&:pending?) end |
#run ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/monarch_migrate/migrator.rb', line 23 def run if pending_migrations.any? puts "Running #{pending_migrations.size} data migrations" pending_migrations.sort_by(&:version).each(&:run) else puts "No data migrations pending" [] end end |