activerecord-import 0.19.0 → 1.0.0

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.
Files changed (43) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +22 -12
  3. data/CHANGELOG.md +166 -0
  4. data/Gemfile +13 -10
  5. data/README.markdown +548 -5
  6. data/Rakefile +2 -1
  7. data/benchmarks/lib/cli_parser.rb +2 -1
  8. data/gemfiles/5.1.gemfile +1 -0
  9. data/gemfiles/5.2.gemfile +2 -0
  10. data/lib/activerecord-import/adapters/abstract_adapter.rb +2 -2
  11. data/lib/activerecord-import/adapters/mysql_adapter.rb +16 -10
  12. data/lib/activerecord-import/adapters/postgresql_adapter.rb +59 -15
  13. data/lib/activerecord-import/adapters/sqlite3_adapter.rb +126 -3
  14. data/lib/activerecord-import/base.rb +4 -6
  15. data/lib/activerecord-import/import.rb +384 -126
  16. data/lib/activerecord-import/synchronize.rb +1 -1
  17. data/lib/activerecord-import/value_sets_parser.rb +14 -0
  18. data/lib/activerecord-import/version.rb +1 -1
  19. data/lib/activerecord-import.rb +2 -15
  20. data/test/adapters/makara_postgis.rb +1 -0
  21. data/test/import_test.rb +148 -14
  22. data/test/makara_postgis/import_test.rb +8 -0
  23. data/test/models/account.rb +3 -0
  24. data/test/models/bike_maker.rb +7 -0
  25. data/test/models/topic.rb +10 -0
  26. data/test/models/user.rb +3 -0
  27. data/test/models/user_token.rb +4 -0
  28. data/test/schema/generic_schema.rb +20 -0
  29. data/test/schema/mysql2_schema.rb +19 -0
  30. data/test/schema/postgresql_schema.rb +1 -0
  31. data/test/schema/sqlite3_schema.rb +13 -0
  32. data/test/support/factories.rb +9 -8
  33. data/test/support/generate.rb +6 -6
  34. data/test/support/mysql/import_examples.rb +14 -2
  35. data/test/support/postgresql/import_examples.rb +142 -0
  36. data/test/support/shared_examples/on_duplicate_key_update.rb +252 -1
  37. data/test/support/shared_examples/recursive_import.rb +41 -11
  38. data/test/support/sqlite3/import_examples.rb +187 -10
  39. data/test/synchronize_test.rb +8 -0
  40. data/test/test_helper.rb +9 -1
  41. data/test/value_sets_bytes_parser_test.rb +13 -2
  42. metadata +20 -5
  43. data/test/schema/mysql_schema.rb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9a15b84eab5c3e37adc77106a0c55a8cb030d6d3
4
- data.tar.gz: b2cab0765b2dcb2465dd6178a767836da1b61d65
2
+ SHA256:
3
+ metadata.gz: 8f5ca21d97ac6550f23697bb50649a0e3c04858e922b9e0c9034201b38eaeba9
4
+ data.tar.gz: be99806f9a678aa8be4c9d06c904625ae49cab5be519dfced6300deab00adfe0
5
5
  SHA512:
6
- metadata.gz: c70a9f7ea0ac30697a9342d3243b459a38fc78048ee7287b4172da5353939fd4fbb73567a9ab7c79b7b0ef9e3a367b8ea9c0e6ec78c89050db36964735fc4782
7
- data.tar.gz: 1193d03b7d5ddb8cab84110a2d34c57df9a5c6fca2d38c9967d64dd0e9573d7b3c85a88c3448b3f5a6270a6ddafc459083e5fecd2d50a26a79d7c7c50184ce3a
6
+ metadata.gz: 749c050502f6b5edab4f46dcb6f8048bb652a825287278698b30328001a1d8be2eee4d68e1dc98b0d581c1ef090c957b2aa6918e43ca094818316c478c499c9b
7
+ data.tar.gz: 554e93c8bd7693852f25a9fa777757d22a53a48d3e24fc98e9a44bcb2daa946d9b39eb4dabb8f20063dc48a17717cb91e3f5a0870c95c04557b605108868c2cf
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
- - 2.3.3
4
+ - 2.3.7
5
5
 
6
6
  env:
7
7
  global:
@@ -14,13 +14,12 @@ env:
14
14
  - AR_VERSION=4.2
15
15
  - AR_VERSION=5.0
16
16
  - AR_VERSION=5.1
17
+ - AR_VERSION=5.2
17
18
 
18
19
  matrix:
19
20
  include:
20
- - rvm: jruby-9.1.7.0
21
+ - rvm: jruby-9.1.14.0
21
22
  env: AR_VERSION=4.2
22
- before_install:
23
- - gem update --system
24
23
 
25
24
  script:
26
25
  - bundle exec rake test:jdbcsqlite3
@@ -29,23 +28,32 @@ matrix:
29
28
 
30
29
  fast_finish: true
31
30
 
32
- before_script:
33
- - mysql -e 'create database activerecord_import_test;'
34
- - psql -c 'create database activerecord_import_test;' -U postgres
35
- - psql activerecord_import_test -c 'create extension if not exists hstore;' -U postgres
36
- - psql -c 'create extension if not exists postgis;' -U postgres
37
- - psql -c 'create extension if not exists "uuid-ossp";' -U postgres
38
- - cp test/travis/database.yml test/database.yml
39
-
40
31
  addons:
41
32
  postgresql: "9.5"
42
33
  apt:
43
34
  sources:
44
35
  - travis-ci/sqlite3
36
+ - mysql-5.7-trusty
45
37
  packages:
46
38
  - sqlite3
39
+ - mysql-server
40
+ - mysql-client
47
41
  - postgresql-9.5-postgis-2.3
48
42
 
43
+ before_install:
44
+ - gem update --system
45
+ - sudo mysql -e "use mysql; update user set authentication_string=PASSWORD('') where User='root'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;"
46
+ - sudo mysql_upgrade
47
+ - sudo service mysql restart
48
+
49
+ before_script:
50
+ - mysql -e 'create database activerecord_import_test;'
51
+ - psql -c 'create database activerecord_import_test;' -U postgres
52
+ - psql activerecord_import_test -c 'create extension if not exists hstore;' -U postgres
53
+ - psql -c 'create extension if not exists postgis;' -U postgres
54
+ - psql -c 'create extension if not exists "uuid-ossp";' -U postgres
55
+ - cp test/travis/database.yml test/database.yml
56
+
49
57
  script:
50
58
  - bundle exec rake test:mysql2
51
59
  - bundle exec rake test:mysql2_makara
@@ -59,3 +67,5 @@ script:
59
67
  - bundle exec rubocop
60
68
 
61
69
  dist: trusty
70
+
71
+ sudo: required
data/CHANGELOG.md CHANGED
@@ -1,3 +1,169 @@
1
+ ## Changes in 1.0.0
2
+
3
+ ### New Features
4
+
5
+ * Move ActiveRecord::Dirty changes to previous_changes after import.
6
+ Thanks to @stokarenko via \#584.
7
+
8
+ ### Breaking Changes
9
+
10
+ * Previously :on_duplicate_key_update was enabled by default for MySQL.
11
+ The update timestamp columns (updated_at, updated_on) would be updated
12
+ on duplicate key. This was behavior is inconsistent with the other database
13
+ adapters and could also be considered surprising. Going forward it must
14
+ be explicitly enabled. See \#548.
15
+
16
+ ## Changes in 0.28.2
17
+
18
+ ### Fixes
19
+
20
+ * Fix issue where validations where not working in certain scenarios.
21
+ Thanks to @CASIXx1 via \#579.
22
+
23
+ ## Changes in 0.28.1
24
+
25
+ ### Fixes
26
+
27
+ * Fix issue where ActiveRecord presence validations were being mutated.
28
+ Limited custom presence validation to bulk imports.
29
+
30
+ ## Changes in 0.28.0
31
+
32
+ ### New Features
33
+
34
+ * Allow updated timestamps to be manually set.Thanks to @Rob117, @jkowens via \#570.
35
+
36
+ ### Fixes
37
+
38
+ * Fix validating presence of belongs_to associations. Existence
39
+ of the parent record is not validated, but the foreign key field
40
+ cannot be empty. Thanks to @Rob117, @jkowens via \#575.
41
+
42
+ ## Changes in 0.27.0
43
+
44
+ ### New Features
45
+
46
+ * Add "secret" option validate_uniqueness to enable uniqueness
47
+ validators when validating import. This is not a recommended
48
+ approach (See #228), but is being added back in for projects
49
+ that depended on this feature. Thanks to @jkowens via \#554.
50
+
51
+ ## Changes in 0.26.0
52
+
53
+ ### New Features
54
+
55
+ * Add on_duplicate_key_update for SQLite. Thanks to @jkowens via \#542.
56
+ * Add option to update all fields on_duplicate_key_update. Thanks to @aimerald, @jkowens via \#543.
57
+
58
+ ### Fixes
59
+
60
+ * Handle deeply frozen options hashes. Thanks to @jturkel via \#546.
61
+ * Switch from FactoryGirl to FactoryBot. Thanks to @koic via \#547.
62
+ * Allow import to work with ProxySQL. Thanks to @GregFarrell via \#550.
63
+
64
+ ## Changes in 0.25.0
65
+
66
+ ### New Features
67
+
68
+ * Add support for makara_postgis adapter. Thanks to @chadwilken via \#527.
69
+ * Skip validating presence of belongs_to associations. Thanks to @Sohair63, @naiyt, @jkowens via \#528.
70
+
71
+ ### Fixes
72
+
73
+ * Add missing require for ActiveSupport.on_load. Thanks to @onk via \#529.
74
+ * Support setting attribute values in before_validation callbacks.
75
+ Thanks to @SirRawlins, @jkowens via \#531.
76
+ * Ignore virtual columns. Thanks to @dbourguignon, @jkowens via \#530.
77
+
78
+ ## Changes in 0.24.0
79
+
80
+ ### Fixes
81
+
82
+ * Use the association primary key when importing. Thanks to @dpogue via \#512.
83
+ * Allow association ids to be updated. Thanks to @Aristat via \#515.
84
+
85
+ ## Changes in 0.23.0
86
+
87
+ ### New Features
88
+
89
+ * Rename `import` method to `bulk_import` and alias to `import`. Thanks
90
+ to @itay-grudev, @jkowens via \#498.
91
+ * Increment lock_version on duplicate key update. Thanks to @aimerald
92
+ via \#500.
93
+
94
+ ### Fixes
95
+
96
+ * Fix import_without_validations_or_callbacks exception if array is empty.
97
+ Thanks to @doloopwhile via \#508.
98
+
99
+ ## Changes in 0.22.0
100
+
101
+ ### New Features
102
+
103
+ * Add support for importing hashes thru a has many association. Thanks
104
+ to @jkowens via \#483.
105
+
106
+ ### Fixes
107
+
108
+ * Fix validation logic for recursive import. For those on Rails 5.0 and 5.1,
109
+ this change requires models with polymorphic associations to specify the `inverse_of`
110
+ argument (See issue #495). Thanks to @eric-simonton-sama, @jkowens via
111
+ \#489.
112
+
113
+ ## Changes in 0.21.0
114
+
115
+ ### New Features
116
+
117
+ * Allow SQL subqueries (objects that respond to .to_sql) to be passed as values. Thanks
118
+ to @jalada, @jkowens via \#471
119
+ * Raise an ArgumentError when importing an array of hashes if any of the
120
+ hash objects have different keys. Thanks to @mbell697 via \#465.
121
+
122
+ ### Fixes
123
+
124
+ * Fix issue loading incorrect foreign key value when syncing belongs_to
125
+ associations with custom foreign key columns. Thanks to @marcgreenstock, @jkowens via \#470.
126
+ * Fix issue importing models with polymorphic belongs_to associations.
127
+ Thanks to @zorab47, @jkowens via \#476.
128
+ * Fix issue importing STI models with ActiveRecord 4.0. Thanks to
129
+ @kazuki-st, @jkowens via \#478.
130
+
131
+ ## Changes in 0.20.2
132
+
133
+ ### Fixes
134
+
135
+ * Unscope model when synchronizing with database. Thanks to @indigoviolet via \#455.
136
+
137
+ ## Changes in 0.20.1
138
+
139
+ ### Fixes
140
+
141
+ * Prevent :on_duplicate_key_update args from being modified. Thanks to @joshuamcginnis, @jkowens via \#451.
142
+
143
+ ## Changes in 0.20.0
144
+
145
+ ### New Features
146
+
147
+ * Allow returning columns to be specified for PostgreSQL. Thanks to
148
+ @tjwp via \#433.
149
+
150
+ ### Fixes
151
+
152
+ * Fixes an issue when bypassing uniqueness validators. Thanks to @vmaxv via \#444.
153
+ * For AR < 4.2, prevent type casting for binary columns on Postgresql. Thanks to @mwalsher via \#446.
154
+ * Fix issue logging class name on import. Thanks to @sophylee, @jkowens via \#447.
155
+ * Copy belongs_to association id to foreign key column before importing. Thanks to @jkowens via \#448.
156
+ * Reset model instance on validate. Thanks to @vmaxv via \#449.
157
+
158
+ ## Changes in 0.19.1
159
+
160
+ ### Fixes
161
+
162
+ * Fix a regression where models weren't properly being marked clean. Thanks to @tjwp via \#434.
163
+ * Raise ActiveRecord::Import::ValueSetTooLargeError when a record being inserted exceeds the
164
+ `max_allowed_packet` for MySQL. Thanks to @saizai, @jkowens via \#437.
165
+ * Fix issue concatenating column names array with primary key. Thanks to @keeguon via \#440.
166
+
1
167
  ## Changes in 0.19.0
2
168
 
3
169
  ### New Features
data/Gemfile CHANGED
@@ -2,14 +2,19 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
+ version = ENV['AR_VERSION'].to_f
6
+
7
+ mysql2_version = '0.3.0'
8
+ mysql2_version = '0.4.0' if version >= 4.2
9
+
5
10
  group :development, :test do
6
- gem 'rubocop', '~> 0.38.0'
11
+ gem 'rubocop', '~> 0.40.0'
7
12
  gem 'rake'
8
13
  end
9
14
 
10
15
  # Database Adapters
11
16
  platforms :ruby do
12
- gem "mysql2", "~> 0.3.0"
17
+ gem "mysql2", "~> #{mysql2_version}"
13
18
  gem "pg", "~> 0.9"
14
19
  gem "sqlite3", "~> 1.3.10"
15
20
  gem "seamless_database_pool", "~> 1.0.20"
@@ -18,16 +23,16 @@ end
18
23
  platforms :jruby do
19
24
  gem "jdbc-mysql"
20
25
  gem "jdbc-postgres"
21
- gem "activerecord-jdbcsqlite3-adapter"
22
- gem "activerecord-jdbcmysql-adapter"
23
- gem "activerecord-jdbcpostgresql-adapter"
26
+ gem "activerecord-jdbcsqlite3-adapter", "~> 1.3"
27
+ gem "activerecord-jdbcmysql-adapter", "~> 1.3"
28
+ gem "activerecord-jdbcpostgresql-adapter", "~> 1.3"
24
29
  end
25
30
 
26
31
  # Support libs
27
- gem "factory_girl", "~> 4.2.0"
32
+ gem "factory_bot"
28
33
  gem "timecop"
29
34
  gem "chronic"
30
- gem "mocha"
35
+ gem "mocha", "~> 1.3.0"
31
36
 
32
37
  # Debugging
33
38
  platforms :jruby do
@@ -43,9 +48,7 @@ platforms :ruby do
43
48
  gem "rb-readline"
44
49
  end
45
50
 
46
- version = ENV['AR_VERSION'] || "4.2"
47
-
48
- if version >= "4.0"
51
+ if version >= 4.0
49
52
  gem "minitest"
50
53
  else
51
54
  gem "test-unit"