-
Notifications
You must be signed in to change notification settings - Fork 177
/
dbtasks.rb
146 lines (127 loc) · 5.24 KB
/
dbtasks.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
require File.expand_path("#{File.dirname(__FILE__)}/util")
require File.expand_path("#{File.dirname(__FILE__)}/database")
require File.expand_path("#{File.dirname(__FILE__)}/asset")
require File.expand_path("#{File.dirname(__FILE__)}/compressors/base")
require File.expand_path("#{File.dirname(__FILE__)}/compressors/bzip2")
require File.expand_path("#{File.dirname(__FILE__)}/compressors/gzip")
require File.expand_path("#{File.dirname(__FILE__)}/compressors/zstd")
set :local_rails_env, ENV['RAILS_ENV'] || 'development' unless fetch(:local_rails_env)
set :rails_env, fetch(:stage) || 'production' unless fetch(:rails_env)
set :db_local_clean, false unless fetch(:db_local_clean)
set :assets_dir, 'system' unless fetch(:assets_dir)
set :local_assets_dir, 'public' unless fetch(:local_assets_dir)
set :skip_data_sync_confirm, ENV['SKIP_DATA_SYNC_CONFIRM'].to_s.casecmp('true').zero?
set :disallow_pushing, false unless fetch(:disallow_pushing)
set :compressor, :gzip unless fetch(:compressor)
namespace :capistrano_db_tasks do
task :check_can_push do
raise "pushing is disabled, set disallow_pushing to false to carry out this operation" if fetch(:disallow_pushing)
end
end
namespace :db do
namespace :remote do
desc 'Synchronize your remote database using local database data'
task :sync => 'capistrano_db_tasks:check_can_push' do
on roles(:db) do
if fetch(:skip_data_sync_confirm) || Util.prompt('Are you sure you want to REPLACE THE REMOTE DATABASE with local database')
Database.local_to_remote(self)
end
end
end
end
namespace :local do
desc 'Synchronize your local database using remote database data'
task :sync do
on roles(:db) do
puts "Local database: #{Database::Local.new(self).database}"
if fetch(:skip_data_sync_confirm) || Util.prompt('Are you sure you want to erase your local database with server database')
Database.remote_to_local(self)
end
end
end
desc 'Replace your local database using a dump file from the DUMP_FILE ' \
'environment variable'
task :load do
run_locally do
if ENV['DUMP_FILE'].nil?
raise 'You must give a dump file using the DUMP_FILE environment ' \
'variable'
end
unless File.exist?(ENV['DUMP_FILE'])
raise "File #{ENV['DUMP_FILE']} doesn't exists"
end
if fetch(:skip_data_sync_confirm) ||
Util.prompt('Are you sure you want to erase your local database ' \
"with the dump file #{ENV['DUMP_FILE']}")
Database.local_to_local(self, ENV['DUMP_FILE'])
end
end
end
end
desc 'Synchronize your local database using remote database data'
task :pull => "db:local:sync"
desc 'Synchronize your remote database using local database data'
task :push => "db:remote:sync"
end
namespace :assets do
namespace :remote do
desc 'Synchronize your remote assets using local assets'
task :sync => 'capistrano_db_tasks:check_can_push' do
on roles(:app) do
puts "Assets directories: #{fetch(:assets_dir)}"
if fetch(:skip_data_sync_confirm) || Util.prompt("Are you sure you want to erase your server assets with local assets")
Asset.local_to_remote(self)
end
end
end
end
namespace :local do
desc 'Synchronize your local assets using remote assets'
task :sync do
on roles(:app) do
puts "Assets directories: #{fetch(:local_assets_dir)}"
if fetch(:skip_data_sync_confirm) || Util.prompt("Are you sure you want to erase your local assets with server assets")
Asset.remote_to_local(self)
end
end
end
end
desc 'Synchronize your local assets using remote assets'
task :pull => "assets:local:sync"
desc 'Synchronize your remote assets using local assets'
task :push => "assets:remote:sync"
end
namespace :app do
namespace :remote do
desc 'Synchronize your remote assets AND database using local assets and database'
task :sync => 'capistrano_db_tasks:check_can_push' do
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)})")
on roles(:db) do
Database.local_to_remote(self)
end
on roles(:app) do
Asset.local_to_remote(self)
end
end
end
end
namespace :local do
desc 'Synchronize your local assets AND database using remote assets and database'
task :sync do
puts "Local database : #{Database::Local.new(self).database}"
puts "Assets directories : #{fetch(:local_assets_dir)}"
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)})")
on roles(:db) do
Database.remote_to_local(self)
end
on roles(:app) do
Asset.remote_to_local(self)
end
end
end
end
desc 'Synchronize your local assets AND database using remote assets and database'
task :pull => "app:local:sync"
desc 'Synchronize your remote assets AND database using local assets and database'
task :push => "app:remote:sync"
end