activerecord-import 2.2.0 → 2.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -0
- data/README.markdown +9 -9
- data/lib/activerecord-import/active_record/adapters/mysql2_proxy_adapter.rb +8 -0
- data/lib/activerecord-import/active_record/adapters/postgresql_proxy_adapter.rb +8 -0
- data/lib/activerecord-import/active_record/adapters/sqlite3_proxy_adapter.rb +8 -0
- data/lib/activerecord-import/active_record/adapters/trilogy_proxy_adapter.rb +8 -0
- data/lib/activerecord-import/adapters/active_record_proxy_adapter.rb +19 -0
- data/lib/activerecord-import/adapters/mysql2_proxy_adapter.rb +9 -0
- data/lib/activerecord-import/adapters/mysql_adapter.rb +10 -3
- data/lib/activerecord-import/adapters/postgresql_adapter.rb +1 -1
- data/lib/activerecord-import/adapters/postgresql_proxy_adapter.rb +9 -0
- data/lib/activerecord-import/adapters/sqlite3_proxy_adapter.rb +9 -0
- data/lib/activerecord-import/adapters/trilogy_proxy_adapter.rb +9 -0
- data/lib/activerecord-import/base.rb +0 -2
- data/lib/activerecord-import/import.rb +243 -207
- data/lib/activerecord-import/version.rb +1 -1
- metadata +13 -208
- data/.github/workflows/test.yaml +0 -165
- data/.gitignore +0 -37
- data/.rubocop.yml +0 -118
- data/.rubocop_todo.yml +0 -30
- data/Brewfile +0 -5
- data/Dockerfile +0 -23
- data/Gemfile +0 -63
- data/Rakefile +0 -75
- data/activerecord-import.gemspec +0 -28
- data/benchmarks/README +0 -32
- data/benchmarks/benchmark.rb +0 -72
- data/benchmarks/lib/base.rb +0 -143
- data/benchmarks/lib/cli_parser.rb +0 -111
- data/benchmarks/lib/float.rb +0 -17
- data/benchmarks/lib/mysql2_benchmark.rb +0 -21
- data/benchmarks/lib/output_to_csv.rb +0 -21
- data/benchmarks/lib/output_to_html.rb +0 -66
- data/benchmarks/models/test_innodb.rb +0 -5
- data/benchmarks/models/test_memory.rb +0 -5
- data/benchmarks/models/test_myisam.rb +0 -5
- data/benchmarks/schema/mysql2_schema.rb +0 -18
- data/docker-compose.yml +0 -34
- data/gemfiles/5.2.gemfile +0 -4
- data/gemfiles/6.0.gemfile +0 -4
- data/gemfiles/6.1.gemfile +0 -4
- data/gemfiles/7.0.gemfile +0 -4
- data/gemfiles/7.1.gemfile +0 -3
- data/gemfiles/7.2.gemfile +0 -3
- data/gemfiles/8.0.gemfile +0 -3
- data/test/adapters/janus_mysql2.rb +0 -3
- data/test/adapters/janus_trilogy.rb +0 -11
- data/test/adapters/jdbcmysql.rb +0 -3
- data/test/adapters/jdbcpostgresql.rb +0 -3
- data/test/adapters/jdbcsqlite3.rb +0 -3
- data/test/adapters/makara_postgis.rb +0 -3
- data/test/adapters/mysql2.rb +0 -3
- data/test/adapters/mysql2_makara.rb +0 -3
- data/test/adapters/mysql2_proxy.rb +0 -3
- data/test/adapters/mysql2spatial.rb +0 -3
- data/test/adapters/postgis.rb +0 -3
- data/test/adapters/postgresql.rb +0 -3
- data/test/adapters/postgresql_makara.rb +0 -3
- data/test/adapters/postgresql_proxy.rb +0 -3
- data/test/adapters/seamless_database_pool.rb +0 -3
- data/test/adapters/spatialite.rb +0 -3
- data/test/adapters/sqlite3.rb +0 -3
- data/test/adapters/trilogy.rb +0 -11
- data/test/database.yml.sample +0 -73
- data/test/github/database.yml +0 -85
- data/test/import_test.rb +0 -970
- data/test/janus_mysql2/import_test.rb +0 -8
- data/test/janus_trilogy/import_test.rb +0 -7
- data/test/jdbcmysql/import_test.rb +0 -7
- data/test/jdbcpostgresql/import_test.rb +0 -6
- data/test/jdbcsqlite3/import_test.rb +0 -6
- data/test/makara_postgis/import_test.rb +0 -10
- data/test/models/account.rb +0 -5
- data/test/models/alarm.rb +0 -4
- data/test/models/animal.rb +0 -8
- data/test/models/author.rb +0 -9
- data/test/models/bike_maker.rb +0 -10
- data/test/models/book.rb +0 -18
- data/test/models/car.rb +0 -5
- data/test/models/card.rb +0 -5
- data/test/models/chapter.rb +0 -6
- data/test/models/composite_book.rb +0 -19
- data/test/models/composite_chapter.rb +0 -12
- data/test/models/customer.rb +0 -18
- data/test/models/deck.rb +0 -8
- data/test/models/dictionary.rb +0 -6
- data/test/models/discount.rb +0 -5
- data/test/models/end_note.rb +0 -6
- data/test/models/group.rb +0 -5
- data/test/models/order.rb +0 -17
- data/test/models/playing_card.rb +0 -4
- data/test/models/promotion.rb +0 -5
- data/test/models/question.rb +0 -5
- data/test/models/rule.rb +0 -5
- data/test/models/tag.rb +0 -12
- data/test/models/tag_alias.rb +0 -11
- data/test/models/topic.rb +0 -31
- data/test/models/user.rb +0 -5
- data/test/models/user_token.rb +0 -6
- data/test/models/vendor.rb +0 -9
- data/test/models/widget.rb +0 -33
- data/test/mysql2/import_test.rb +0 -7
- data/test/mysql2_makara/import_test.rb +0 -8
- data/test/mysql2_proxy/import_test.rb +0 -6
- data/test/mysqlspatial2/import_test.rb +0 -8
- data/test/postgis/import_test.rb +0 -10
- data/test/postgresql/import_test.rb +0 -6
- data/test/postgresql_proxy/import_test.rb +0 -6
- data/test/schema/generic_schema.rb +0 -230
- data/test/schema/jdbcpostgresql_schema.rb +0 -3
- data/test/schema/mysql2_schema.rb +0 -21
- data/test/schema/postgis_schema.rb +0 -3
- data/test/schema/postgresql_schema.rb +0 -94
- data/test/schema/sqlite3_schema.rb +0 -15
- data/test/schema/version.rb +0 -12
- data/test/sqlite3/import_test.rb +0 -6
- data/test/support/active_support/test_case_extensions.rb +0 -73
- data/test/support/assertions.rb +0 -75
- data/test/support/factories.rb +0 -66
- data/test/support/generate.rb +0 -31
- data/test/support/mysql/import_examples.rb +0 -97
- data/test/support/postgresql/import_examples.rb +0 -642
- data/test/support/shared_examples/on_duplicate_key_ignore.rb +0 -45
- data/test/support/shared_examples/on_duplicate_key_update.rb +0 -437
- data/test/support/shared_examples/recursive_import.rb +0 -352
- data/test/support/sqlite3/import_examples.rb +0 -232
- data/test/synchronize_test.rb +0 -43
- data/test/test_helper.rb +0 -91
- data/test/trilogy/import_test.rb +0 -7
- data/test/value_sets_bytes_parser_test.rb +0 -106
- data/test/value_sets_records_parser_test.rb +0 -34
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
def should_support_mysql_import_functionality
|
|
4
|
-
# Forcefully disable strict mode for this session.
|
|
5
|
-
ActiveRecord::Base.connection.execute "set sql_mode='STRICT_ALL_TABLES'"
|
|
6
|
-
|
|
7
|
-
should_support_basic_on_duplicate_key_update
|
|
8
|
-
should_support_on_duplicate_key_ignore
|
|
9
|
-
|
|
10
|
-
describe "#import" do
|
|
11
|
-
context "with :on_duplicate_key_update and validation checks turned off" do
|
|
12
|
-
extend ActiveSupport::TestCase::ImportAssertions
|
|
13
|
-
|
|
14
|
-
asssertion_group(:should_support_on_duplicate_key_update) do
|
|
15
|
-
should_not_update_fields_not_mentioned
|
|
16
|
-
should_update_foreign_keys
|
|
17
|
-
should_not_update_created_at_on_timestamp_columns
|
|
18
|
-
should_update_updated_at_on_timestamp_columns
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
macro(:perform_import) { raise "supply your own #perform_import in a context below" }
|
|
22
|
-
macro(:updated_topic) { Topic.find(@topic.id) }
|
|
23
|
-
|
|
24
|
-
let(:columns) { %w( id title author_name author_email_address parent_id ) }
|
|
25
|
-
let(:values) { [[99, "Book", "John Doe", "john@doe.com", 17]] }
|
|
26
|
-
let(:updated_values) { [[99, "Book - 2nd Edition", "Author Should Not Change", "johndoe@example.com", 57]] }
|
|
27
|
-
|
|
28
|
-
macro(:perform_import) do |*opts|
|
|
29
|
-
Topic.import columns, updated_values, opts.extract_options!.merge(on_duplicate_key_update: update_columns, validate: false)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
setup do
|
|
33
|
-
Topic.import columns, values, validate: false
|
|
34
|
-
@topic = Topic.find 99
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
context "using string hash map" do
|
|
38
|
-
let(:update_columns) { { "title" => "title", "author_email_address" => "author_email_address", "parent_id" => "parent_id" } }
|
|
39
|
-
should_support_on_duplicate_key_update
|
|
40
|
-
should_update_fields_mentioned
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
context "using string hash map, but specifying column mismatches" do
|
|
44
|
-
let(:update_columns) { { "title" => "author_email_address", "author_email_address" => "title", "parent_id" => "parent_id" } }
|
|
45
|
-
should_support_on_duplicate_key_update
|
|
46
|
-
should_update_fields_mentioned_with_hash_mappings
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
context "using symbol hash map" do
|
|
50
|
-
let(:update_columns) { { title: :title, author_email_address: :author_email_address, parent_id: :parent_id } }
|
|
51
|
-
should_support_on_duplicate_key_update
|
|
52
|
-
should_update_fields_mentioned
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
context "using symbol hash map, but specifying column mismatches" do
|
|
56
|
-
let(:update_columns) { { title: :author_email_address, author_email_address: :title, parent_id: :parent_id } }
|
|
57
|
-
should_support_on_duplicate_key_update
|
|
58
|
-
should_update_fields_mentioned_with_hash_mappings
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
context "with :synchronization option" do
|
|
63
|
-
let(:topics) { [] }
|
|
64
|
-
let(:values) { [[topics.first.id, "Jerry Carter", "title1"], [topics.last.id, "Chad Fowler", "title2"]] }
|
|
65
|
-
let(:columns) { %w(id author_name title) }
|
|
66
|
-
|
|
67
|
-
setup do
|
|
68
|
-
topics << Topic.create!(title: "LDAP", author_name: "Big Bird", content: "Putting Directories to Work.")
|
|
69
|
-
topics << Topic.create!(title: "Rails Recipes", author_name: "Elmo", content: "A trusted collection of solutions.")
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it "synchronizes passed in ActiveRecord model instances with the data just imported" do
|
|
73
|
-
columns2update = ['author_name']
|
|
74
|
-
|
|
75
|
-
expected_count = Topic.count
|
|
76
|
-
Topic.import( columns, values,
|
|
77
|
-
validate: false,
|
|
78
|
-
on_duplicate_key_update: columns2update,
|
|
79
|
-
synchronize: topics )
|
|
80
|
-
|
|
81
|
-
assert_equal expected_count, Topic.count, "no new records should have been created!"
|
|
82
|
-
assert_equal "Jerry Carter", topics.first.author_name, "wrong author!"
|
|
83
|
-
assert_equal "Chad Fowler", topics.last.author_name, "wrong author!"
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
context "with virtual columns" do
|
|
88
|
-
let(:books) { [Book.new(author_name: "foo", title: "bar")] }
|
|
89
|
-
|
|
90
|
-
it "ignores virtual columns and creates record" do
|
|
91
|
-
assert_difference "Book.count", +1 do
|
|
92
|
-
Book.import books
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|