capistrano-db-tasks 0.2.1 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +1 -1
- data/Rakefile +1 -1
- data/capistrano-db-tasks.gemspec +1 -1
- data/lib/capistrano-db-tasks/asset.rb +13 -9
- data/lib/capistrano-db-tasks/database.rb +12 -15
- data/lib/capistrano-db-tasks/dbtasks.rb +78 -90
- data/lib/capistrano-db-tasks/util.rb +2 -6
- data/lib/capistrano-db-tasks/version.rb +1 -1
- metadata +8 -8
data/README.markdown
CHANGED
@@ -2,7 +2,7 @@ CapistranoDbTasks
|
|
2
2
|
=================
|
3
3
|
|
4
4
|
Add database AND assets tasks to capistrano to a Rails project.
|
5
|
-
It only works with capistrano
|
5
|
+
It only works with capistrano 3. Older versions until 0.3 works with capistrano 2.
|
6
6
|
|
7
7
|
Currently
|
8
8
|
|
data/Rakefile
CHANGED
data/capistrano-db-tasks.gemspec
CHANGED
@@ -2,22 +2,26 @@ module Asset
|
|
2
2
|
extend self
|
3
3
|
|
4
4
|
def remote_to_local(cap)
|
5
|
-
servers =
|
6
|
-
|
7
|
-
[
|
8
|
-
|
5
|
+
servers = Capistrano::Configuration.env.send(:servers)
|
6
|
+
server = servers.detect { |s| s.roles.include?(:app) }
|
7
|
+
port = server.netssh_options[:port] || 22
|
8
|
+
user = server.netssh_options[:user]
|
9
|
+
[cap.fetch(:assets_dir)].flatten.each do |dir|
|
10
|
+
system("rsync -a --del -L -K -vv --progress --rsh='ssh -p #{port}' #{user}@#{server}:#{cap.current_path}/#{dir} #{cap.fetch(:local_assets_dir)}")
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
12
14
|
def local_to_remote(cap)
|
13
|
-
servers =
|
14
|
-
|
15
|
-
[
|
16
|
-
|
15
|
+
servers = Capistrano::Configuration.env.send(:servers)
|
16
|
+
server = servers.detect { |s| s.roles.include?(:app) }
|
17
|
+
port = server.netssh_options[:port] || 22
|
18
|
+
user = server.netssh_options[:user]
|
19
|
+
[cap.fetch(:assets_dir)].flatten.each do |dir|
|
20
|
+
system("rsync -a --del -L -K -vv --progress --rsh='ssh -p #{port}' ./#{dir} #{user}@#{server}:#{cap.current_path}/#{cap.fetch(:local_assets_dir)}")
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
20
24
|
def to_string(cap)
|
21
|
-
[cap.assets_dir].flatten.join(" ")
|
25
|
+
[cap.fetch(:assets_dir)].flatten.join(" ")
|
22
26
|
end
|
23
27
|
end
|
@@ -61,36 +61,33 @@ module Database
|
|
61
61
|
class Remote < Base
|
62
62
|
def initialize(cap_instance)
|
63
63
|
super(cap_instance)
|
64
|
-
@config = ""
|
65
|
-
@
|
66
|
-
@config += d
|
67
|
-
end
|
68
|
-
@config = YAML.load(ERB.new(@config).result)[@cap.rails_env.to_s]
|
64
|
+
@config = @cap.capture("cat #{@cap.current_path}/config/database.yml")
|
65
|
+
@config = YAML.load(ERB.new(@config).result)[@cap.fetch(:rails_env).to_s]
|
69
66
|
end
|
70
67
|
|
71
68
|
def dump
|
72
|
-
@cap.
|
69
|
+
@cap.execute "cd #{@cap.current_path} && #{dump_cmd} | bzip2 - - > #{output_file}"
|
73
70
|
self
|
74
71
|
end
|
75
72
|
|
76
73
|
def download(local_file = "#{output_file}")
|
77
74
|
remote_file = "#{@cap.current_path}/#{output_file}"
|
78
|
-
@cap.
|
75
|
+
@cap.download! remote_file, local_file
|
79
76
|
end
|
80
77
|
|
81
78
|
# cleanup = true removes the mysqldump file after loading, false leaves it in db/
|
82
79
|
def load(file, cleanup)
|
83
80
|
unzip_file = File.join(File.dirname(file), File.basename(file, '.bz2'))
|
84
81
|
# @cap.run "cd #{@cap.current_path} && bunzip2 -f #{file} && RAILS_ENV=#{@cap.rails_env} bundle exec rake db:drop db:create && #{import_cmd(unzip_file)}"
|
85
|
-
@cap.
|
86
|
-
@cap.
|
82
|
+
@cap.execute "cd #{@cap.current_path} && bunzip2 -f #{file} && RAILS_ENV=#{@cap.fetch(:rails_env)} && #{import_cmd(unzip_file)}"
|
83
|
+
@cap.execute("cd #{@cap.current_path} && rm #{unzip_file}") if cleanup
|
87
84
|
end
|
88
85
|
end
|
89
86
|
|
90
87
|
class Local < Base
|
91
88
|
def initialize(cap_instance)
|
92
89
|
super(cap_instance)
|
93
|
-
@config = YAML.load(ERB.new(File.read(File.join('config', 'database.yml'))).result)[
|
90
|
+
@config = YAML.load(ERB.new(File.read(File.join('config', 'database.yml'))).result)[fetch(:local_rails_env).to_s]
|
94
91
|
puts "local #{@config}"
|
95
92
|
end
|
96
93
|
|
@@ -98,15 +95,15 @@ module Database
|
|
98
95
|
def load(file, cleanup)
|
99
96
|
unzip_file = File.join(File.dirname(file), File.basename(file, '.bz2'))
|
100
97
|
# system("bunzip2 -f #{file} && bundle exec rake db:drop db:create && #{import_cmd(unzip_file)} && bundle exec rake db:migrate")
|
101
|
-
@cap.
|
98
|
+
@cap.info "executing local: bunzip2 -f #{file} && #{import_cmd(unzip_file)}"
|
102
99
|
system("bunzip2 -f #{file} && #{import_cmd(unzip_file)}")
|
103
100
|
if cleanup
|
104
|
-
@cap.
|
101
|
+
@cap.info "removing #{unzip_file}"
|
105
102
|
File.unlink(unzip_file)
|
106
103
|
else
|
107
|
-
@cap.
|
104
|
+
@cap.info "leaving #{unzip_file} (specify :db_local_clean in deploy.rb to remove)"
|
108
105
|
end
|
109
|
-
@cap.
|
106
|
+
@cap.info "Completed database import"
|
110
107
|
end
|
111
108
|
|
112
109
|
def dump
|
@@ -116,7 +113,7 @@ module Database
|
|
116
113
|
|
117
114
|
def upload
|
118
115
|
remote_file = "#{@cap.current_path}/#{output_file}"
|
119
|
-
@cap.upload output_file, remote_file
|
116
|
+
@cap.upload! output_file, remote_file
|
120
117
|
end
|
121
118
|
end
|
122
119
|
|
@@ -1,114 +1,102 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
task :sync, :roles => :db do
|
19
|
-
if Util.prompt 'Are you sure you want to REPLACE THE REMOTE DATABASE with local database'
|
20
|
-
Database.local_to_remote(instance)
|
21
|
-
end
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/util")
|
2
|
+
require File.expand_path("#{File.dirname(__FILE__)}/database")
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/asset")
|
4
|
+
|
5
|
+
set :local_rails_env, ENV['RAILS_ENV'] || 'development' unless fetch(:local_rails_env)
|
6
|
+
set :rails_env, 'production' unless fetch(:rails_env)
|
7
|
+
set :db_local_clean, false unless fetch(:db_local_clean)
|
8
|
+
set :assets_dir, 'system' unless fetch(:assets_dir)
|
9
|
+
set :local_assets_dir, 'public' unless fetch(:local_assets_dir)
|
10
|
+
|
11
|
+
namespace :db do
|
12
|
+
namespace :remote do
|
13
|
+
desc 'Synchronize your remote database using local database data'
|
14
|
+
task :sync do
|
15
|
+
on roles(:db) do
|
16
|
+
if Util.prompt 'Are you sure you want to REPLACE THE REMOTE DATABASE with local database'
|
17
|
+
Database.local_to_remote(self)
|
22
18
|
end
|
23
19
|
end
|
20
|
+
end
|
21
|
+
end
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
namespace :local do
|
24
|
+
desc 'Synchronize your local database using remote database data'
|
25
|
+
task :sync do
|
26
|
+
on roles(:db) do
|
27
|
+
puts "Local database: #{Database::Local.new(self).database}"
|
28
|
+
if Util.prompt 'Are you sure you want to erase your local database with server database'
|
29
|
+
Database.remote_to_local(self)
|
32
30
|
end
|
33
31
|
end
|
32
|
+
end
|
33
|
+
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
db.local.sync
|
38
|
-
end
|
35
|
+
desc 'Synchronize your local database using remote database data'
|
36
|
+
task :pull => "db:local:sync"
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
end
|
38
|
+
desc 'Synchronize your remote database using local database data'
|
39
|
+
task :push => "db:remote:sync"
|
40
|
+
end
|
45
41
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
42
|
+
namespace :assets do
|
43
|
+
namespace :remote do
|
44
|
+
desc 'Synchronize your remote assets using local assets'
|
45
|
+
task :sync do
|
46
|
+
on roles(:app) do
|
47
|
+
puts "Assets directories: #{fetch(:assets_dir)}"
|
48
|
+
if Util.prompt "Are you sure you want to erase your server assets with local assets"
|
49
|
+
Asset.local_to_remote(self)
|
54
50
|
end
|
55
51
|
end
|
52
|
+
end
|
53
|
+
end
|
56
54
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
55
|
+
namespace :local do
|
56
|
+
desc 'Synchronize your local assets using remote assets'
|
57
|
+
task :sync do
|
58
|
+
on roles(:app) do
|
59
|
+
puts "Assets directories: #{fetch(:local_assets_dir)}"
|
60
|
+
if Util.prompt "Are you sure you want to erase your local assets with server assets"
|
61
|
+
Asset.remote_to_local(self)
|
64
62
|
end
|
65
63
|
end
|
66
|
-
|
67
|
-
desc 'Synchronize your local assets using remote assets'
|
68
|
-
task :pull do
|
69
|
-
assets.local.sync
|
70
|
-
end
|
71
|
-
|
72
|
-
desc 'Synchronize your remote assets using local assets'
|
73
|
-
task :push do
|
74
|
-
assets.remote.sync
|
75
|
-
end
|
76
64
|
end
|
65
|
+
end
|
77
66
|
|
78
|
-
|
79
|
-
|
80
|
-
desc 'Synchronize your remote assets AND database using local assets and database'
|
81
|
-
task :sync do
|
82
|
-
if Util.prompt "Are you sure you want to REPLACE THE REMOTE DATABASE AND your remote assets with local database and assets(#{assets_dir})"
|
83
|
-
Database.local_to_remote(instance)
|
84
|
-
Asset.local_to_remote(instance)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
67
|
+
desc 'Synchronize your local assets using remote assets'
|
68
|
+
task :pull => "assets:local:sync"
|
88
69
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
puts "Local database : #{Database::Local.new(instance).database}"
|
93
|
-
puts "Assets directories : #{local_assets_dir}"
|
94
|
-
if Util.prompt "Are you sure you want to erase your local database AND your local assets with server database and assets(#{assets_dir})"
|
95
|
-
Database.remote_to_local(instance)
|
96
|
-
Asset.remote_to_local(instance)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
70
|
+
desc 'Synchronize your remote assets using local assets'
|
71
|
+
task :push => "assets:remote:sync"
|
72
|
+
end
|
100
73
|
|
101
|
-
|
102
|
-
|
103
|
-
|
74
|
+
namespace :app do
|
75
|
+
namespace :remote do
|
76
|
+
desc 'Synchronize your remote assets AND database using local assets and database'
|
77
|
+
task :sync do
|
78
|
+
if Util.prompt "Are you sure you want to REPLACE THE REMOTE DATABASE AND your remote assets with local database and assets(#{assets_dir})"
|
79
|
+
Database.local_to_remote(self)
|
80
|
+
Asset.local_to_remote(self)
|
104
81
|
end
|
82
|
+
end
|
83
|
+
end
|
105
84
|
|
106
|
-
|
107
|
-
|
108
|
-
|
85
|
+
namespace :local do
|
86
|
+
desc 'Synchronize your local assets AND database using remote assets and database'
|
87
|
+
task :sync do
|
88
|
+
puts "Local database : #{Database::Local.new(self).database}"
|
89
|
+
puts "Assets directories : #{fetch(:local_assets_dir)}"
|
90
|
+
if Util.prompt "Are you sure you want to erase your local database AND your local assets with server database and assets(#{assets_dir})"
|
91
|
+
Database.remote_to_local(self)
|
92
|
+
Asset.remote_to_local(self)
|
109
93
|
end
|
110
|
-
|
111
94
|
end
|
112
95
|
end
|
113
96
|
|
97
|
+
desc 'Synchronize your local assets AND database using remote assets and database'
|
98
|
+
task :pull => "app:local:sync"
|
99
|
+
|
100
|
+
desc 'Synchronize your remote assets AND database using local assets and database'
|
101
|
+
task :push => "app:remote:sync"
|
114
102
|
end
|
@@ -1,10 +1,6 @@
|
|
1
1
|
module Util
|
2
2
|
def self.prompt(msg, prompt = "(y)es, (n)o ")
|
3
|
-
answer
|
4
|
-
|
5
|
-
q.validate = /^y$|^yes$|^n$|^no$/i
|
6
|
-
q.responses[:not_valid] = prompt
|
7
|
-
end
|
8
|
-
(answer =~ /^y$|^yes$/i) == 0
|
3
|
+
ask(:answer, "#{msg} #{prompt} ? ")
|
4
|
+
(fetch(:answer) =~ /^y$|^yes$/i) == 0
|
9
5
|
end
|
10
6
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-db-tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.3'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -16,17 +16,17 @@ dependencies:
|
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- - ! '
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
22
|
-
type: :
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- - ! '
|
27
|
+
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 3.0.0
|
30
30
|
description: A collection of capistrano tasks for syncing assets and databases
|
31
31
|
email:
|
32
32
|
- sebastien.gruhier@xilinus.com
|
@@ -61,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
61
|
version: '0'
|
62
62
|
segments:
|
63
63
|
- 0
|
64
|
-
hash:
|
64
|
+
hash: 2376160182580984421
|
65
65
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
66
|
none: false
|
67
67
|
requirements:
|
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
version: '0'
|
71
71
|
segments:
|
72
72
|
- 0
|
73
|
-
hash:
|
73
|
+
hash: 2376160182580984421
|
74
74
|
requirements: []
|
75
75
|
rubyforge_project: capistrano-db-tasks
|
76
76
|
rubygems_version: 1.8.23
|