21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/yad/db/rails.rb', line 21
def self.define_tasks
return if @tasks_already_defined
@tasks_already_defined = true
namespace :yad do
namespace :db do
desc "Creates the database for the application"
remote_task :create, :roles => :app do
break unless target_host == Rake::RemoteTask.hosts_for(:app).first
options = Rake::RemoteTask.get_options_hash(:app_env, :rake_cmd)
cmd = Yad::Db::Rails.build_create_db_command(current_path, options)
run(cmd)
puts("database created")
end
desc "Runs migrations on the database"
remote_task :migrate, :roles => :app do
break unless target_host == Rake::RemoteTask.hosts_for(:app).first
options = Rake::RemoteTask.get_options_hash(:app_env, :rake_cmd, :migrate_args)
target = Rake::RemoteTask.fetch(:migrate_target, false)
if target
target_directory = case target.to_sym
when :current then current_path
when :latest then latest_release
else raise ArgumentError, "unknown migration target #{target.inspect}"
end
else
target_directory = latest_release
end
cmd = Yad::Db::Rails.build_migrate_db_command(target_directory, options)
run(cmd)
puts("database migrations completed")
end
end
end
end
|