capistrano-db-pull 0.0.2 → 0.0.7

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
- SHA1:
3
- metadata.gz: e69cec59066ebbbfc828f42903230ee0448c9322
4
- data.tar.gz: bb0fc6405d575a91229b436b622a82f479b24ed3
2
+ SHA256:
3
+ metadata.gz: 959e3144ad4b91152306572d1b3f7610d1efc46c28bd4924c81985579b7c16a8
4
+ data.tar.gz: 82edccf2b386f5f3045062c0846dbe4d16cdc77c3db7c1c4d845cfd248e343d6
5
5
  SHA512:
6
- metadata.gz: 4c9b54d76b8decb4df3b4717200dae8af5c52b1a1d74e12e4c94f7457c845b8eb12c64e7859da49c413298c910a8f7bcb07402b64079bbfe8eadf8a9d22b0e4a
7
- data.tar.gz: 9f1a439e96fcb283dc278a5ef4d80f4cb8617387973cdd16a21e08812ae51dd4a29be04503939e5a241e4e856943b379762f683d620f921875e0425f2e78b9ce
6
+ metadata.gz: 0a88169c55c9efc7879b92e412ee4dc2778918e1f000742388409f0206d0ad6208d1f772ff48d8a5cbc3098d81cc2c3d39158abe50b69ecf2e7bce6707cd5850
7
+ data.tar.gz: 86c8f170501841bd7249195f2e12b0efcce991be6ebd4872a4af11348087d24a12c00dc54160bae2d8032e99916d775bca8e0943a60d9b75a66a3011fb4151f7
@@ -0,0 +1,12 @@
1
+ # Capistrano DB Pull
2
+
3
+ Replace your local development database with a database pulled from the server.
4
+
5
+ ## Getting Started
6
+
7
+ * Add `gem capistrano-db-pull` to the :development group in your Gemfile
8
+ * Add `require 'capistrano/db/pull` to your Capfile
9
+
10
+ ## How To Use
11
+
12
+ * Run `cap <STAGE> db:pull`, e.g. `cap production db:pull` to pull your production database
@@ -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.7'
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,33 @@
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
+ end
27
+
28
+ class Sqlite3 < Base
29
+ end
30
+
31
+ class MySQL < Base
32
+ end
33
+ 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,16 @@
1
1
  namespace :db do
2
2
  task :pull do
3
+ remote = nil
4
+ local = Application::Local.new(self)
5
+
3
6
  on roles(:db) do
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
+ remote = Application::Remote.new(self, fetch(:rails_env) || 'production')
8
+ if remote.postgresql? && local.postgresql?
9
+ execute "pg_dump --no-owner #{remote.database} | gzip -9 > #{fetch(:application)}.sql.gz"
10
+ elsif remote.postgresql? && local.sqlite3?
11
+ execute "pg_dump --data-only --exclude-table=schema_migrations --column-inserts #{remote.database} | gzip -9 > #{fetch(:application)}.sql.gz"
12
+ elsif remote.mysql?
13
+ execute "mysqldump --skip-opt --routines --triggers --events #{remote.database} | gzip -9 > #{fetch(:application)}.sql.gz"
7
14
  else
8
15
  raise "Remote database adapter '#{remote.adapter}' is currently unsupported"
9
16
  end
@@ -11,8 +18,11 @@ namespace :db do
11
18
  execute "rm #{fetch(:application)}.sql.gz"
12
19
  end
13
20
 
14
- local = Database::Local.new(self)
15
- if local.sqlite3?
21
+ if remote.postgresql? && local.postgresql?
22
+ system 'bin/rake db:drop && bin/rake db:create'
23
+ system "gunzip -c #{fetch(:application)}.sql.gz | psql #{local.database}"
24
+ system 'bin/rails db:environment:set RAILS_ENV=development'
25
+ elsif remote.postgresql? && local.sqlite3?
16
26
  system "echo 'BEGIN;' > #{fetch(:application)}.sql"
17
27
  system "gunzip -c #{fetch(:application)}.sql.gz | sed '/^SET/ d' |\
18
28
  sed '/^SELECT pg_catalog.setval/ d' |\
@@ -23,14 +33,25 @@ namespace :db do
23
33
  sed \"s/true)/'t')/g\" |\
24
34
  sed \"s/false)/'f')/g\" >> #{fetch(:application)}.sql"
25
35
  system "echo 'END;' >> #{fetch(:application)}.sql"
26
-
27
36
  system "bin/rake db:drop && bin/rake db:schema:load &&
28
37
  cat #{fetch(:application)}.sql | sqlite3 db/development.sqlite3"
29
-
30
- system "rm #{fetch(:application)}.sql"
38
+ elsif remote.mysql? && local.sqlite3?
39
+ system "gunzip -c #{fetch(:application)}.sql.gz |
40
+ sed 's/\\`//g' |
41
+ sed \"s/\\\\\\\'/\'\'/g\" |
42
+ sed 's/\\\"/\"/g' > #{fetch(:application)}.sql"
43
+ system "bin/rake db:drop && bin/rake db:schema:load &&
44
+ cat #{fetch(:application)}.sql | sqlite3 db/development.sqlite3"
45
+ elsif remote.mysql? && local.mysql?
46
+ system 'bin/rake db:drop'
47
+ system 'bin/rake db:create'
48
+ system "gunzip -c #{fetch(:application)}.sql.gz | mysql #{local.database}"
49
+ system 'bin/rails db:environment:set RAILS_ENV=development'
31
50
  else
32
51
  raise "Local database adapter '#{local.adapter}' is currently unsupported"
33
52
  end
34
- system "rm #{fetch(:application)}.sql.gz"
53
+
54
+ system "rm -f #{fetch(:application)}.sql"
55
+ system "rm -f #{fetch(:application)}.sql.gz"
35
56
  end
36
57
  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.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Groeneveld
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-19 00:00:00.000000000 Z
11
+ date: 2020-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -35,16 +35,18 @@ extra_rdoc_files: []
35
35
  files:
36
36
  - ".gitignore"
37
37
  - LICENSE
38
+ - README.md
38
39
  - capistrano-db-pull.gemspec
39
40
  - lib/capistrano-db-pull.rb
40
- - lib/capistrano/db/database.rb
41
+ - lib/capistrano-db-pull/application.rb
42
+ - lib/capistrano-db-pull/database.rb
41
43
  - lib/capistrano/db/pull.rb
42
44
  - lib/capistrano/tasks/db-pull.rake
43
45
  homepage: https://github.com/ivaldi/capistrano-db-pull
44
46
  licenses:
45
47
  - BSD-2-Clause
46
48
  metadata: {}
47
- post_install_message:
49
+ post_install_message:
48
50
  rdoc_options: []
49
51
  require_paths:
50
52
  - lib
@@ -59,9 +61,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
61
  - !ruby/object:Gem::Version
60
62
  version: '0'
61
63
  requirements: []
62
- rubyforge_project:
63
- rubygems_version: 2.5.1
64
- signing_key:
64
+ rubygems_version: 3.1.4
65
+ signing_key:
65
66
  specification_version: 4
66
67
  summary: Download remote database to local database
67
68
  test_files: []