db_dumper 0.5.2 → 0.5.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
  SHA256:
3
- metadata.gz: ae74a3eb271dba85c9185c0e805fae78b68fd055bcbdd85d5a5d485d62fa9237
4
- data.tar.gz: 18a0336e0b869ae4b08662a5e4cc07f16cf80596f45b04eceb6843d1961c1c50
3
+ metadata.gz: 18914983a2e3a39e23fd891de9ff495eda36da6bd23be62c1b41f17f144070e5
4
+ data.tar.gz: b025dc6ca5704703b2205805876659669b9d9f069613bae776226fc2a06979ea
5
5
  SHA512:
6
- metadata.gz: 543832e4c9e6d37a1b4384325afa7e655a8d01fa76d80cd9563af1b90faf10c236549ae7e4700a146b29079d6c0f5fe541c18fa69336dca5c37bbe946558e477
7
- data.tar.gz: f5837c1c71534c1448ef19a572e7b655a56b4720afc77de90628189a746d69cbabe27588f6c587e8c4736b8098f0e68330e5753d174a82f6a47412506381fd08
6
+ metadata.gz: 145c849770ae6173546fc52dc87940cf57c1ca6bc2384351e19056e088068514993853b0082ddafa88b9d26f8c8842b4d15c4dc11d010cb14a0ca18b141d79f0
7
+ data.tar.gz: e98b614cdd9d491d6837f2405d5b76068301007e2043f1775b5b1abbd3ad842a7a3f65cc17adaad059b37fb0d3f2341d292e1087c9b0e86d3d8b1c3b337d584d
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # DB dumper - configurable SQL database data copying util from remote to local machine.
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/db_dumper.svg)](https://badge.fury.io/rb/db_dumper)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/d5676f2dca807bdc458b/maintainability)](https://codeclimate.com/github/alukyanov/db_dumper/maintainability)
4
5
 
5
6
  ## Index
6
7
  - [Usage](#usage)
@@ -10,6 +11,8 @@
10
11
  - [Bundler](#or-if-you-are-using-bundler)
11
12
 
12
13
  ## Usage
14
+ - Setup config/application.yml file properly.
15
+ - Install pg_dump, psql utils on remote machine for PostgreSQL adapter.
13
16
 
14
17
  Example for simple Ruby file:
15
18
 
@@ -25,10 +28,10 @@ end
25
28
 
26
29
  DbDumper.dump do
27
30
  user_id = 1
28
- dump('users').where(id: user_id)
31
+ dump q('users').where(id: user_id)
29
32
  campaigns_q = q('campaigns').where('user_id = ? OR for_all IS TRUE', user_id)
30
- dump(campaigns_q)
31
- dump('offices').where(campaign_id: campaigns_q.ar)
33
+ dump campaigns_q
34
+ dump q('offices').where(campaign_id: campaigns_q.ar)
32
35
  end
33
36
  ```
34
37
 
@@ -39,6 +42,10 @@ After executing you will see:
39
42
 
40
43
  ### Config
41
44
 
45
+ #### remote_db
46
+ ##### adapter
47
+ Currently supported only postgres adapter, so you can dump only PostgreSQL.
48
+
42
49
  Config file example at config/application.yml
43
50
 
44
51
  ```
@@ -63,10 +70,6 @@ local_machine:
63
70
  dest_path: /tmp
64
71
  ```
65
72
 
66
- ### Testing
67
-
68
- No tests fo now
69
-
70
73
  ## <a id="installation">Installation ##
71
74
 
72
75
  ### Manually from RubyGems.org ###
@@ -122,4 +125,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
122
125
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
123
126
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
124
127
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
125
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
128
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -17,15 +17,14 @@ module DbDumper
17
17
 
18
18
  # DSL start
19
19
 
20
- # creates new query and add it to resulting queries array
20
+ # add query to current dump
21
21
  def dump(query)
22
- query = q(query) if query.is_a?(String)
23
- query.tap { |q| queries << q }
22
+ queries << query
24
23
  end
25
24
 
26
25
  # creates new query
27
- def q(table_name)
28
- Query.new Table.from(table_name.to_s)
26
+ def q(raw_table)
27
+ Query.new(raw_table)
29
28
  end
30
29
 
31
30
  # DSL end
@@ -7,22 +7,22 @@ module DbDumper
7
7
 
8
8
  delegate :table_name, to: :table
9
9
 
10
- def initialize(table)
11
- @table = table
12
- @ar = @table.ar.all
10
+ def initialize(raw_table, exist_ar = nil)
11
+ @table = Table.from(raw_table)
12
+ @ar = exist_ar || table.ar.all
13
13
  end
14
14
 
15
15
  def where(*args)
16
- tap { @ar = @ar.where(*args) }
16
+ self.class.new(table, ar.where(*args))
17
17
  end
18
18
 
19
19
  def joins(*args)
20
20
  raise 'Only simple string for joins supported' unless args.size == 1 && args[0].is_a?(String)
21
- tap { @ar = @ar.joins(*args) }
21
+ self.class.new(table, ar.joins(*args))
22
22
  end
23
23
 
24
24
  def select(*args)
25
- tap { @ar = @ar.select(*args) }
25
+ self.class.new(table, ar.select(*args))
26
26
  end
27
27
 
28
28
  def to_sql
@@ -7,10 +7,13 @@ module DbDumper
7
7
 
8
8
  @tables = {}
9
9
 
10
- def self.from(table_name)
11
- @tables[table_name] ||= begin
12
- ActiveRecord::Migration.create_table(table_name)
13
- new(table_name)
10
+ def self.from(raw_table)
11
+ return raw_table if raw_table.is_a?(Table)
12
+
13
+ table_name_str = raw_table.to_s
14
+ @tables[table_name_str] ||= begin
15
+ ActiveRecord::Migration.create_table(table_name_str)
16
+ new(table_name_str)
14
17
  end
15
18
  end
16
19
 
@@ -1,3 +1,3 @@
1
1
  module DbDumper
2
- VERSION = '0.5.2'
2
+ VERSION = '0.5.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db_dumper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Lukyanov
@@ -96,7 +96,7 @@ licenses:
96
96
  metadata:
97
97
  bug_tracker_uri: https://github.com/alukyanov/db_dumper/issues
98
98
  changelog_uri: https://github.com/alukyanov/db_dumper/CHANGELOG.md
99
- documentation_uri: http://www.rubydoc.info/gems/db_dumper/0.5.2
99
+ documentation_uri: http://www.rubydoc.info/gems/db_dumper/0.5.3
100
100
  homepage_uri: https://github.com/alukyanov/db_dumper
101
101
  source_code_uri: https://github.com/alukyanov/db_dumper
102
102
  wiki_uri: https://github.com/alukyanov/db_dumper/wiki