class Squasher::Worker
Attributes
date[R]
Public Class Methods
new(date)
click to toggle source
# File lib/squasher/worker.rb, line 11 def initialize(date) @date = date end
process(*args)
click to toggle source
# File lib/squasher/worker.rb, line 7 def self.process(*args) new(*args).process end
Public Instance Methods
process()
click to toggle source
# File lib/squasher/worker.rb, line 15 def process check! result = under_squash_env do if Squasher.config.set?(:dry) Squasher.tell(:dry_mode_finished) Squasher.print(Render.render(:init_schema, config)) else path = config.migration_file(finish_timestamp, :init_schema) File.open(path, 'wb') { |io| io << Render.render(:init_schema, config) } migrations.each { |file| FileUtils.rm(file) } end Squasher.rake("db:drop") unless Squasher.ask(:keep_database) end Squasher.clean if result && Squasher.ask(:apply_clean) end
Private Instance Methods
before_date?(timestamp)
click to toggle source
# File lib/squasher/worker.rb, line 57 def before_date?(timestamp) @point ||= date.strftime("%Y%m%d").to_i return unless timestamp timestamp[0...8].to_i < @point end
check!()
click to toggle source
# File lib/squasher/worker.rb, line 40 def check! Squasher.error(:migration_folder_missing) unless config.migrations_folder? Squasher.error(:dbconfig_invalid) unless config.dbconfig? if migrations.empty? print_date = date.strftime("%Y/%m/%d") Squasher.error(:no_migrations, :date => print_date) end end
config()
click to toggle source
# File lib/squasher/worker.rb, line 36 def config Squasher.config end
finish_timestamp()
click to toggle source
# File lib/squasher/worker.rb, line 63 def finish_timestamp @finish_timestamp ||= get_timestamp(migrations.last) end
get_timestamp(file)
click to toggle source
# File lib/squasher/worker.rb, line 53 def get_timestamp(file) File.basename(file)[/\A\d+/] end
migrations()
click to toggle source
# File lib/squasher/worker.rb, line 49 def migrations @migrations ||= config.migration_files.select { |file| before_date?(get_timestamp(file)) }.sort end
under_squash_env() { || ... }
click to toggle source
# File lib/squasher/worker.rb, line 67 def under_squash_env config.stub_dbconfig do if Squasher.config.set?(:reuse) Squasher.tell(:db_reuse) else return unless Squasher.rake("db:drop db:create", :db_create) end return unless Squasher.rake("db:migrate VERSION=#{ finish_timestamp }", :db_migrate) yield true end end