capistrano-db-pull 0.0.2 → 0.0.3

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: e69cec59066ebbbfc828f42903230ee0448c9322
4
- data.tar.gz: bb0fc6405d575a91229b436b622a82f479b24ed3
3
+ metadata.gz: a027c0c483289dc7577a0c642bea055255e583e9
4
+ data.tar.gz: b9330f0a2cf9f0d7acbf2351703faf49e2d8ac93
5
5
  SHA512:
6
- metadata.gz: 4c9b54d76b8decb4df3b4717200dae8af5c52b1a1d74e12e4c94f7457c845b8eb12c64e7859da49c413298c910a8f7bcb07402b64079bbfe8eadf8a9d22b0e4a
7
- data.tar.gz: 9f1a439e96fcb283dc278a5ef4d80f4cb8617387973cdd16a21e08812ae51dd4a29be04503939e5a241e4e856943b379762f683d620f921875e0425f2e78b9ce
6
+ metadata.gz: 4c84368adc629e9ae81fe9f3c4be62e72008d9c909ac918cff290bb3ea75206946d4a383fee6449504d5721fd67ee5c1e99b3d95e91f235dfe827379c14e95de
7
+ data.tar.gz: f9354ef4d04d3bc9d5395c823f5b0ea628747480e611eff4c46197e1b7c592a9fdf71c301383f04fcbdf5e11cca08e0ad112f09f017250291de13c60a56ccec8
@@ -2,7 +2,7 @@ $:.push File.expand_path('../lib', __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'capistrano-db-pull'
5
- s.version = '0.0.2'
5
+ s.version = '0.0.3'
6
6
  s.licenses = ['BSD-2-Clause']
7
7
 
8
8
  s.summary = 'Download remote database to local database'
@@ -1,4 +1,4 @@
1
- module Database
1
+ module Application
2
2
  class Base
3
3
  attr_accessor :capistrano, :config
4
4
 
@@ -14,9 +14,17 @@ module Database
14
14
  adapter == 'sqlite3'
15
15
  end
16
16
 
17
+ def mysql?
18
+ adapter == 'mysql2' || adapter == 'mysql'
19
+ end
20
+
17
21
  def adapter
18
22
  @config['adapter'].downcase
19
23
  end
24
+
25
+ def database
26
+ @config['database']
27
+ end
20
28
  end
21
29
 
22
30
  class Remote < Base
@@ -0,0 +1,36 @@
1
+ module Database
2
+ def self.factory application
3
+ if application.postgresql?
4
+ Database::PostgreSQL.new
5
+ elsif application.sqlite3?
6
+ Database::SQLite3.new
7
+ elsif application.mysql?
8
+ Database::MySQL.new
9
+ else
10
+ raise 'Not implemented'
11
+ end
12
+ end
13
+
14
+ class Base
15
+
16
+ def dump
17
+ raise 'Not implemented'
18
+ end
19
+
20
+ def load filename
21
+ raise 'Not implemented'
22
+ end
23
+ end
24
+
25
+ class PostgreSQL < Base
26
+ def dump
27
+ "pg_dump --data-only --exclude-table=schema_migrations --column-inserts"
28
+ end
29
+ end
30
+
31
+ class Sqlite3 < Base
32
+ end
33
+
34
+ class MySQL < Base
35
+ end
36
+ end
@@ -1,3 +1,4 @@
1
- require 'capistrano/db/database'
1
+ require 'capistrano-db-pull/application'
2
+ require 'capistrano-db-pull/database'
2
3
 
3
4
  load File.expand_path('../../tasks/db-pull.rake', __FILE__)
@@ -1,9 +1,12 @@
1
1
  namespace :db do
2
2
  task :pull do
3
+ remote = nil
3
4
  on roles(:db) do
4
- remote = Database::Remote.new(self, fetch(:stage) || 'production')
5
+ remote = Application::Remote.new(self, fetch(:stage) || 'production')
5
6
  if remote.postgresql?
6
- execute "pg_dump --data-only --exclude-table=schema_migrations --column-inserts | gzip -9 > #{fetch(:application)}.sql.gz"
7
+ execute "#{Database.factory(remote).dump} | gzip -9 > #{fetch(:application)}.sql.gz"
8
+ elsif remote.mysql?
9
+ execute "mysqldump --skip-opt --no-create-info #{remote.database} | gzip -9 > #{fetch(:application)}.sql.gz"
7
10
  else
8
11
  raise "Remote database adapter '#{remote.adapter}' is currently unsupported"
9
12
  end
@@ -11,8 +14,8 @@ namespace :db do
11
14
  execute "rm #{fetch(:application)}.sql.gz"
12
15
  end
13
16
 
14
- local = Database::Local.new(self)
15
- if local.sqlite3?
17
+ local = Application::Local.new(self)
18
+ if remote.postgresql? && local.sqlite3?
16
19
  system "echo 'BEGIN;' > #{fetch(:application)}.sql"
17
20
  system "gunzip -c #{fetch(:application)}.sql.gz | sed '/^SET/ d' |\
18
21
  sed '/^SELECT pg_catalog.setval/ d' |\
@@ -23,14 +26,18 @@ namespace :db do
23
26
  sed \"s/true)/'t')/g\" |\
24
27
  sed \"s/false)/'f')/g\" >> #{fetch(:application)}.sql"
25
28
  system "echo 'END;' >> #{fetch(:application)}.sql"
26
-
27
- system "bin/rake db:drop && bin/rake db:schema:load &&
28
- cat #{fetch(:application)}.sql | sqlite3 db/development.sqlite3"
29
-
30
- system "rm #{fetch(:application)}.sql"
29
+ elsif remote.mysql? && local.sqlite3?
30
+ system "gunzip -c #{fetch(:application)}.sql.gz |
31
+ sed 's/\\`//g' |
32
+ sed \"s/\\\'/\'\'/g\" |
33
+ sed 's/\\\"/\"/g' > #{fetch(:application)}.sql"
31
34
  else
32
35
  raise "Local database adapter '#{local.adapter}' is currently unsupported"
33
36
  end
37
+ system "bin/rake db:drop && bin/rake db:schema:load &&
38
+ cat #{fetch(:application)}.sql | sqlite3 db/development.sqlite3"
39
+
40
+ system "rm #{fetch(:application)}.sql"
34
41
  system "rm #{fetch(:application)}.sql.gz"
35
42
  end
36
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-db-pull
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Groeneveld
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-19 00:00:00.000000000 Z
11
+ date: 2017-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -37,7 +37,8 @@ files:
37
37
  - LICENSE
38
38
  - capistrano-db-pull.gemspec
39
39
  - lib/capistrano-db-pull.rb
40
- - lib/capistrano/db/database.rb
40
+ - lib/capistrano-db-pull/application.rb
41
+ - lib/capistrano-db-pull/database.rb
41
42
  - lib/capistrano/db/pull.rb
42
43
  - lib/capistrano/tasks/db-pull.rake
43
44
  homepage: https://github.com/ivaldi/capistrano-db-pull
@@ -60,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
61
  version: '0'
61
62
  requirements: []
62
63
  rubyforge_project:
63
- rubygems_version: 2.5.1
64
+ rubygems_version: 2.5.2
64
65
  signing_key:
65
66
  specification_version: 4
66
67
  summary: Download remote database to local database