capistrano-db-pull 0.0.2 → 0.0.3
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a027c0c483289dc7577a0c642bea055255e583e9
|
4
|
+
data.tar.gz: b9330f0a2cf9f0d7acbf2351703faf49e2d8ac93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c84368adc629e9ae81fe9f3c4be62e72008d9c909ac918cff290bb3ea75206946d4a383fee6449504d5721fd67ee5c1e99b3d95e91f235dfe827379c14e95de
|
7
|
+
data.tar.gz: f9354ef4d04d3bc9d5395c823f5b0ea628747480e611eff4c46197e1b7c592a9fdf71c301383f04fcbdf5e11cca08e0ad112f09f017250291de13c60a56ccec8
|
data/capistrano-db-pull.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
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
|
data/lib/capistrano/db/pull.rb
CHANGED
@@ -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 =
|
5
|
+
remote = Application::Remote.new(self, fetch(:stage) || 'production')
|
5
6
|
if remote.postgresql?
|
6
|
-
execute "
|
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 =
|
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 "
|
28
|
-
|
29
|
-
|
30
|
-
|
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.
|
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:
|
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
|
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.
|
64
|
+
rubygems_version: 2.5.2
|
64
65
|
signing_key:
|
65
66
|
specification_version: 4
|
66
67
|
summary: Download remote database to local database
|