active_record_data_loader 1.0.2 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/build.yml +51 -0
  3. data/.github/workflows/codeql-analysis.yml +70 -0
  4. data/.github/workflows/gem-push.yml +29 -0
  5. data/.rubocop.yml +46 -7
  6. data/CHANGELOG.md +38 -2
  7. data/CODE_OF_CONDUCT.md +2 -2
  8. data/Gemfile.lock +71 -73
  9. data/README.md +162 -9
  10. data/Rakefile +8 -2
  11. data/active_record_data_loader.gemspec +7 -6
  12. data/config/database.yml +2 -0
  13. data/docker-compose.yml +18 -0
  14. data/gemfiles/activerecord_6.gemfile +1 -1
  15. data/lib/active_record_data_loader/active_record/{belongs_to_configuration.rb → belongs_to_data_provider.rb} +8 -7
  16. data/lib/active_record_data_loader/active_record/{column_configuration.rb → column_data_provider.rb} +2 -2
  17. data/lib/active_record_data_loader/active_record/enum_value_generator.rb +9 -8
  18. data/lib/active_record_data_loader/active_record/integer_value_generator.rb +1 -1
  19. data/lib/active_record_data_loader/active_record/list.rb +47 -0
  20. data/lib/active_record_data_loader/active_record/model_data_generator.rb +62 -7
  21. data/lib/active_record_data_loader/active_record/{polymorphic_belongs_to_configuration.rb → polymorphic_belongs_to_data_provider.rb} +12 -7
  22. data/lib/active_record_data_loader/active_record/unique_index_tracker.rb +67 -0
  23. data/lib/active_record_data_loader/bulk_insert_strategy.rb +16 -8
  24. data/lib/active_record_data_loader/configuration.rb +26 -3
  25. data/lib/active_record_data_loader/connection_handler.rb +52 -0
  26. data/lib/active_record_data_loader/copy_strategy.rb +38 -24
  27. data/lib/active_record_data_loader/data_faker.rb +12 -4
  28. data/lib/active_record_data_loader/dsl/model.rb +19 -2
  29. data/lib/active_record_data_loader/errors.rb +5 -0
  30. data/lib/active_record_data_loader/file_output_adapter.rb +48 -0
  31. data/lib/active_record_data_loader/loader.rb +55 -71
  32. data/lib/active_record_data_loader/null_output_adapter.rb +15 -0
  33. data/lib/active_record_data_loader/table_loader.rb +59 -0
  34. data/lib/active_record_data_loader/version.rb +1 -1
  35. data/lib/active_record_data_loader.rb +11 -38
  36. metadata +51 -29
  37. data/.travis.yml +0 -24
  38. data/config/database.yml.travis +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a76332e648af9f10d665eaab3fb442b18d708914
4
- data.tar.gz: 012eb43c82d6bca82f97ece0d719faa07ea79c6c
2
+ SHA256:
3
+ metadata.gz: ae90d445d9e578a618a7ff3858edcb00719055716647c6fec0374db385b0b935
4
+ data.tar.gz: cc51ca7b8093c2b43d5c8610130db5cbbd12811520a57f8cc0b4fe3e114a1eaa
5
5
  SHA512:
6
- metadata.gz: 2f41b6aedb4c4cd4f02319cd3d13c50715a0e91bbfd0710e04caa2145054d26b20a4e7a2f69b295b28650a0ad8e111f322fbf008bda28f0db7fa6fa25428de24
7
- data.tar.gz: 18d9fb81d1e5d273aab3d21bc2d12f5e28624636f6286deeaf0ccadfdbf20afe629583c96dde78ee32acaaa0b931a363fe32c2c8a77435eca32540875a8d3ee7
6
+ metadata.gz: be8f649f5b1240b081b20ce713c2da69596d278db2cf19009916dcaeac3e73493745114c6ec662b90b0ff18ad068f0c881fb345ff68cb15c54497cf97a5ec325
7
+ data.tar.gz: 490223f97f751eedcaad7de58846a01a5ff08a38762f30a9040b6dd65b05b2c2e5ac9fc71683f52ac8986a5c7c7748258904f6b380370813380a7e136581b4df
@@ -0,0 +1,51 @@
1
+ name: Build
2
+
3
+ on: [push, workflow_dispatch]
4
+
5
+ jobs:
6
+ build:
7
+ name: Build + Test
8
+ runs-on: ubuntu-latest
9
+ services:
10
+ postgres:
11
+ image: postgres:11
12
+ ports:
13
+ - "2345:5432"
14
+ env:
15
+ POSTGRES_USER: test
16
+ POSTGRES_PASSWORD: test
17
+ mysql:
18
+ image: mysql:5
19
+ ports:
20
+ - "3306:3306"
21
+ env:
22
+ MYSQL_ROOT_PASSWORD: test
23
+ MYSQL_USER: test
24
+ MYSQL_PASSWORD: test
25
+ MYSQL_DATABASE: test
26
+ strategy:
27
+ matrix:
28
+ ruby: [2.5.9, 2.6.7, 2.7.3]
29
+ gemfile: [activerecord_5, rails, faker, ffaker]
30
+ env:
31
+ BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
32
+ steps:
33
+ - name: Checkout
34
+ uses: actions/checkout@v2
35
+
36
+ - name: Setup ruby
37
+ uses: ruby/setup-ruby@v1
38
+ with:
39
+ ruby-version: ${{ matrix.ruby }}
40
+ bundler-cache: true
41
+
42
+ - name: Wait for DBs to be ready
43
+ run: bundle exec rake wait_for_test_db
44
+
45
+ - name: Run tests
46
+ run: bundle exec rake
47
+
48
+ - name: Coveralls
49
+ uses: coverallsapp/github-action@master
50
+ with:
51
+ github-token: ${{ secrets.github_token }}
@@ -0,0 +1,70 @@
1
+ # For most projects, this workflow file will not need changing; you simply need
2
+ # to commit it to your repository.
3
+ #
4
+ # You may wish to alter this file to override the set of languages analyzed,
5
+ # or to provide custom queries or build logic.
6
+ #
7
+ # ******** NOTE ********
8
+ # We have attempted to detect the languages in your repository. Please check
9
+ # the `language` matrix defined below to confirm you have the correct set of
10
+ # supported CodeQL languages.
11
+ #
12
+ name: "CodeQL"
13
+
14
+ on:
15
+ push:
16
+ branches: [ master ]
17
+ pull_request:
18
+ # The branches below must be a subset of the branches above
19
+ branches: [ master ]
20
+ schedule:
21
+ - cron: '26 13 * * 4'
22
+
23
+ jobs:
24
+ analyze:
25
+ name: Analyze
26
+ runs-on: ubuntu-latest
27
+ permissions:
28
+ actions: read
29
+ contents: read
30
+ security-events: write
31
+
32
+ strategy:
33
+ fail-fast: false
34
+ matrix:
35
+ language: [ 'ruby' ]
36
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37
+ # Learn more about CodeQL language support at https://git.io/codeql-language-support
38
+
39
+ steps:
40
+ - name: Checkout repository
41
+ uses: actions/checkout@v2
42
+
43
+ # Initializes the CodeQL tools for scanning.
44
+ - name: Initialize CodeQL
45
+ uses: github/codeql-action/init@v1
46
+ with:
47
+ languages: ${{ matrix.language }}
48
+ # If you wish to specify custom queries, you can do so here or in a config file.
49
+ # By default, queries listed here will override any specified in a config file.
50
+ # Prefix the list here with "+" to use these queries and those in the config file.
51
+ # queries: ./path/to/local/query, your-org/your-repo/queries@main
52
+
53
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
54
+ # If this step fails, then you should remove it and run the build manually (see below)
55
+ - name: Autobuild
56
+ uses: github/codeql-action/autobuild@v1
57
+
58
+ # ℹ️ Command-line programs to run using the OS shell.
59
+ # 📚 https://git.io/JvXDl
60
+
61
+ # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
62
+ # and modify them (or add more) to build your code if your project
63
+ # uses a compiled language
64
+
65
+ #- run: |
66
+ # make bootstrap
67
+ # make release
68
+
69
+ - name: Perform CodeQL Analysis
70
+ uses: github/codeql-action/analyze@v1
@@ -0,0 +1,29 @@
1
+ name: Ruby Gem
2
+
3
+ on: workflow_dispatch
4
+
5
+ jobs:
6
+ build:
7
+ name: Build + Publish
8
+ runs-on: ubuntu-latest
9
+ permissions:
10
+ contents: read
11
+ packages: write
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - name: Set up Ruby 2.6
16
+ uses: actions/setup-ruby@v1
17
+ with:
18
+ ruby-version: 2.6.x
19
+
20
+ - name: Publish to RubyGems
21
+ run: |
22
+ mkdir -p $HOME/.gem
23
+ touch $HOME/.gem/credentials
24
+ chmod 0600 $HOME/.gem/credentials
25
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
26
+ gem build *.gemspec
27
+ gem push *.gem
28
+ env:
29
+ GEM_HOST_API_KEY: "${{ secrets.RUBYGEMS_API_KEY }}"
data/.rubocop.yml CHANGED
@@ -1,5 +1,23 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.3
2
+ TargetRubyVersion: 2.5
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Gemspec/RequireMFA:
7
+ Enabled: false
8
+
9
+ Layout/LineLength:
10
+ Max: 110
11
+ Exclude: ["*.gemspec"]
12
+
13
+ Layout/SpaceAroundMethodCallOperator:
14
+ Enabled: true
15
+
16
+ Lint/RaiseException:
17
+ Enabled: true
18
+
19
+ Lint/StructNewOverride:
20
+ Enabled: true
3
21
 
4
22
  Lint/UnusedMethodArgument:
5
23
  AllowUnusedKeywordArguments: true
@@ -11,20 +29,41 @@ Metrics/AbcSize:
11
29
  Metrics/BlockLength:
12
30
  Exclude: ["spec/**/*", "*.gemspec"]
13
31
 
14
- Metrics/LineLength:
15
- Max: 110
16
- Exclude: ["*.gemspec"]
32
+ Metrics/ClassLength:
33
+ Max: 150
34
+ Exclude: ["spec/**/*", "*.gemspec"]
17
35
 
18
36
  Metrics/MethodLength:
19
- Max: 15
37
+ Max: 25
20
38
  Exclude: ["spec/**/*"]
21
39
 
22
- Style/FrozenStringLiteralComment:
23
- Exclude: ["gemfiles/*"]
40
+ Metrics/ParameterLists:
41
+ Max: 5
42
+ Exclude:
43
+ - "lib/active_record_data_loader/configuration.rb"
44
+ - "lib/active_record_data_loader/active_record/model_data_generator.rb"
45
+
46
+ Style/CaseLikeIf:
47
+ Enabled: false
24
48
 
25
49
  Style/Documentation:
26
50
  Enabled: false
27
51
 
52
+ Style/ExponentialNotation:
53
+ Enabled: true
54
+
55
+ Style/FrozenStringLiteralComment:
56
+ Exclude: ["gemfiles/*"]
57
+
58
+ Style/HashEachMethods:
59
+ Enabled: true
60
+
61
+ Style/HashTransformKeys:
62
+ Enabled: true
63
+
64
+ Style/HashTransformValues:
65
+ Enabled: true
66
+
28
67
  Style/StringLiterals:
29
68
  EnforcedStyle: double_quotes
30
69
 
data/CHANGELOG.md CHANGED
@@ -1,10 +1,41 @@
1
1
  # Change log
2
2
 
3
+ ## [v1.3.1] - 2021-12-10
4
+
5
+ [Diff](https://github.com/abeiderman/active_record_data_loader/compare/v1.3.0...v1.3.1)
6
+
7
+ ### Changes:
8
+ * Fix bug with cycling through foreign key IDs when multiple foreign keys are in a unique index/constraint. It was cycling all foreign keys in the same order which meant that if a duplicate row was generated then it will continue to be generated. By shuffling the list of foreign key IDs after each cycle, it gives it a chance at coming up with unique values during retries.
9
+
10
+ ## [v1.3.0] - 2021-12-10
11
+
12
+ [Diff](https://github.com/abeiderman/active_record_data_loader/compare/v1.2.0...v1.3.0)
13
+
14
+ ### Changes:
15
+ * Replace the `:file` output option with simply accepting an optional file path as `output`. A SQL script file will be generated in addition to loading the data into the database.
16
+ * Identify and handle unique indexes by attempting to generate unique values. Add configuration options for behavior around duplicate rows.
17
+
18
+ ## [v1.2.0] - 2021-11-14
19
+
20
+ [Diff](https://github.com/abeiderman/active_record_data_loader/compare/v1.1.0...v1.2.0)
21
+
22
+ ### Changes:
23
+ * Add `:file` output option for generating a SQL script instead of loading the data into the database.
24
+ * Fix some connection handling issues when a custom connection factory is provided.
25
+
26
+ ## [v1.1.0] - 2021-05-01
27
+
28
+ [Diff](https://github.com/abeiderman/active_record_data_loader/compare/v1.0.2...v1.1.0)
29
+
30
+ ### Changes:
31
+ * Bump ruby version requirement to >= 2.5
32
+ * Bump activerecord requirement to >= 5.0
33
+
3
34
  ## [v1.0.2] - 2019-07-05
4
35
 
5
36
  [Diff](https://github.com/abeiderman/active_record_data_loader/compare/v1.0.1...v1.0.2)
6
37
 
7
- ### Enhancements:
38
+ ### Changes:
8
39
  * Add support for MySQL enums
9
40
  * Accept a connection factory lambda as part of the configuration
10
41
 
@@ -12,7 +43,7 @@
12
43
 
13
44
  [Diff](https://github.com/abeiderman/active_record_data_loader/compare/v1.0.0...v1.0.1)
14
45
 
15
- ### Enhancements:
46
+ ### Changes:
16
47
  * Generate values for datetime column types. This also fixes the fact that `created_at` and `updated_at` were not being populated by default.
17
48
 
18
49
  ## [v1.0.0] - 2019-06-15
@@ -21,3 +52,8 @@ Initial stable release
21
52
 
22
53
  [v1.0.0]: https://github.com/abeiderman/active_record_data_loader/releases/tag/v1.0.0
23
54
  [v1.0.1]: https://github.com/abeiderman/active_record_data_loader/releases/tag/v1.0.1
55
+ [v1.0.2]: https://github.com/abeiderman/active_record_data_loader/releases/tag/v1.0.2
56
+ [v1.1.0]: https://github.com/abeiderman/active_record_data_loader/releases/tag/v1.1.0
57
+ [v1.2.0]: https://github.com/abeiderman/active_record_data_loader/releases/tag/v1.2.0
58
+ [v1.3.0]: https://github.com/abeiderman/active_record_data_loader/releases/tag/v1.3.0
59
+ [v1.3.1]: https://github.com/abeiderman/active_record_data_loader/releases/tag/v1.3.1
data/CODE_OF_CONDUCT.md CHANGED
@@ -55,8 +55,8 @@ further defined and clarified by project maintainers.
55
55
  ## Enforcement
56
56
 
57
57
  Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at abeiderman@gmail.com. All
59
- complaints will be reviewed and investigated and will result in a response that
58
+ reported by contacting the project team at active_record_data_loader@ossprojects.dev.
59
+ All complaints will be reviewed and investigated and will result in a response that
60
60
  is deemed necessary and appropriate to the circumstances. The project team is
61
61
  obligated to maintain confidentiality with regard to the reporter of an incident.
62
62
  Further details of specific enforcement policies may be posted separately.
data/Gemfile.lock CHANGED
@@ -1,111 +1,109 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_record_data_loader (1.0.2)
5
- activerecord (>= 4.0)
4
+ active_record_data_loader (1.3.1)
5
+ activerecord (>= 5.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (5.2.3)
11
- activesupport (= 5.2.3)
12
- activerecord (5.2.3)
13
- activemodel (= 5.2.3)
14
- activesupport (= 5.2.3)
15
- arel (>= 9.0)
16
- activesupport (5.2.3)
10
+ activemodel (6.1.4.1)
11
+ activesupport (= 6.1.4.1)
12
+ activerecord (6.1.4.1)
13
+ activemodel (= 6.1.4.1)
14
+ activesupport (= 6.1.4.1)
15
+ activesupport (6.1.4.1)
17
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
- i18n (>= 0.7, < 2)
19
- minitest (~> 5.1)
20
- tzinfo (~> 1.1)
21
- appraisal (2.2.0)
17
+ i18n (>= 1.6, < 2)
18
+ minitest (>= 5.1)
19
+ tzinfo (~> 2.0)
20
+ zeitwerk (~> 2.3)
21
+ appraisal (2.4.1)
22
22
  bundler
23
23
  rake
24
24
  thor (>= 0.14.0)
25
- arel (9.0.0)
26
- ast (2.4.0)
27
- coderay (1.1.2)
28
- concurrent-ruby (1.1.5)
29
- coveralls (0.8.23)
30
- json (>= 1.8, < 3)
31
- simplecov (~> 0.16.1)
32
- term-ansicolor (~> 1.3)
33
- thor (>= 0.19.4, < 2.0)
34
- tins (~> 1.6)
35
- diff-lcs (1.3)
36
- docile (1.3.1)
37
- i18n (1.6.0)
25
+ ast (2.4.2)
26
+ coderay (1.1.3)
27
+ concurrent-ruby (1.1.9)
28
+ diff-lcs (1.4.4)
29
+ docile (1.4.0)
30
+ i18n (1.8.11)
38
31
  concurrent-ruby (~> 1.0)
39
- jaro_winkler (1.5.2)
40
- json (2.2.0)
41
- method_source (0.9.2)
42
- minitest (5.11.3)
43
- mysql2 (0.5.2)
44
- parallel (1.17.0)
45
- parser (2.6.3.0)
46
- ast (~> 2.4.0)
47
- pg (1.1.4)
48
- pry (0.12.2)
49
- coderay (~> 1.1.0)
50
- method_source (~> 0.9.0)
32
+ method_source (1.0.0)
33
+ minitest (5.14.4)
34
+ mysql2 (0.5.3)
35
+ parallel (1.21.0)
36
+ parser (3.0.3.2)
37
+ ast (~> 2.4.1)
38
+ pg (1.2.3)
39
+ pry (0.14.1)
40
+ coderay (~> 1.1)
41
+ method_source (~> 1.0)
51
42
  rainbow (3.0.0)
52
- rake (12.3.2)
53
- rspec (3.8.0)
54
- rspec-core (~> 3.8.0)
55
- rspec-expectations (~> 3.8.0)
56
- rspec-mocks (~> 3.8.0)
57
- rspec-collection_matchers (1.1.3)
43
+ rake (13.0.6)
44
+ regexp_parser (2.2.0)
45
+ rexml (3.2.5)
46
+ rspec (3.10.0)
47
+ rspec-core (~> 3.10.0)
48
+ rspec-expectations (~> 3.10.0)
49
+ rspec-mocks (~> 3.10.0)
50
+ rspec-collection_matchers (1.2.0)
58
51
  rspec-expectations (>= 2.99.0.beta1)
59
- rspec-core (3.8.0)
60
- rspec-support (~> 3.8.0)
61
- rspec-expectations (3.8.3)
52
+ rspec-core (3.10.1)
53
+ rspec-support (~> 3.10.0)
54
+ rspec-expectations (3.10.1)
62
55
  diff-lcs (>= 1.2.0, < 2.0)
63
- rspec-support (~> 3.8.0)
64
- rspec-mocks (3.8.0)
56
+ rspec-support (~> 3.10.0)
57
+ rspec-mocks (3.10.2)
65
58
  diff-lcs (>= 1.2.0, < 2.0)
66
- rspec-support (~> 3.8.0)
67
- rspec-support (3.8.0)
68
- rubocop (0.68.1)
69
- jaro_winkler (~> 1.5.1)
59
+ rspec-support (~> 3.10.0)
60
+ rspec-support (3.10.3)
61
+ rubocop (1.23.0)
70
62
  parallel (~> 1.10)
71
- parser (>= 2.5, != 2.5.1.1)
63
+ parser (>= 3.0.0.0)
72
64
  rainbow (>= 2.2.2, < 4.0)
65
+ regexp_parser (>= 1.8, < 3.0)
66
+ rexml
67
+ rubocop-ast (>= 1.12.0, < 2.0)
73
68
  ruby-progressbar (~> 1.7)
74
- unicode-display_width (>= 1.4.0, < 1.6)
75
- ruby-progressbar (1.10.0)
76
- simplecov (0.16.1)
69
+ unicode-display_width (>= 1.4.0, < 3.0)
70
+ rubocop-ast (1.14.0)
71
+ parser (>= 3.0.1.1)
72
+ ruby-progressbar (1.11.0)
73
+ simplecov (0.21.2)
77
74
  docile (~> 1.1)
78
- json (>= 1.8, < 3)
79
- simplecov-html (~> 0.10.0)
80
- simplecov-html (0.10.2)
81
- sqlite3 (1.4.1)
82
- term-ansicolor (1.7.1)
83
- tins (~> 1.0)
84
- thor (0.20.3)
85
- thread_safe (0.3.6)
86
- timecop (0.9.1)
87
- tins (1.20.3)
88
- tzinfo (1.2.5)
89
- thread_safe (~> 0.1)
90
- unicode-display_width (1.5.0)
75
+ simplecov-html (~> 0.11)
76
+ simplecov_json_formatter (~> 0.1)
77
+ simplecov-html (0.12.3)
78
+ simplecov-lcov (0.8.0)
79
+ simplecov_json_formatter (0.1.3)
80
+ sqlite3 (1.4.2)
81
+ thor (1.1.0)
82
+ timecop (0.9.4)
83
+ tzinfo (2.0.4)
84
+ concurrent-ruby (~> 1.0)
85
+ unicode-display_width (2.1.0)
86
+ zeitwerk (2.5.1)
91
87
 
92
88
  PLATFORMS
93
89
  ruby
90
+ x86_64-darwin-19
94
91
 
95
92
  DEPENDENCIES
96
93
  active_record_data_loader!
97
94
  appraisal
98
95
  bundler (>= 1.16)
99
- coveralls
100
96
  mysql2
101
97
  pg
102
98
  pry
103
- rake (~> 12.0)
99
+ rake (~> 13.0)
104
100
  rspec (~> 3.0)
105
101
  rspec-collection_matchers
106
102
  rubocop
103
+ simplecov
104
+ simplecov-lcov
107
105
  sqlite3
108
106
  timecop
109
107
 
110
108
  BUNDLED WITH
111
- 2.0.1
109
+ 2.2.31