table_saw 2.5.0 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,14 +2,10 @@
2
2
 
3
3
  module TableSaw
4
4
  class InformationSchema
5
- %i(belongs_to constraint_names has_many).each do |method_name|
6
- define_method method_name do
7
- foreign_key_relationships.public_send method_name
8
- end
5
+ def constraint_names
6
+ foreign_key_relationships.constraint_names
9
7
  end
10
8
 
11
- private
12
-
13
9
  def foreign_key_relationships
14
10
  @foreign_key_relationships ||= TableSaw::Queries::ForeignKeyRelationships.new
15
11
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'yaml'
4
+ require 'table_saw/associations'
4
5
 
5
6
  module TableSaw
6
7
  class Manifest
@@ -46,7 +47,8 @@ module TableSaw
46
47
  end
47
48
 
48
49
  def variables
49
- config.fetch('variables', {})
50
+ vars = config.fetch('variables', {})
51
+ vars.merge(TableSaw.configuration.variables.slice(*vars.keys))
50
52
  end
51
53
 
52
54
  def tables
@@ -58,5 +60,13 @@ module TableSaw
58
60
  def has_many
59
61
  @has_many ||= config.fetch('has_many', {})
60
62
  end
63
+
64
+ def foreign_keys
65
+ @foreign_keys ||= config.fetch('foreign_keys', [])
66
+ end
67
+
68
+ def associations
69
+ @associations ||= TableSaw::Associations.new(self)
70
+ end
61
71
  end
62
72
  end
@@ -18,16 +18,17 @@ module TableSaw
18
18
 
19
19
  def values
20
20
  TableSaw.schema_cache.columns(statement.table_name).zip(row)
21
- .map { |column, value| connection.quote(connection.type_cast_from_column(column, value)) }
21
+ .map { |column, value| quote_value(column, value) }
22
22
  .join(', ')
23
23
  end
24
24
 
25
- def schema_cache
26
- TableSaw.schema_cache
25
+ def connection
26
+ TableSaw.schema_cache.connection
27
27
  end
28
28
 
29
- def connection
30
- schema_cache.connection
29
+ def quote_value(column, value)
30
+ type = connection.lookup_cast_type_from_column(column)
31
+ connection.quote(type.serialize(type.deserialize(value)))
31
32
  end
32
33
  end
33
34
  end
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'table_saw/foreign_key'
4
+ require 'set'
5
+
3
6
  module TableSaw
4
7
  module Queries
5
8
  class ForeignKeyRelationships
@@ -16,24 +19,20 @@ module TableSaw
16
19
  where tc.constraint_type = 'FOREIGN KEY'
17
20
  SQL
18
21
 
19
- def belongs_to
20
- @belongs_to ||= result.each_with_object(Hash.new { |h, k| h[k] = {} }) do |row, memo|
21
- memo[row['from_table']][row['from_column']] = row['to_table']
22
- end
23
- end
24
-
25
- def has_many
26
- @has_many ||= result.each_with_object(Hash.new { |h, k| h[k] = [] }) do |row, memo|
27
- memo[row['to_table']].push([row['from_table'], row['from_column']])
28
- end
29
- end
30
-
31
22
  def constraint_names
32
23
  @constraint_names ||= result.each_with_object(Hash.new { |h, k| h[k] = [] }) do |row, memo|
33
24
  memo[row['from_table']].push(row['constraint_name'])
34
25
  end
35
26
  end
36
27
 
28
+ def foreign_keys
29
+ @foreign_keys ||= result.map do |row|
30
+ TableSaw::ForeignKey.new(name: row['constraint_name'],
31
+ from_table: row['from_table'], from_column: row['from_column'],
32
+ to_table: row['to_table'], to_column: row['to_column'])
33
+ end
34
+ end
35
+
37
36
  private
38
37
 
39
38
  def result
@@ -23,7 +23,7 @@ module TableSaw
23
23
  end
24
24
 
25
25
  def sql
26
- [prepare_statement, conflict_statement].compact.join(' ') + ';'
26
+ "#{[prepare_statement, conflict_statement].compact.join(' ')};"
27
27
  end
28
28
 
29
29
  def column_types
@@ -23,7 +23,7 @@ module TableSaw
23
23
 
24
24
  def serialized_values
25
25
  values.map do |value|
26
- connection.quote(connection.type_cast_from_column(db_column, value))
26
+ connection.quote_default_expression(value, db_column)
27
27
  end
28
28
  end
29
29
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TableSaw
4
- VERSION = '2.5.0'
4
+ VERSION = '2.9.0'
5
5
  end
data/table_saw.gemspec CHANGED
@@ -23,15 +23,17 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = ['table-saw']
24
24
  spec.require_paths = ['lib']
25
25
 
26
+ spec.required_ruby_version = '>= 2.6'
27
+
26
28
  spec.add_dependency 'activerecord', '>= 5.2'
27
29
  spec.add_dependency 'pg'
28
30
  spec.add_dependency 'thor'
29
31
 
30
32
  spec.add_development_dependency 'bundler', '~> 2.0'
31
- spec.add_development_dependency 'combustion', '~> 1.1'
33
+ spec.add_development_dependency 'combustion', '~> 1.3'
32
34
  spec.add_development_dependency 'database_cleaner', '~> 1.7'
33
35
  spec.add_development_dependency 'pry'
34
- spec.add_development_dependency 'rake', '~> 10.0'
36
+ spec.add_development_dependency 'rake', '~> 13.0'
35
37
  spec.add_development_dependency 'rspec', '~> 3.0'
36
38
  spec.add_development_dependency 'rubocop-rspec', '~> 1.33'
37
39
  spec.add_development_dependency 'scenic', '~> 1.5'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_saw
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hamed Asghari
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-04 00:00:00.000000000 Z
11
+ date: 2021-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.1'
75
+ version: '1.3'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.1'
82
+ version: '1.3'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: database_cleaner
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '10.0'
117
+ version: '13.0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '10.0'
124
+ version: '13.0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rspec
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -178,7 +178,7 @@ dependencies:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0.16'
181
- description:
181
+ description:
182
182
  email:
183
183
  - hasghari@gmail.com
184
184
  executables:
@@ -186,12 +186,14 @@ executables:
186
186
  extensions: []
187
187
  extra_rdoc_files: []
188
188
  files:
189
+ - ".github/workflows/ruby.yml"
189
190
  - ".gitignore"
190
191
  - ".rspec"
191
192
  - ".rubocop.yml"
192
193
  - ".ruby-gemset"
193
194
  - ".ruby-version"
194
- - ".travis.yml"
195
+ - ".tool-versions"
196
+ - Appraisals
195
197
  - CODE_OF_CONDUCT.md
196
198
  - Gemfile
197
199
  - Gemfile.lock
@@ -201,7 +203,12 @@ files:
201
203
  - bin/console
202
204
  - bin/setup
203
205
  - exe/table-saw
206
+ - gemfiles/activerecord_6.0.0.gemfile
207
+ - gemfiles/activerecord_6.0.0.gemfile.lock
208
+ - gemfiles/activerecord_6.1.0.gemfile
209
+ - gemfiles/activerecord_6.1.0.gemfile.lock
204
210
  - lib/table_saw.rb
211
+ - lib/table_saw/associations.rb
205
212
  - lib/table_saw/configuration.rb
206
213
  - lib/table_saw/connection.rb
207
214
  - lib/table_saw/create_dump_file.rb
@@ -211,6 +218,7 @@ files:
211
218
  - lib/table_saw/dependency_graph/build.rb
212
219
  - lib/table_saw/dependency_graph/dump_table.rb
213
220
  - lib/table_saw/dependency_graph/has_many_directives.rb
221
+ - lib/table_saw/foreign_key.rb
214
222
  - lib/table_saw/formats.rb
215
223
  - lib/table_saw/formats/base.rb
216
224
  - lib/table_saw/formats/copy.rb
@@ -230,7 +238,7 @@ homepage: https://github.com/hasghari/table_saw
230
238
  licenses:
231
239
  - MIT
232
240
  metadata: {}
233
- post_install_message:
241
+ post_install_message:
234
242
  rdoc_options: []
235
243
  require_paths:
236
244
  - lib
@@ -238,15 +246,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
238
246
  requirements:
239
247
  - - ">="
240
248
  - !ruby/object:Gem::Version
241
- version: '0'
249
+ version: '2.6'
242
250
  required_rubygems_version: !ruby/object:Gem::Requirement
243
251
  requirements:
244
252
  - - ">="
245
253
  - !ruby/object:Gem::Version
246
254
  version: '0'
247
255
  requirements: []
248
- rubygems_version: 3.0.6
249
- signing_key:
256
+ rubygems_version: 3.2.3
257
+ signing_key:
250
258
  specification_version: 4
251
259
  summary: Create a postgres dump file from a subset of tables
252
260
  test_files: []
data/.travis.yml DELETED
@@ -1,24 +0,0 @@
1
- ---
2
- sudo: false
3
- env:
4
- global:
5
- - CC_TEST_REPORTER_ID=5432d4e95a7749f237cf9e659c44ba28c5c91fa65436b15c5bc849d6d9ebc049
6
- language: ruby
7
- cache: bundler
8
- rvm:
9
- - 2.5.5
10
- - 2.6.5
11
- - 2.7.0
12
- before_install: gem install bundler -v 2.0.1
13
- before_script:
14
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
15
- - chmod +x ./cc-test-reporter
16
- - ./cc-test-reporter before-build
17
- script:
18
- - bundle exec rspec
19
- after_script:
20
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
21
- addons:
22
- postgresql: "9.6"
23
- services:
24
- - postgresql