capistrano-db-tasks 0.3 → 0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ea446d397b392606dc52f06573bcb96a9393512c
4
+ data.tar.gz: 5f7e0c4afe2bbabe318dbc4394f89ef785b48dfd
5
+ SHA512:
6
+ metadata.gz: 176d858ac97f2e33fd31457e178c1e34c33d9022594bf83f2cb81b1dd4253ce665782c4f5eaaef36ff263c9b2ee3cd0b4dc4c5229ea7417d48d1cc57215c8426
7
+ data.tar.gz: c850f2dd9138ba36f5cb07506eb67c0f6b6feda66f5daef31d2edccaf71fec8ac9990d199ef03113e311f1811102330079a13a2112d0a434f0edb0812ff683f3
data/README.markdown CHANGED
@@ -1,82 +1,92 @@
1
- CapistranoDbTasks
2
- =================
3
-
4
- Add database AND assets tasks to capistrano to a Rails project.
5
- It only works with capistrano 3. Older versions until 0.3 works with capistrano 2.
6
-
7
- Currently
8
-
9
- * It only supports mysql and postgresql (both side remote and local)
10
- * Synchronize assets remote to local and local to remote
11
-
12
- Commands mysql, mysqldump (or pg_dump, psql), bzip2 and unbzip2 must be in your PATH
13
-
14
- Feel free to fork and to add more database support or new tasks.
15
-
16
- Install
17
- =======
18
-
19
- Add it as a gem:
20
-
21
- ```ruby
22
- gem "capistrano-db-tasks", require: false
23
- ```
24
-
25
- Add to config/deploy.rb:
26
-
27
- ```ruby
28
- require 'capistrano-db-tasks'
29
-
30
- # if you haven't already specified
31
- set :rails_env, "production"
32
-
33
- # if you want to remove the dump file after loading
34
- set :db_local_clean, true
35
-
36
- # If you want to import assets, you can change default asset dir (default = system)
37
- # This directory must be in your shared directory on the server
38
- set :assets_dir, %w(public/assets public/att)
39
-
40
- # if you want to work on a specific local environment (default = ENV['RAILS_ENV'] || 'development')
41
- set :locals_rails_env, "production"
42
- ```
43
-
44
- Add to .gitignore
45
- ```yml
46
- /db/*.sql
47
- ```
48
-
49
- Available tasks
50
- ===============
51
-
52
- app:local:sync || app:pull # Synchronize your local assets AND database using remote assets and database
53
- app:remote:sync || app:push # Synchronize your remote assets AND database using local assets and database
54
-
55
- assets:local:sync || assets:pull # Synchronize your local assets using remote assets
56
- assets:remote:sync || assets:push # Synchronize your remote assets using local assets
57
-
58
- db:local:sync || db:pull # Synchronize your local database using remote database data
59
- db:remote:sync || db:push # Synchronize your remote database using local database data
60
-
61
- Example
62
- =======
63
-
64
- cap db:pull
65
- cap production db:pull # if you are using capistrano-ext to have multistages
66
-
67
-
68
- Contributors
69
- ============
70
-
71
- * tilsammans (http://github.com/tilsammansee)
72
- * bigfive (http://github.com/bigfive)
73
- * jakemauer (http://github.com/jakemauer)
74
- * tjoneseng (http://github.com/tjoneseng)
75
-
76
- TODO
77
- ====
78
-
79
- * May be change project's name as it's not only database tasks now :)
80
- * Add tests
81
-
82
- Copyright (c) 2009 [Sébastien Gruhier - XILINUS], released under the MIT license
1
+ CapistranoDbTasks
2
+ =================
3
+
4
+ Add database AND assets tasks to capistrano to a Rails project.
5
+ It only works with capistrano 3. Older versions until 0.3 works with capistrano 2.
6
+
7
+ Currently
8
+
9
+ * It only supports mysql and postgresql (both side remote and local)
10
+ * Synchronize assets remote to local and local to remote
11
+
12
+ Commands mysql, mysqldump (or pg_dump, psql), bzip2 and unbzip2 must be in your PATH
13
+
14
+ Feel free to fork and to add more database support or new tasks.
15
+
16
+ Install
17
+ =======
18
+
19
+ Add it as a gem:
20
+
21
+ ```ruby
22
+ gem "capistrano-db-tasks", require: false
23
+ ```
24
+
25
+ Add to config/deploy.rb:
26
+
27
+ ```ruby
28
+ require 'capistrano-db-tasks'
29
+
30
+ # if you haven't already specified
31
+ set :rails_env, "production"
32
+
33
+ # if you want to remove the local dump file after loading
34
+ set :db_local_clean, true
35
+
36
+ # if you want to remove the dump file from the server after downloading
37
+ set :db_remote_clean, true
38
+
39
+ # If you want to import assets, you can change default asset dir (default = system)
40
+ # This directory must be in your shared directory on the server
41
+ set :assets_dir, %w(public/assets public/att)
42
+ set :local_assets_dir, %w(public/assets public/att)
43
+
44
+ # if you want to work on a specific local environment (default = ENV['RAILS_ENV'] || 'development')
45
+ set :locals_rails_env, "production"
46
+
47
+ # if you are highly paranoid and want to prevent any push operation to the server
48
+ set :disallow_pushing, true
49
+ ```
50
+
51
+ Add to .gitignore
52
+ ```yml
53
+ /db/*.sql
54
+ ```
55
+
56
+
57
+ [How to install bzip2 on Windows](http://stackoverflow.com/a/25625988/3324219)
58
+
59
+ Available tasks
60
+ ===============
61
+
62
+ app:local:sync || app:pull # Synchronize your local assets AND database using remote assets and database
63
+ app:remote:sync || app:push # Synchronize your remote assets AND database using local assets and database
64
+
65
+ assets:local:sync || assets:pull # Synchronize your local assets using remote assets
66
+ assets:remote:sync || assets:push # Synchronize your remote assets using local assets
67
+
68
+ db:local:sync || db:pull # Synchronize your local database using remote database data
69
+ db:remote:sync || db:push # Synchronize your remote database using local database data
70
+
71
+ Example
72
+ =======
73
+
74
+ cap db:pull
75
+ cap production db:pull # if you are using capistrano-ext to have multistages
76
+
77
+
78
+ Contributors
79
+ ============
80
+
81
+ * tilsammans (http://github.com/tilsammansee)
82
+ * bigfive (http://github.com/bigfive)
83
+ * jakemauer (http://github.com/jakemauer)
84
+ * tjoneseng (http://github.com/tjoneseng)
85
+
86
+ TODO
87
+ ====
88
+
89
+ * May be change project's name as it's not only database tasks now :)
90
+ * Add tests
91
+
92
+ Copyright (c) 2009 [Sébastien Gruhier - XILINUS], released under the MIT license
@@ -1,149 +1,178 @@
1
- module Database
2
- class Base
3
- attr_accessor :config, :output_file
4
- def initialize(cap_instance)
5
- @cap = cap_instance
6
- end
7
-
8
- def mysql?
9
- @config['adapter'] =~ /^mysql/
10
- end
11
-
12
- def postgresql?
13
- %w(postgresql pg).include? @config['adapter']
14
- end
15
-
16
- def credentials
17
- if mysql?
18
- username = @config['username'] || @config['user']
19
- (username ? " -u #{username} " : '') + (@config['password'] ? " -p'#{@config['password']}' " : '') + (@config['host'] ? " -h #{@config['host']}" : '') + (@config['socket'] ? " -S#{@config['socket']}" : '')
20
- elsif postgresql?
21
- (@config['username'] ? " -U #{@config['username']} " : '') + (@config['host'] ? " -h #{@config['host']}" : '')
22
- end
23
- end
24
-
25
- def database
26
- @config['database']
27
- end
28
-
29
- def current_time
30
- Time.now.strftime("%Y-%m-%d-%H%M%S")
31
- end
32
-
33
- def output_file
34
- @output_file ||= "db/#{database}_#{current_time}.sql.bz2"
35
- end
36
-
37
- def pgpass
38
- "PGPASSWORD='#{@config['password']}'" if @config['password']
39
- end
40
-
41
- private
42
-
43
- def dump_cmd
44
- if mysql?
45
- "mysqldump #{credentials} #{database} --lock-tables=false"
46
- elsif postgresql?
47
- "#{pgpass} pg_dump #{credentials} -c -O #{database}"
48
- end
49
- end
50
-
51
- def import_cmd(file)
52
- if mysql?
53
- "mysql #{credentials} -D #{database} < #{file}"
54
- elsif postgresql?
55
- "#{pgpass} psql #{credentials} #{database} < #{file}"
56
- end
57
- end
58
-
59
- end
60
-
61
- class Remote < Base
62
- def initialize(cap_instance)
63
- super(cap_instance)
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]
66
- end
67
-
68
- def dump
69
- @cap.execute "cd #{@cap.current_path} && #{dump_cmd} | bzip2 - - > #{output_file}"
70
- self
71
- end
72
-
73
- def download(local_file = "#{output_file}")
74
- remote_file = "#{@cap.current_path}/#{output_file}"
75
- @cap.download! remote_file, local_file
76
- end
77
-
78
- # cleanup = true removes the mysqldump file after loading, false leaves it in db/
79
- def load(file, cleanup)
80
- unzip_file = File.join(File.dirname(file), File.basename(file, '.bz2'))
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)}"
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
84
- end
85
- end
86
-
87
- class Local < Base
88
- def initialize(cap_instance)
89
- super(cap_instance)
90
- @config = YAML.load(ERB.new(File.read(File.join('config', 'database.yml'))).result)[fetch(:local_rails_env).to_s]
91
- puts "local #{@config}"
92
- end
93
-
94
- # cleanup = true removes the mysqldump file after loading, false leaves it in db/
95
- def load(file, cleanup)
96
- unzip_file = File.join(File.dirname(file), File.basename(file, '.bz2'))
97
- # system("bunzip2 -f #{file} && bundle exec rake db:drop db:create && #{import_cmd(unzip_file)} && bundle exec rake db:migrate")
98
- @cap.info "executing local: bunzip2 -f #{file} && #{import_cmd(unzip_file)}"
99
- system("bunzip2 -f #{file} && #{import_cmd(unzip_file)}")
100
- if cleanup
101
- @cap.info "removing #{unzip_file}"
102
- File.unlink(unzip_file)
103
- else
104
- @cap.info "leaving #{unzip_file} (specify :db_local_clean in deploy.rb to remove)"
105
- end
106
- @cap.info "Completed database import"
107
- end
108
-
109
- def dump
110
- system "#{dump_cmd} | bzip2 - - > #{output_file}"
111
- self
112
- end
113
-
114
- def upload
115
- remote_file = "#{@cap.current_path}/#{output_file}"
116
- @cap.upload! output_file, remote_file
117
- end
118
- end
119
-
120
-
121
- class << self
122
- def check(local_db, remote_db)
123
- unless (local_db.mysql? && remote_db.mysql?) || (local_db.postgresql? && remote_db.postgresql?)
124
- raise 'Only mysql or postgresql on remote and local server is supported'
125
- end
126
- end
127
-
128
- def remote_to_local(instance)
129
- local_db = Database::Local.new(instance)
130
- remote_db = Database::Remote.new(instance)
131
-
132
- check(local_db, remote_db)
133
-
134
- remote_db.dump.download
135
- local_db.load(remote_db.output_file, instance.fetch(:db_local_clean))
136
- end
137
-
138
- def local_to_remote(instance)
139
- local_db = Database::Local.new(instance)
140
- remote_db = Database::Remote.new(instance)
141
-
142
- check(local_db, remote_db)
143
-
144
- local_db.dump.upload
145
- remote_db.load(local_db.output_file, instance.fetch(:db_local_clean))
146
- end
147
- end
148
-
149
- end
1
+ module Database
2
+ class Base
3
+ attr_accessor :config, :output_file
4
+ def initialize(cap_instance)
5
+ @cap = cap_instance
6
+ end
7
+
8
+ def mysql?
9
+ @config['adapter'] =~ /^mysql/
10
+ end
11
+
12
+ def postgresql?
13
+ %w(postgresql pg).include? @config['adapter']
14
+ end
15
+
16
+ def credentials
17
+ credential_params = ""
18
+ username = @config['username'] || @config['user']
19
+
20
+ if mysql?
21
+ credential_params << " -u #{username} " if username
22
+ credential_params << " -p'#{@config['password']}' " if @config['password']
23
+ credential_params << " -h #{@config['host']} " if @config['host']
24
+ credential_params << " -S #{@config['socket']} " if @config['socket']
25
+ credential_params << " -P #{@config['port']} " if @config['port']
26
+ elsif postgresql?
27
+ credential_params << " -U #{username} " if username
28
+ credential_params << " -h #{@config['host']} " if @config['host']
29
+ credential_params << " -p #{@config['port']} " if @config['port']
30
+ end
31
+
32
+ credential_params
33
+ end
34
+
35
+ def database
36
+ @config['database']
37
+ end
38
+
39
+ def current_time
40
+ Time.now.strftime("%Y-%m-%d-%H%M%S")
41
+ end
42
+
43
+ def output_file
44
+ @output_file ||= "db/#{database}_#{current_time}.sql.bz2"
45
+ end
46
+
47
+ def pgpass
48
+ "PGPASSWORD='#{@config['password']}'" if @config['password']
49
+ end
50
+
51
+ private
52
+
53
+ def dump_cmd
54
+ if mysql?
55
+ "mysqldump #{credentials} #{database} --lock-tables=false"
56
+ elsif postgresql?
57
+ "#{pgpass} pg_dump --no-acl --no-owner #{credentials} #{database}"
58
+ end
59
+ end
60
+
61
+ def import_cmd(file)
62
+ if mysql?
63
+ "mysql #{credentials} -D #{database} < #{file}"
64
+ elsif postgresql?
65
+ terminate_connection_sql = "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '#{database}' AND pid <> pg_backend_pid();"
66
+ "#{pgpass} psql -c \"#{terminate_connection_sql};\" #{credentials}; #{pgpass} dropdb #{credentials} #{database}; #{pgpass} createdb #{credentials} #{database}; #{pgpass} psql #{credentials} -d #{database} < #{file}"
67
+ end
68
+ end
69
+
70
+ end
71
+
72
+ class Remote < Base
73
+ def initialize(cap_instance)
74
+ super(cap_instance)
75
+ @config = @cap.capture("cat #{@cap.current_path}/config/database.yml")
76
+ @config = YAML.load(ERB.new(@config).result)[@cap.fetch(:rails_env).to_s]
77
+ end
78
+
79
+ def dump
80
+ @cap.execute "cd #{@cap.current_path} && #{dump_cmd} | bzip2 - - > #{output_file}"
81
+ self
82
+ end
83
+
84
+ def download(local_file = "#{output_file}")
85
+ @cap.download! dump_file_path, local_file
86
+ end
87
+
88
+ def clean_dump_if_needed
89
+ if @cap.fetch(:db_remote_clean)
90
+ @cap.execute "rm -f #{dump_file_path}"
91
+ else
92
+ @cap.info "leaving #{dump_file_path} on the server (add \"set :db_remote_clean, true\" to deploy.rb to remove)"
93
+ end
94
+ end
95
+
96
+ # cleanup = true removes the mysqldump file after loading, false leaves it in db/
97
+ def load(file, cleanup)
98
+ unzip_file = File.join(File.dirname(file), File.basename(file, '.bz2'))
99
+ # @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)}"
100
+ @cap.execute "cd #{@cap.current_path} && bunzip2 -f #{file} && RAILS_ENV=#{@cap.fetch(:rails_env)} && #{import_cmd(unzip_file)}"
101
+ @cap.execute("cd #{@cap.current_path} && rm #{unzip_file}") if cleanup
102
+ end
103
+
104
+ private
105
+
106
+ def dump_file_path
107
+ "#{@cap.current_path}/#{output_file}"
108
+ end
109
+ end
110
+
111
+ class Local < Base
112
+ def initialize(cap_instance)
113
+ super(cap_instance)
114
+ @config = YAML.load(ERB.new(File.read(File.join('config', 'database.yml'))).result)[fetch(:local_rails_env).to_s]
115
+ puts "local #{@config}"
116
+ end
117
+
118
+ # cleanup = true removes the mysqldump file after loading, false leaves it in db/
119
+ def load(file, cleanup)
120
+ unzip_file = File.join(File.dirname(file), File.basename(file, '.bz2'))
121
+ # system("bunzip2 -f #{file} && bundle exec rake db:drop db:create && #{import_cmd(unzip_file)} && bundle exec rake db:migrate")
122
+ @cap.info "executing local: bunzip2 -f #{file} && #{import_cmd(unzip_file)}"
123
+ system("bunzip2 -f #{file} && #{import_cmd(unzip_file)}")
124
+ if cleanup
125
+ @cap.info "removing #{unzip_file}"
126
+ File.unlink(unzip_file)
127
+ else
128
+ @cap.info "leaving #{unzip_file} (specify :db_local_clean in deploy.rb to remove)"
129
+ end
130
+ @cap.info "Completed database import"
131
+ end
132
+
133
+ def dump
134
+ system "#{dump_cmd} | bzip2 - - > #{output_file}"
135
+ self
136
+ end
137
+
138
+ def upload
139
+ remote_file = "#{@cap.current_path}/#{output_file}"
140
+ @cap.upload! output_file, remote_file
141
+ end
142
+ end
143
+
144
+
145
+ class << self
146
+ def check(local_db, remote_db)
147
+ unless (local_db.mysql? && remote_db.mysql?) || (local_db.postgresql? && remote_db.postgresql?)
148
+ raise 'Only mysql or postgresql on remote and local server is supported'
149
+ end
150
+ end
151
+
152
+ def remote_to_local(instance)
153
+ local_db = Database::Local.new(instance)
154
+ remote_db = Database::Remote.new(instance)
155
+
156
+ check(local_db, remote_db)
157
+
158
+ begin
159
+ remote_db.dump.download
160
+ ensure
161
+ remote_db.clean_dump_if_needed
162
+ end
163
+ local_db.load(remote_db.output_file, instance.fetch(:db_local_clean))
164
+ end
165
+
166
+ def local_to_remote(instance)
167
+ local_db = Database::Local.new(instance)
168
+ remote_db = Database::Remote.new(instance)
169
+
170
+ check(local_db, remote_db)
171
+
172
+ local_db.dump.upload
173
+ remote_db.load(local_db.output_file, instance.fetch(:db_local_clean))
174
+ File.unlink(local_db.output_file) if instance.fetch(:db_local_clean)
175
+ end
176
+ end
177
+
178
+ end
@@ -1,102 +1,120 @@
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)
18
- end
19
- end
20
- end
21
- end
22
-
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)
30
- end
31
- end
32
- end
33
- end
34
-
35
- desc 'Synchronize your local database using remote database data'
36
- task :pull => "db:local:sync"
37
-
38
- desc 'Synchronize your remote database using local database data'
39
- task :push => "db:remote:sync"
40
- end
41
-
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)
50
- end
51
- end
52
- end
53
- end
54
-
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)
62
- end
63
- end
64
- end
65
- end
66
-
67
- desc 'Synchronize your local assets using remote assets'
68
- task :pull => "assets:local:sync"
69
-
70
- desc 'Synchronize your remote assets using local assets'
71
- task :push => "assets:remote:sync"
72
- end
73
-
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)
81
- end
82
- end
83
- end
84
-
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)
93
- end
94
- end
95
- end
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"
102
- 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, fetch(:stage) || '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
+ set :skip_data_sync_confirm, (ENV['SKIP_DATA_SYNC_CONFIRM'].to_s.downcase == 'true')
11
+ set :disallow_pushing, false unless fetch(:disallow_pushing)
12
+
13
+ namespace :capistrano_db_tasks do
14
+ task :check_can_push do
15
+ raise "pushing is disabled, set disallow_pushing to false to carry out this operation" if fetch(:disallow_pushing)
16
+ end
17
+ end
18
+
19
+ namespace :db do
20
+ namespace :remote do
21
+ desc 'Synchronize your remote database using local database data'
22
+ task :sync => 'capistrano_db_tasks:check_can_push' do
23
+ on roles(:db) do
24
+ if fetch(:skip_data_sync_confirm) || Util.prompt('Are you sure you want to REPLACE THE REMOTE DATABASE with local database')
25
+ Database.local_to_remote(self)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ namespace :local do
32
+ desc 'Synchronize your local database using remote database data'
33
+ task :sync do
34
+ on roles(:db) do
35
+ puts "Local database: #{Database::Local.new(self).database}"
36
+ if fetch(:skip_data_sync_confirm) || Util.prompt('Are you sure you want to erase your local database with server database')
37
+ Database.remote_to_local(self)
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ desc 'Synchronize your local database using remote database data'
44
+ task :pull => "db:local:sync"
45
+
46
+ desc 'Synchronize your remote database using local database data'
47
+ task :push => "db:remote:sync"
48
+ end
49
+
50
+ namespace :assets do
51
+ namespace :remote do
52
+ desc 'Synchronize your remote assets using local assets'
53
+ task :sync => 'capistrano_db_tasks:check_can_push' do
54
+ on roles(:app) do
55
+ puts "Assets directories: #{fetch(:assets_dir)}"
56
+ if fetch(:skip_data_sync_confirm) || Util.prompt("Are you sure you want to erase your server assets with local assets")
57
+ Asset.local_to_remote(self)
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ namespace :local do
64
+ desc 'Synchronize your local assets using remote assets'
65
+ task :sync do
66
+ on roles(:app) do
67
+ puts "Assets directories: #{fetch(:local_assets_dir)}"
68
+ if fetch(:skip_data_sync_confirm) || Util.prompt("Are you sure you want to erase your local assets with server assets")
69
+ Asset.remote_to_local(self)
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ desc 'Synchronize your local assets using remote assets'
76
+ task :pull => "assets:local:sync"
77
+
78
+ desc 'Synchronize your remote assets using local assets'
79
+ task :push => "assets:remote:sync"
80
+ end
81
+
82
+ namespace :app do
83
+ namespace :remote do
84
+ desc 'Synchronize your remote assets AND database using local assets and database'
85
+ task :sync => 'capistrano_db_tasks:check_can_push' do
86
+ if fetch(:skip_data_sync_confirm) || Util.prompt("Are you sure you want to REPLACE THE REMOTE DATABASE AND your remote assets with local database and assets(#{fetch(:assets_dir)})")
87
+ on roles(:db) do
88
+ Database.local_to_remote(self)
89
+ end
90
+
91
+ on roles(:app) do
92
+ Asset.local_to_remote(self)
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ namespace :local do
99
+ desc 'Synchronize your local assets AND database using remote assets and database'
100
+ task :sync do
101
+ puts "Local database : #{Database::Local.new(self).database}"
102
+ puts "Assets directories : #{fetch(:local_assets_dir)}"
103
+ if fetch(:skip_data_sync_confirm) || Util.prompt("Are you sure you want to erase your local database AND your local assets with server database and assets(#{fetch(:assets_dir)})")
104
+ on roles(:db) do
105
+ Database.remote_to_local(self)
106
+ end
107
+
108
+ on roles(:app) do
109
+ Asset.remote_to_local(self)
110
+ end
111
+ end
112
+ end
113
+ end
114
+
115
+ desc 'Synchronize your local assets AND database using remote assets and database'
116
+ task :pull => "app:local:sync"
117
+
118
+ desc 'Synchronize your remote assets AND database using local assets and database'
119
+ task :push => "app:remote:sync"
120
+ end
@@ -1,3 +1,3 @@
1
1
  module CapistranoDbTasks
2
- VERSION = "0.3"
2
+ VERSION = "0.4"
3
3
  end
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-db-tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
5
- prerelease:
4
+ version: '0.4'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Sebastien Gruhier
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-02-09 00:00:00.000000000 Z
11
+ date: 2015-02-26 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: capistrano
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.0.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 3.0.0
30
27
  description: A collection of capistrano tasks for syncing assets and databases
@@ -49,33 +46,26 @@ files:
49
46
  - test/test_helper.rb
50
47
  homepage: https://github.com/sgruhier/capistrano-db-tasks
51
48
  licenses: []
49
+ metadata: {}
52
50
  post_install_message:
53
51
  rdoc_options: []
54
52
  require_paths:
55
53
  - lib
56
54
  required_ruby_version: !ruby/object:Gem::Requirement
57
- none: false
58
55
  requirements:
59
- - - ! '>='
56
+ - - ">="
60
57
  - !ruby/object:Gem::Version
61
58
  version: '0'
62
- segments:
63
- - 0
64
- hash: 2376160182580984421
65
59
  required_rubygems_version: !ruby/object:Gem::Requirement
66
- none: false
67
60
  requirements:
68
- - - ! '>='
61
+ - - ">="
69
62
  - !ruby/object:Gem::Version
70
63
  version: '0'
71
- segments:
72
- - 0
73
- hash: 2376160182580984421
74
64
  requirements: []
75
65
  rubyforge_project: capistrano-db-tasks
76
- rubygems_version: 1.8.23
66
+ rubygems_version: 2.2.2
77
67
  signing_key:
78
- specification_version: 3
68
+ specification_version: 4
79
69
  summary: A collection of capistrano tasks for syncing assets and databases
80
70
  test_files:
81
71
  - test/capistrano_db_tasks_test.rb