Class: Squasher::Cleaner

Inherits:
Object
  • Object
show all
Defined in:
lib/squasher/cleaner.rb

Constant Summary collapse

MIGRATION_NAME =
'squasher_clean'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.process(*args) ⇒ Object



7
8
9
# File 'lib/squasher/cleaner.rb', line 7

def self.process(*args)
  new(*args).process
end

Instance Method Details

#processObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/squasher/cleaner.rb', line 11

def process
  Squasher.error(:migration_folder_missing) unless config.migrations_folders?

  if config.multi_db_format == 'rails'
    config.databases.each do |database|
      process_database(database)
    end
  else
    process_database
  end
end

#process_database(database = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/squasher/cleaner.rb', line 23

def process_database(database = nil)
  migration_file = config.migration_file(now_timestamp, MIGRATION_NAME, database)
  if (prev_migration = prev_migration(database))
    FileUtils.rm(prev_migration)
  end
  File.open(migration_file, 'wb') do |stream|
    stream << ::Squasher::Render.render(MIGRATION_NAME, config, database)
  end

  if database.nil?
    Squasher.rake("db:migrate", :db_cleaning)
  else
    Squasher.rake("db:migrate:#{database}", :db_cleaning)
  end
end