capistrano-db-pull 0.0.1 → 0.0.2
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 +4 -4
- data/capistrano-db-pull.gemspec +1 -1
- data/lib/capistrano/db/database.rb +38 -0
- data/lib/capistrano/db/pull.rb +2 -0
- data/lib/capistrano/tasks/db-pull.rake +24 -14
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e69cec59066ebbbfc828f42903230ee0448c9322
|
4
|
+
data.tar.gz: bb0fc6405d575a91229b436b622a82f479b24ed3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c9b54d76b8decb4df3b4717200dae8af5c52b1a1d74e12e4c94f7457c845b8eb12c64e7859da49c413298c910a8f7bcb07402b64079bbfe8eadf8a9d22b0e4a
|
7
|
+
data.tar.gz: 9f1a439e96fcb283dc278a5ef4d80f4cb8617387973cdd16a21e08812ae51dd4a29be04503939e5a241e4e856943b379762f683d620f921875e0425f2e78b9ce
|
data/capistrano-db-pull.gemspec
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Database
|
2
|
+
class Base
|
3
|
+
attr_accessor :capistrano, :config
|
4
|
+
|
5
|
+
def initialize(instance)
|
6
|
+
@capistrano = instance
|
7
|
+
end
|
8
|
+
|
9
|
+
def postgresql?
|
10
|
+
adapter == 'pg' || adapter == 'postgresql'
|
11
|
+
end
|
12
|
+
|
13
|
+
def sqlite3?
|
14
|
+
adapter == 'sqlite3'
|
15
|
+
end
|
16
|
+
|
17
|
+
def adapter
|
18
|
+
@config['adapter'].downcase
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Remote < Base
|
23
|
+
def initialize(instance, stage)
|
24
|
+
super(instance)
|
25
|
+
config = @capistrano.capture(
|
26
|
+
"cat #{@capstrano.current_path}/config/database.yml")
|
27
|
+
@config = YAML.load(ERB.new(config).result)[stage.to_s]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Local < Base
|
32
|
+
def initialize(instance)
|
33
|
+
super(instance)
|
34
|
+
config = File.read('config/database.yml')
|
35
|
+
@config = YAML.load(ERB.new(config).result)['development']
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/capistrano/db/pull.rb
CHANGED
@@ -1,26 +1,36 @@
|
|
1
1
|
namespace :db do
|
2
2
|
task :pull do
|
3
3
|
on roles(:db) do
|
4
|
-
|
4
|
+
remote = Database::Remote.new(self, fetch(:stage) || 'production')
|
5
|
+
if remote.postgresql?
|
6
|
+
execute "pg_dump --data-only --exclude-table=schema_migrations --column-inserts | gzip -9 > #{fetch(:application)}.sql.gz"
|
7
|
+
else
|
8
|
+
raise "Remote database adapter '#{remote.adapter}' is currently unsupported"
|
9
|
+
end
|
5
10
|
download! "#{fetch(:application)}.sql.gz", "#{fetch(:application)}.sql.gz"
|
6
11
|
execute "rm #{fetch(:application)}.sql.gz"
|
7
12
|
end
|
8
13
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
local = Database::Local.new(self)
|
15
|
+
if local.sqlite3?
|
16
|
+
system "echo 'BEGIN;' > #{fetch(:application)}.sql"
|
17
|
+
system "gunzip -c #{fetch(:application)}.sql.gz | sed '/^SET/ d' |\
|
18
|
+
sed '/^SELECT pg_catalog.setval/ d' |\
|
19
|
+
sed \"s/ true,/ 't',/g\" |\
|
20
|
+
sed \"s/ false,/ 'f',/g\" |\
|
21
|
+
sed \"s/(true/('t'/g\" |\
|
22
|
+
sed \"s/(false/('f'/g\" |\
|
23
|
+
sed \"s/true)/'t')/g\" |\
|
24
|
+
sed \"s/false)/'f')/g\" >> #{fetch(:application)}.sql"
|
25
|
+
system "echo 'END;' >> #{fetch(:application)}.sql"
|
19
26
|
|
20
|
-
|
21
|
-
|
27
|
+
system "bin/rake db:drop && bin/rake db:schema:load &&
|
28
|
+
cat #{fetch(:application)}.sql | sqlite3 db/development.sqlite3"
|
22
29
|
|
23
|
-
|
30
|
+
system "rm #{fetch(:application)}.sql"
|
31
|
+
else
|
32
|
+
raise "Local database adapter '#{local.adapter}' is currently unsupported"
|
33
|
+
end
|
24
34
|
system "rm #{fetch(:application)}.sql.gz"
|
25
35
|
end
|
26
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Groeneveld
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- LICENSE
|
38
38
|
- capistrano-db-pull.gemspec
|
39
39
|
- lib/capistrano-db-pull.rb
|
40
|
+
- lib/capistrano/db/database.rb
|
40
41
|
- lib/capistrano/db/pull.rb
|
41
42
|
- lib/capistrano/tasks/db-pull.rake
|
42
43
|
homepage: https://github.com/ivaldi/capistrano-db-pull
|