yaml_db 0.5.0 → 0.6.0

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: 8a4e39c17d583195897d45248f0aca67b9cbdb31
4
- data.tar.gz: fdcf74702568fb3fafe04cd4956a0c25cf9f4c48
3
+ metadata.gz: 97ea4b448b5e237251d13e2c8b5393a594105e56
4
+ data.tar.gz: 98c49ef9d688d45c18bc94cda62a8816969cc2b0
5
5
  SHA512:
6
- metadata.gz: 228b520f88360a5fc698f5809bc0b917c6669d74156c7d0f174631c59c76d8bcb3b09e9eaa982cff136f5bf8a1e9ea59cc99391a6bc570d3548c2f39c998ea8b
7
- data.tar.gz: 0e329ffcd25e425cd75da70cc8ebc51299c14308d3614169b6692f186c876c725ce3b6da9e63657a698655e5d3acfd0b649d029d0d677dc477f6dbea2e053f05
6
+ metadata.gz: ac7599aa51c7a3ee0237d849c008cb48abdb9d63fd3ff83ead8bf811fb06bf7e44ceb576a4beb4ff3635a0ac0b6fb4643f65a58d14cf6de4aff669e8c3a3984b
7
+ data.tar.gz: ed53717fa314f06618fd810f880ace40400b3be74a57d6814cfe7b9844d29c2288ee148232d2aca5bc200b329d68efedb1a9aa63963237376d1e94275dfe9e00
data/README.md CHANGED
@@ -6,7 +6,7 @@ This can be used as a replacement for mysqldump or pg_dump, but only for the dat
6
6
 
7
7
  Any database that has an ActiveRecord adapter should work.
8
8
 
9
- This gem supports Rails 3.x, 4.x, and 5.0.
9
+ This gem supports Rails versions 3.0 through 5.1.
10
10
 
11
11
  [![Build Status](https://travis-ci.org/yamldb/yaml_db.svg?branch=master)](https://travis-ci.org/yamldb/yaml_db)
12
12
 
@@ -1,7 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'yaml'
3
3
  require 'active_record'
4
- require 'active_support/core_ext/kernel/reporting'
5
4
  require 'rails/railtie'
6
5
  require 'yaml_db/rake_tasks'
7
6
  require 'yaml_db/version'
@@ -1,3 +1,5 @@
1
+ require 'active_support/core_ext/kernel/reporting'
2
+
1
3
  module YamlDb
2
4
  module SerializationHelper
3
5
 
@@ -83,11 +85,10 @@ module YamlDb
83
85
  if column_names.nil?
84
86
  return
85
87
  end
86
- columns = column_names.map{|cn| ActiveRecord::Base.connection.columns(table).detect{|c| c.name == cn}}
87
88
  quoted_column_names = column_names.map { |column| ActiveRecord::Base.connection.quote_column_name(column) }.join(',')
88
89
  quoted_table_name = Utils.quote_table(table)
89
90
  records.each do |record|
90
- quoted_values = record.zip(columns).map{|c| ActiveRecord::Base.connection.quote(c.first, c.last)}.join(',')
91
+ quoted_values = record.map{|c| ActiveRecord::Base.connection.quote(c)}.join(',')
91
92
  ActiveRecord::Base.connection.execute("INSERT INTO #{quoted_table_name} (#{quoted_column_names}) VALUES (#{quoted_values})")
92
93
  end
93
94
  end
@@ -182,12 +183,12 @@ module YamlDb
182
183
  def self.each_table_page(table, records_per_page=1000)
183
184
  total_count = table_record_count(table)
184
185
  pages = (total_count.to_f / records_per_page).ceil - 1
185
- key = sort_key(table)
186
+ keys = sort_keys(table)
186
187
  boolean_columns = Utils.boolean_columns(table)
187
188
  quoted_table_name = Utils.quote_table(table)
188
189
 
189
190
  (0..pages).to_a.each do |page|
190
- query = Arel::Table.new(table).order(key).skip(records_per_page*page).take(records_per_page).project(Arel.sql('*'))
191
+ query = Arel::Table.new(table).order(*keys).skip(records_per_page*page).take(records_per_page).project(Arel.sql('*'))
191
192
  records = ActiveRecord::Base.connection.select_all(query.to_sql)
192
193
  records = Utils.convert_booleans(records, boolean_columns)
193
194
  yield records
@@ -198,15 +199,15 @@ module YamlDb
198
199
  ActiveRecord::Base.connection.select_one("SELECT COUNT(*) FROM #{Utils.quote_table(table)}").values.first.to_i
199
200
  end
200
201
 
201
- # Just return the first column as sort key unless the table looks like a
202
- # standard HABTM join table, in which case add the second "id column"
203
- def self.sort_key(table)
202
+ # Return the first column as sort key unless the table looks like a
203
+ # standard has_and_belongs_to_many join table, in which case add the second "ID column"
204
+ def self.sort_keys(table)
204
205
  first_column, second_column = table_column_names(table)
205
206
 
206
207
  if [first_column, second_column].all? { |name| name =~ /_id$/ }
207
208
  [Utils.quote_column(first_column), Utils.quote_column(second_column)]
208
209
  else
209
- Utils.quote_column(first_column)
210
+ [Utils.quote_column(first_column)]
210
211
  end
211
212
  end
212
213
  end
@@ -1,3 +1,3 @@
1
1
  module YamlDb
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaml_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Wiggins
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-03-25 00:00:00.000000000 Z
12
+ date: 2017-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -20,7 +20,7 @@ dependencies:
20
20
  version: '3.0'
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: '5.1'
23
+ version: '5.2'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -30,7 +30,7 @@ dependencies:
30
30
  version: '3.0'
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.1'
33
+ version: '5.2'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rake
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -51,14 +51,14 @@ dependencies:
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.0'
54
+ version: '1.14'
55
55
  type: :development
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.0'
61
+ version: '1.14'
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: rspec
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  requirements: []
127
127
  rubyforge_project:
128
- rubygems_version: 2.6.8
128
+ rubygems_version: 2.5.1
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: yaml_db allows export/import of database into/from yaml files