capistrano-db-sync 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1c9cd18b08af220dcea5414d5c4a947c223d6bb
4
- data.tar.gz: 32ae9194356ffdb7022165dab9983668c3134682
3
+ metadata.gz: 61a00da50099a5a15b3e8c8281064a1a7f2bc759
4
+ data.tar.gz: 637491ea039f1b33ed2b0a5247002a4133653725
5
5
  SHA512:
6
- metadata.gz: e78718114f19a18a0e55f0e74dca83e4bd92798e02b6beee297f71bd402d4b0e7f303bf1042308800c41d904359361d0324db5bacf571e62325ee234131026dd
7
- data.tar.gz: dabdefa1175834c6f4d87bc4cf050c4fcf5dfa1e80c4e61b71666e10101cd2f204c0184729dced0520b0e94402d8b6fb2244e52c7711229c1ed599e7b0777eab
6
+ metadata.gz: 2227e4376dca58e3a0a563019fb60d28f7d650dc0d0ea33e5d6fa481d38c6cfe5e07e9484fb4b750cc71f2ea5e99be4464353ef09fe3557d3b4ef1dff962bc3b
7
+ data.tar.gz: 4f1c40b19b59b844d30724ecadd6683be3d0a9983e234c541b6c40a03a8148a55ed1d76036091e27806148ed12ecd1b4c63d08bbd945e5c55fa01442699e5732
data/README.md CHANGED
@@ -1,9 +1,22 @@
1
1
  # capistrano-db-sync
2
2
 
3
- ### Usage
3
+ ## Install
4
4
 
5
- Add the gem to your gemfile:
5
+ Download and install the gem :
6
6
 
7
7
  ```ruby
8
- gem 'capistrano-db-sync'
9
- ```
8
+ gem install capistrano-db-sync
9
+ ```
10
+
11
+ Add to Capfile :
12
+
13
+ ```ruby
14
+ require 'capistrano/db-sync'
15
+ ```
16
+
17
+ ## Available tasks
18
+ ```
19
+ db:sync:pull # Synchronize your local database using remote database
20
+ db:sync:push # Synchronize your remote database using local database
21
+ ```
22
+
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'capistrano-db-sync'
7
- spec.version = '0.0.12'
7
+ spec.version = '0.0.13'
8
8
  spec.date = Date.today.to_s
9
9
  spec.summary = "Capistrano synchronization databases task"
10
10
  spec.description = "Capistrano synchronization task for syncing databases between the local development environment and different multi_stage environments"
@@ -0,0 +1,15 @@
1
+ class Connexion
2
+ #attr_accessor :username, password, database, host
3
+
4
+ def initialize(config_file, db)
5
+ config = YAML::load_file(config_file)
6
+ puts "testdd"
7
+
8
+ #@username = database["#{db}"]['user']
9
+ @password = database["#{db}"]['password']
10
+ #@database = database["#{db}"]['dbname']
11
+ #@host = database["#{db}"]['host']
12
+ puts @password
13
+ end
14
+
15
+ end
@@ -0,0 +1,54 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/connexion")
2
+
3
+ class Database
4
+
5
+
6
+ def initialize(config_file = fetch(:filename) || 'config/database.yml')
7
+ @config_file = config_file
8
+ end
9
+
10
+ def dump
11
+ #dump_file = "dump.local.#{Time.now.strftime '%Y-%m-%d_%H-%M-%S'}.sql"
12
+ #username, password, database, host = database_config('development')
13
+ #system "mysqldump -u #{username} --password=#{password} #{database} > #{dump_file}"
14
+ end
15
+
16
+ def sync_dir
17
+ execute :mkdir, "-p #{shared_path}/sync"
18
+ end
19
+
20
+ end
21
+
22
+ #
23
+ # The remote database
24
+ #
25
+ class Remote < Database
26
+
27
+ #def initialize
28
+ # puts "yyy"
29
+
30
+ #Connexion.new(config_file, 'stage')
31
+ #end
32
+
33
+ # Download the dump file to the local directory
34
+ def download
35
+ local_file = "#{shared_path}/sync/#{dump_file}"
36
+
37
+ download! dump_file, local_file
38
+ end
39
+
40
+ end
41
+
42
+ #
43
+ # The local database
44
+ #
45
+ class Locale < Database
46
+
47
+ # Upload the dump file to the shared directory
48
+ def upload
49
+ remote_file = "#{shared_path}/sync/#{dump_file}"
50
+
51
+ upload! dump_file, remote_file
52
+ end
53
+
54
+ end
@@ -1,7 +1,13 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/database")
2
+
1
3
  namespace :db do
2
4
 
3
5
  namespace :sync do
4
6
 
7
+ desc <<-DESC
8
+ Push the current local development database to the remote database from the selected stage
9
+ environment. The database credentials will be read from the remote config/database.yml file.
10
+ DESC
5
11
  task :local_to_remote do
6
12
 
7
13
  on roles(:all) do
@@ -17,6 +23,8 @@ namespace :db do
17
23
 
18
24
  # Export du fichier SQL
19
25
  upload! filename, "#{shared_path}/sync/#{filename}"
26
+
27
+ # Suppression du fichier SQL de la base de données locale
20
28
  system "rm -f #{filename}"
21
29
 
22
30
  # Import de la base de données
@@ -27,6 +35,33 @@ namespace :db do
27
35
 
28
36
  end
29
37
 
38
+
39
+ desc <<-DESC
40
+ Retrieves a remote database from the selected stage environment to the local development
41
+ environment. The database credentials will be read from your local config/database.yml file.
42
+ DESC
43
+ task :remote_to_locale do
44
+ on roles(:all) do
45
+ # Backup de la base donnée distante
46
+
47
+ # Création du fichier SQL de la base de données distante
48
+ filename = "dump.local.#{Time.now.strftime '%Y-%m-%d_%H-%M-%S'}.sql"
49
+ username, password, database, host = remote_database_config('stage')
50
+ execute "mysqldump -u #{username} --password=#{password} #{database} > #{shared_path}/sync/#{filename}"
51
+
52
+ # Import du fichier SQL
53
+ download! "#{shared_path}/sync/#{filename}", filename
54
+
55
+ # Import de la base de données
56
+ username, password, database, host = remote_database_config(:stage)
57
+ hostcmd = host.nil? ? '' : "-h #{host}"
58
+ system "mysql -u #{username} --password=#{password} #{database} #{hostcmd} < #{filename}"
59
+
60
+ # Suppression du fichier SQL de la base de données distante
61
+ system "rm -f #{filename}"
62
+ end
63
+ end
64
+
30
65
  end
31
66
 
32
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-db-sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Albuisson Stéphane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-12 00:00:00.000000000 Z
11
+ date: 2017-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -37,6 +37,8 @@ files:
37
37
  - capistrano-db-sync.gemspec
38
38
  - lib/capistrano-db-sync.rb
39
39
  - lib/capistrano/db-sync.rb
40
+ - lib/capistrano/tasks/connexion.rb
41
+ - lib/capistrano/tasks/database.rb
40
42
  - lib/capistrano/tasks/db.rake
41
43
  homepage: http://www.stephane-albuisson.com
42
44
  licenses: