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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23e7fa198b7f768db665cdf3f2817607065e14a3
4
- data.tar.gz: 4cb1921a81df400f094149ce22a152037ea89bb4
3
+ metadata.gz: e69cec59066ebbbfc828f42903230ee0448c9322
4
+ data.tar.gz: bb0fc6405d575a91229b436b622a82f479b24ed3
5
5
  SHA512:
6
- metadata.gz: 92fb33b8b8d30ba9e178a2fd69bb82c5f58b2fd172e17a1b303f358bbc6c1c832e0baf72c55a40f4c95d93faf078c3575407489a42cb09ca67d8af6ab5ec3882
7
- data.tar.gz: 8973045627fadb3538b5605e9c32eafff1dc2a95d6acd19c7ab2664afb438fdab3e96c672f56af9a9367e3f9f461b39534b079732ba4334a1079c080f41728e2
6
+ metadata.gz: 4c9b54d76b8decb4df3b4717200dae8af5c52b1a1d74e12e4c94f7457c845b8eb12c64e7859da49c413298c910a8f7bcb07402b64079bbfe8eadf8a9d22b0e4a
7
+ data.tar.gz: 9f1a439e96fcb283dc278a5ef4d80f4cb8617387973cdd16a21e08812ae51dd4a29be04503939e5a241e4e856943b379762f683d620f921875e0425f2e78b9ce
@@ -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.1'
5
+ s.version = '0.0.2'
6
6
  s.licenses = ['BSD-2-Clause']
7
7
 
8
8
  s.summary = 'Download remote database to local database'
@@ -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
@@ -1 +1,3 @@
1
+ require 'capistrano/db/database'
2
+
1
3
  load File.expand_path('../../tasks/db-pull.rake', __FILE__)
@@ -1,26 +1,36 @@
1
1
  namespace :db do
2
2
  task :pull do
3
3
  on roles(:db) do
4
- execute "pg_dump --data-only --exclude-table=schema_migrations --column-inserts | gzip -9 > #{fetch(:application)}.sql.gz"
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
- system "echo 'BEGIN;' > #{fetch(:application)}.sql"
10
- system "gunzip -c #{fetch(:application)}.sql.gz | sed '/^SET/ d' |\
11
- sed '/^SELECT pg_catalog.setval/ d' |\
12
- sed \"s/ true,/ 't',/g\" |\
13
- sed \"s/ false,/ 'f',/g\" |\
14
- sed \"s/(true/('t'/g\" |\
15
- sed \"s/(false/('f'/g\" |\
16
- sed \"s/true)/'t')/g\" |\
17
- sed \"s/false)/'f')/g\" >> #{fetch(:application)}.sql"
18
- system "echo 'END;' >> #{fetch(:application)}.sql"
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
- system "bin/rake db:drop && bin/rake db:schema:load &&
21
- cat #{fetch(:application)}.sql | sqlite3 db/development.sqlite3"
27
+ system "bin/rake db:drop && bin/rake db:schema:load &&
28
+ cat #{fetch(:application)}.sql | sqlite3 db/development.sqlite3"
22
29
 
23
- system "rm #{fetch(:application)}.sql"
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.1
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