mina-data_sync 0.1.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d58104d7068180adc905c2bd922ba4eee9666da
4
- data.tar.gz: 3805c517428a3161f12fef18c5c2f2a5cdf4946a
3
+ metadata.gz: 189a72cf302e49da6dd218a584a40b95dab6b84c
4
+ data.tar.gz: 45551eeefb495721775d139079ab737e5c6dd600
5
5
  SHA512:
6
- metadata.gz: df60b6a711f9d35d993324a41036109390db09a4da859eebcfe1ec45c481b4fdd78191edd440f4fb7d838158392235ea92cff29a1f2bd6dc551cae053e88ab4a
7
- data.tar.gz: 3f95e89310c6d1d7013e0243a3f97ec624af08922cd2793f3b57c48c7570031baf5884e0ec3cf20576fdda7f9a8133b6b9dfbe2891ab5fa126e16d45d1c65114
6
+ metadata.gz: fdd31793c16b9ce58c3506b09c6e70968272dd2cfb100b1f649fc0f6e9c7005129adf91f8492efafecee86fabc918e17dd41b6563dcc758cedb11e3c3944c838
7
+ data.tar.gz: 7b9b272a3016c70d326f4f51317ff6408961e8a86e5c7733b86d1fc1ffcace5b2731b185ee7a466b9a8b2dfd2e237a0421f947d9dbcb2ddb3809f9f5fde90f3e
data/config/database.yml CHANGED
@@ -1,46 +1,11 @@
1
- # MySQL. Versions 4.1 and 5.0 are recommended.
2
- #
3
- # Install the MYSQL driver
4
- # gem install mysql2
5
- #
6
- # Ensure the MySQL gem is defined in your Gemfile
7
- # gem 'mysql2'
8
- #
9
- # And be sure to use new-style password hashing:
10
- # http://dev.mysql.com/doc/refman/5.0/en/old-client.html
11
- development:
12
- adapter: mysql2
13
- encoding: utf8
14
- database: test
15
- pool: 5
16
- username: root
17
- password:
18
-
19
- # Warning: The database defined as "test" will be erased and
20
- # re-generated from your development database when you run "rake".
21
- # Do not set this db to the same as development or production.
22
- test:
23
- adapter: mysql2
1
+ default: &default
2
+ adapter: postgresql
24
3
  encoding: utf8
25
- database: psylog_test
26
4
  pool: 5
27
- username: root
5
+ username: postgres
28
6
  password:
29
7
 
30
- production:
31
- host: localhost
32
- adapter: mysql2
33
- encoding: utf8
34
- database: psylog_infinum_co
35
- pool: 5
36
- username: psylog_p
37
- password: DzmKmmMw
8
+ development:
9
+ <<: *default
10
+ database: truck_development_2
38
11
 
39
- staging:
40
- host: localhost
41
- adapter: mysql2
42
- encoding: utf8
43
- database: psylog_staging_infinum_co
44
- pool: 5
45
- username: psylog_s
46
- password: uRfbBD1S
@@ -1,28 +1,45 @@
1
- def read_conf(path, rails_env)
2
- @conf ||= YAML.load(ERB.new(File.read(path)).result)[rails_env]
3
- end
4
-
5
- def backup_file
6
- "#{@conf['database']}-#{Date.today}.sql"
7
- end
8
-
9
- def dump
10
- case @conf['adapter']
11
- when 'postgresql' then 'pg_dump'
12
- when 'mysql2' then 'mysqldump'
1
+ COMMAND = <<-RUBY
2
+ method = ARGV[0]
3
+ dc = JSON.parse(ARGV[2])
4
+ adapter = dc["adapter"]
5
+ database = dc["database"]
6
+ host = dc["host"]
7
+ username = dc["username"]
8
+ password = dc["password"]
9
+ port = dc["port"]
10
+ arguments = ""
11
+ case adapter.to_s
12
+ when "postgresql"
13
+ arguments += "PGPASSWORD=" + password if password
14
+ arguments += method == "dump" ? "pg_dump" : "psql -q"
15
+ arguments += " -d " + database if database
16
+ arguments += " -h " + host if host
17
+ arguments += " -U " + username if username
18
+ arguments += " -p " + port.to_s if port
19
+ arguments += " -O -c"
20
+ when "mysql2"
21
+ arguments += method == "dump" ? "mysqldump" : "mysql"
22
+ arguments += " " + database if database
23
+ arguments += " -h " + host if host
24
+ arguments += " -u " + username if username
25
+ arguments += " --password=" + password if password
26
+ arguments += " -P " + port.to_s if port
13
27
  end
14
- end
28
+ arguments += method == "dump" ? " > " : " < "
29
+ arguments += ARGV[1]
30
+ puts arguments
31
+ RUBY
15
32
 
16
- def restore
17
- case @conf['adapter']
18
- when 'postgresql' then 'psql -q'
19
- when 'mysql2' then 'mysql'
20
- end
33
+ DATA_SYNC = <<-BASH
34
+ function data_sync {
35
+ ruby -rjson -e '#{COMMAND}' "$@"
36
+ };
37
+ BASH
38
+
39
+ def config
40
+ "#{rails} runner 'puts ActiveRecord::Base.connection.instance_variable_get(:@config).to_json'"
21
41
  end
22
42
 
23
- def options
24
- case @conf['adapter']
25
- when 'postgresql' then '-O -c'
26
- when 'mysql2' then ''
27
- end
43
+ def backup_file
44
+ "#{repository.split('/').last.split('.').first}-#{rails_env}-#{Date.today}.sql"
28
45
  end
@@ -8,20 +8,20 @@ namespace :data_sync do
8
8
 
9
9
  queue "echo '-----> Dumping database'"
10
10
  queue "cd #{deploy_to}/#{current_path}"
11
- queue "ARGS=$(#{rake} mina_data_sync:config)"
11
+ queue "#{DATA_SYNC}"
12
12
  queue "mkdir -p #{remote_backup_path}"
13
- queue! 'echo $ARGS'
14
- queue! "#{dump} $ARGS #{options} > #{remote_backup_path}/#{backup_file}"
13
+ queue "CONFIG=$(#{rails} runner 'puts ActiveRecord::Base.connection.instance_variable_get(:@config).to_json')"
14
+ queue! %(eval $(data_sync "dump" "#{remote_backup_path}/#{backup_file}" "$CONFIG"))
15
15
 
16
16
  to :after_hook do
17
17
  queue "echo '-----> Copying backup'"
18
18
  queue "mkdir -p #{local_backup_path}"
19
+ queue "#{DATA_SYNC}"
19
20
  queue! "rsync --progress -e 'ssh -p #{port}' #{user}@#{domain}:#{deploy_to}/#{current_path}/#{remote_backup_path}/#{backup_file} #{local_backup_path}/#{backup_file}"
20
- queue "echo '-----> Restoring database'"
21
21
  if restore_data == 'true'
22
- queue "ARGS=$(#{rake} mina_data_sync:config)"
23
- queue! 'echo $ARGS'
24
- queue! "#{restore} $ARGS < #{local_backup_path}/#{backup_file}"
22
+ queue "echo '-----> Restoring database'"
23
+ queue "CONFIG=$(#{rails} runner 'puts ActiveRecord::Base.connection.instance_variable_get(:@config).to_json')"
24
+ queue %(eval $(data_sync "restore" "#{local_backup_path}/#{backup_file}" "$CONFIG"))
25
25
  end
26
26
  end
27
27
  end
@@ -31,8 +31,9 @@ namespace :data_sync do
31
31
 
32
32
  to :before_hook do
33
33
  queue "echo '-----> Dumping database'"
34
- queue "ARGS=$(conf #{database_path} development)"
35
- queue! "#{dump} $ARGS #{options} > #{local_backup_path}/#{backup_file}"
34
+ queue "#{DATA_SYNC}"
35
+ queue "CONFIG=$(#{rails} runner 'puts ActiveRecord::Base.connection.instance_variable_get(:@config).to_json')"
36
+ queue! %(eval $(data_sync "dump" "#{local_backup_path}/#{backup_file}" "$CONFIG"))
36
37
  queue "echo '-----> Copying backup'"
37
38
  queue! "rsync --progress -e 'ssh -p #{port}' #{local_backup_path}/#{backup_file} #{user}@#{domain}:#{deploy_to}/#{current_path}/#{remote_backup_path}/#{backup_file}"
38
39
  end
@@ -40,8 +41,8 @@ namespace :data_sync do
40
41
  if restore_data == 'true'
41
42
  queue "echo '-----> Restoring database'"
42
43
  queue "cd #{deploy_to}/#{current_path}"
43
- queue "ARGS=$(conf #{database_path} #{rails_env})"
44
- queue! "#{restore} $ARGS < #{deploy_to}/#{current_path}/#{remote_backup_path}/#{backup_file}"
44
+ queue "CONFIG=$(#{rails} runner 'puts ActiveRecord::Base.connection.instance_variable_get(:@config).to_json')"
45
+ queue %(eval $(data_sync "restore" "#{remote_backup_path}/#{backup_file}" "$CONFIG"))
45
46
  end
46
47
  end
47
48
  end
@@ -1,5 +1,5 @@
1
1
  module Mina
2
2
  module DataSync
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -7,13 +7,5 @@ require 'mina/data_sync/tasks'
7
7
 
8
8
  module Mina
9
9
  module DataSync
10
- if defined? Rails::Railtie
11
- require 'rails'
12
- class Railtie < Rails::Railtie
13
- rake_tasks do
14
- load 'tasks/config.rake'
15
- end
16
- end
17
- end
18
10
  end
19
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mina-data_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stjepan Hadjic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-22 00:00:00.000000000 Z
11
+ date: 2016-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,7 +85,6 @@ files:
85
85
  - lib/mina/data_sync/helpers.rb
86
86
  - lib/mina/data_sync/tasks.rb
87
87
  - lib/mina/data_sync/version.rb
88
- - lib/mina/tasks/config.rake
89
88
  - mina-data_sync.gemspec
90
89
  homepage: https://github.com/d4be4st/mina-data_sync
91
90
  licenses:
@@ -1,26 +0,0 @@
1
- namespace :mina_data_sync do
2
- task config: :environment do
3
- dc = ActiveRecord::Base.configurations[Rails.env].to_yaml
4
- adapter = dc['adapter']
5
- database = dc['database']
6
- host = dc['host']
7
- username = dc['username']
8
- password = dc['password']
9
- port = dc['port']
10
- arguments = ''
11
- case adapter.to_s
12
- when 'postgresql'
13
- arguments += ' -d ' + database if database
14
- arguments += ' -h ' + host if host
15
- arguments += ' -U ' + username if username
16
- arguments += ' -p ' + port.to_s if port
17
- when 'mysql2'
18
- arguments += ' ' + database if database
19
- arguments += ' -h ' + host if host
20
- arguments += ' -u ' + username if username
21
- arguments += ' --password=' + password if password
22
- arguments += ' -P ' + port.to_s if port
23
- end
24
- puts arguments
25
- end
26
- end