Skip to content

Commit adedf1c

Browse files
committed
Merge pull request #51 from IntractableQuery/master
Protect remote server from pushing
2 parents 8afc3f5 + 25f82f6 commit adedf1c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

README.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ Add to config/deploy.rb:
4343

4444
# if you want to work on a specific local environment (default = ENV['RAILS_ENV'] || 'development')
4545
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
4649
```
4750

4851
Add to .gitignore

lib/capistrano-db-tasks/dbtasks.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@
88
set :assets_dir, 'system' unless fetch(:assets_dir)
99
set :local_assets_dir, 'public' unless fetch(:local_assets_dir)
1010
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
1118

1219
namespace :db do
1320
namespace :remote do
1421
desc 'Synchronize your remote database using local database data'
15-
task :sync do
22+
task :sync => 'capistrano_db_tasks:check_can_push' do
1623
on roles(:db) do
1724
if fetch(:skip_data_sync_confirm) || Util.prompt('Are you sure you want to REPLACE THE REMOTE DATABASE with local database')
1825
Database.local_to_remote(self)
@@ -43,7 +50,7 @@
4350
namespace :assets do
4451
namespace :remote do
4552
desc 'Synchronize your remote assets using local assets'
46-
task :sync do
53+
task :sync => 'capistrano_db_tasks:check_can_push' do
4754
on roles(:app) do
4855
puts "Assets directories: #{fetch(:assets_dir)}"
4956
if fetch(:skip_data_sync_confirm) || Util.prompt("Are you sure you want to erase your server assets with local assets")
@@ -75,7 +82,7 @@
7582
namespace :app do
7683
namespace :remote do
7784
desc 'Synchronize your remote assets AND database using local assets and database'
78-
task :sync do
85+
task :sync => 'capistrano_db_tasks:check_can_push' do
7986
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)})")
8087
on roles(:db) do
8188
Database.local_to_remote(self)
@@ -110,4 +117,4 @@
110117

111118
desc 'Synchronize your remote assets AND database using local assets and database'
112119
task :push => "app:remote:sync"
113-
end
120+
end

0 commit comments

Comments
 (0)