Skip to content

Commit 25f82f6

Browse files
Deduplicate push checking
1 parent ae25656 commit 25f82f6

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/capistrano-db-tasks/dbtasks.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@
1010
set :skip_data_sync_confirm, (ENV['SKIP_DATA_SYNC_CONFIRM'].to_s.downcase == 'true')
1111
set :disallow_pushing, false unless fetch(:disallow_pushing)
1212

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+
1319
namespace :db do
1420
namespace :remote do
1521
desc 'Synchronize your remote database using local database data'
16-
task :sync do
22+
task :sync => 'capistrano_db_tasks:check_can_push' do
1723
on roles(:db) do
18-
raise "pushing is disabled, set disallow_pushing to false to carry out this operation" if fetch(:disallow_pushing)
1924
if fetch(:skip_data_sync_confirm) || Util.prompt('Are you sure you want to REPLACE THE REMOTE DATABASE with local database')
2025
Database.local_to_remote(self)
2126
end
@@ -45,10 +50,9 @@
4550
namespace :assets do
4651
namespace :remote do
4752
desc 'Synchronize your remote assets using local assets'
48-
task :sync do
53+
task :sync => 'capistrano_db_tasks:check_can_push' do
4954
on roles(:app) do
5055
puts "Assets directories: #{fetch(:assets_dir)}"
51-
raise "pushing is disabled, set disallow_pushing to false to carry out this operation" if fetch(:disallow_pushing)
5256
if fetch(:skip_data_sync_confirm) || Util.prompt("Are you sure you want to erase your server assets with local assets")
5357
Asset.local_to_remote(self)
5458
end
@@ -78,8 +82,7 @@
7882
namespace :app do
7983
namespace :remote do
8084
desc 'Synchronize your remote assets AND database using local assets and database'
81-
task :sync do
82-
raise "pushing is disabled, set disallow_pushing to false to carry out this operation" if fetch(:disallow_pushing)
85+
task :sync => 'capistrano_db_tasks:check_can_push' do
8386
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)})")
8487
on roles(:db) do
8588
Database.local_to_remote(self)

0 commit comments

Comments
 (0)