Class: Migrator
- Inherits:
-
Object
- Object
- Migrator
- Defined in:
- lib/sfb_scripts/migrations/migrator.rb
Instance Attribute Summary collapse
-
#drop_dbs ⇒ Object
Returns the value of attribute drop_dbs.
-
#folder_guard ⇒ Object
Returns the value of attribute folder_guard.
-
#queue ⇒ Object
Returns the value of attribute queue.
-
#repo ⇒ Object
Returns the value of attribute repo.
-
#shell ⇒ Object
Returns the value of attribute shell.
Instance Method Summary collapse
- #directories_to_migrate ⇒ Object
-
#initialize(repo:, shell:, queue:, folder_guard:, drop_dbs: false) ⇒ Migrator
constructor
A new instance of Migrator.
- #migrate_where_necessary ⇒ Object
Constructor Details
#initialize(repo:, shell:, queue:, folder_guard:, drop_dbs: false) ⇒ Migrator
Returns a new instance of Migrator.
4 5 6 7 8 9 10 |
# File 'lib/sfb_scripts/migrations/migrator.rb', line 4 def initialize(repo:, shell:, queue:, folder_guard:, drop_dbs: false) @shell = shell @repo = repo @queue = queue @drop_dbs = drop_dbs @folder_guard = folder_guard end |
Instance Attribute Details
#drop_dbs ⇒ Object
Returns the value of attribute drop_dbs.
2 3 4 |
# File 'lib/sfb_scripts/migrations/migrator.rb', line 2 def drop_dbs @drop_dbs end |
#folder_guard ⇒ Object
Returns the value of attribute folder_guard.
2 3 4 |
# File 'lib/sfb_scripts/migrations/migrator.rb', line 2 def folder_guard @folder_guard end |
#queue ⇒ Object
Returns the value of attribute queue.
2 3 4 |
# File 'lib/sfb_scripts/migrations/migrator.rb', line 2 def queue @queue end |
#repo ⇒ Object
Returns the value of attribute repo.
2 3 4 |
# File 'lib/sfb_scripts/migrations/migrator.rb', line 2 def repo @repo end |
#shell ⇒ Object
Returns the value of attribute shell.
2 3 4 |
# File 'lib/sfb_scripts/migrations/migrator.rb', line 2 def shell @shell end |
Instance Method Details
#directories_to_migrate ⇒ Object
22 23 24 25 |
# File 'lib/sfb_scripts/migrations/migrator.rb', line 22 def directories_to_migrate migrate_dirs = repo.files_changed.select {|f| f.match("/migrate/") }.map {|f| File.dirname(f) }.map {|dir| dir.gsub(/\/db\/migrate$/, '')}.uniq migrate_dirs.select {|d| folder_guard.allowed?(d) }; end |
#migrate_where_necessary ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/sfb_scripts/migrations/migrator.rb', line 12 def migrate_where_necessary shell.notify "\nMigrating:" migrations.each do |migration| queue.enqueue_b do shell.run "RAILS_ENV=#{migration[:env]} bundle exec rake #{drop_dbs ? 'db:drop' : ''} db:create 2> /dev/null;\n RAILS_ENV=#{migration[:env]} bundle exec rake db:migrate", dir: migration[:dir] end end queue.join end |