activerecord-import-uuid 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +32 -0
- data/.rubocop.yml +49 -0
- data/.rubocop_todo.yml +36 -0
- data/.travis.yml +52 -0
- data/Brewfile +3 -0
- data/CHANGELOG.md +87 -0
- data/Gemfile +54 -0
- data/LICENSE +56 -0
- data/README.markdown +101 -0
- data/Rakefile +66 -0
- data/activerecord-import.gemspec +23 -0
- data/benchmarks/README +32 -0
- data/benchmarks/benchmark.rb +67 -0
- data/benchmarks/lib/base.rb +138 -0
- data/benchmarks/lib/cli_parser.rb +106 -0
- data/benchmarks/lib/float.rb +15 -0
- data/benchmarks/lib/mysql2_benchmark.rb +19 -0
- data/benchmarks/lib/output_to_csv.rb +19 -0
- data/benchmarks/lib/output_to_html.rb +64 -0
- data/benchmarks/models/test_innodb.rb +3 -0
- data/benchmarks/models/test_memory.rb +3 -0
- data/benchmarks/models/test_myisam.rb +3 -0
- data/benchmarks/schema/mysql_schema.rb +16 -0
- data/gemfiles/3.2.gemfile +3 -0
- data/gemfiles/4.0.gemfile +3 -0
- data/gemfiles/4.1.gemfile +3 -0
- data/gemfiles/4.2.gemfile +7 -0
- data/gemfiles/5.0.gemfile +3 -0
- data/lib/activerecord-import.rb +19 -0
- data/lib/activerecord-import/active_record/adapters/abstract_adapter.rb +9 -0
- data/lib/activerecord-import/active_record/adapters/jdbcmysql_adapter.rb +6 -0
- data/lib/activerecord-import/active_record/adapters/jdbcpostgresql_adapter.rb +6 -0
- data/lib/activerecord-import/active_record/adapters/mysql2_adapter.rb +6 -0
- data/lib/activerecord-import/active_record/adapters/postgresql_adapter.rb +6 -0
- data/lib/activerecord-import/active_record/adapters/seamless_database_pool_adapter.rb +7 -0
- data/lib/activerecord-import/active_record/adapters/sqlite3_adapter.rb +6 -0
- data/lib/activerecord-import/adapters/abstract_adapter.rb +78 -0
- data/lib/activerecord-import/adapters/em_mysql2_adapter.rb +5 -0
- data/lib/activerecord-import/adapters/mysql2_adapter.rb +5 -0
- data/lib/activerecord-import/adapters/mysql_adapter.rb +114 -0
- data/lib/activerecord-import/adapters/postgresql_adapter.rb +144 -0
- data/lib/activerecord-import/adapters/sqlite3_adapter.rb +51 -0
- data/lib/activerecord-import/base.rb +38 -0
- data/lib/activerecord-import/import.rb +660 -0
- data/lib/activerecord-import/mysql2.rb +7 -0
- data/lib/activerecord-import/postgresql.rb +7 -0
- data/lib/activerecord-import/sqlite3.rb +7 -0
- data/lib/activerecord-import/synchronize.rb +66 -0
- data/lib/activerecord-import/value_sets_parser.rb +55 -0
- data/lib/activerecord-import/version.rb +5 -0
- data/test/adapters/jdbcmysql.rb +1 -0
- data/test/adapters/jdbcpostgresql.rb +1 -0
- data/test/adapters/mysql2.rb +1 -0
- data/test/adapters/mysql2_makara.rb +1 -0
- data/test/adapters/mysql2spatial.rb +1 -0
- data/test/adapters/postgis.rb +1 -0
- data/test/adapters/postgresql.rb +1 -0
- data/test/adapters/postgresql_makara.rb +1 -0
- data/test/adapters/seamless_database_pool.rb +1 -0
- data/test/adapters/spatialite.rb +1 -0
- data/test/adapters/sqlite3.rb +1 -0
- data/test/database.yml.sample +52 -0
- data/test/import_test.rb +574 -0
- data/test/jdbcmysql/import_test.rb +6 -0
- data/test/jdbcpostgresql/import_test.rb +5 -0
- data/test/models/book.rb +7 -0
- data/test/models/chapter.rb +4 -0
- data/test/models/discount.rb +3 -0
- data/test/models/end_note.rb +4 -0
- data/test/models/group.rb +3 -0
- data/test/models/promotion.rb +3 -0
- data/test/models/question.rb +3 -0
- data/test/models/rule.rb +3 -0
- data/test/models/topic.rb +9 -0
- data/test/models/widget.rb +24 -0
- data/test/mysql2/import_test.rb +5 -0
- data/test/mysql2_makara/import_test.rb +6 -0
- data/test/mysqlspatial2/import_test.rb +6 -0
- data/test/postgis/import_test.rb +4 -0
- data/test/postgresql/import_test.rb +8 -0
- data/test/schema/generic_schema.rb +144 -0
- data/test/schema/mysql_schema.rb +16 -0
- data/test/schema/version.rb +10 -0
- data/test/sqlite3/import_test.rb +52 -0
- data/test/support/active_support/test_case_extensions.rb +70 -0
- data/test/support/assertions.rb +73 -0
- data/test/support/factories.rb +57 -0
- data/test/support/generate.rb +29 -0
- data/test/support/mysql/import_examples.rb +85 -0
- data/test/support/postgresql/import_examples.rb +242 -0
- data/test/support/shared_examples/on_duplicate_key_update.rb +103 -0
- data/test/support/shared_examples/recursive_import.rb +122 -0
- data/test/synchronize_test.rb +33 -0
- data/test/test_helper.rb +59 -0
- data/test/travis/database.yml +62 -0
- data/test/value_sets_bytes_parser_test.rb +93 -0
- data/test/value_sets_records_parser_test.rb +32 -0
- metadata +225 -0
@@ -0,0 +1,122 @@
|
|
1
|
+
def should_support_recursive_import
|
2
|
+
describe "importing objects with associations" do
|
3
|
+
let(:new_topics) { Build(num_topics, :topic_with_book) }
|
4
|
+
let(:new_topics_with_invalid_chapter) do
|
5
|
+
chapter = new_topics.first.books.first.chapters.first
|
6
|
+
chapter.title = nil
|
7
|
+
new_topics
|
8
|
+
end
|
9
|
+
let(:num_topics) { 3 }
|
10
|
+
let(:num_books) { 6 }
|
11
|
+
let(:num_chapters) { 18 }
|
12
|
+
let(:num_endnotes) { 24 }
|
13
|
+
|
14
|
+
let(:new_question_with_rule) { FactoryGirl.build :question, :with_rule }
|
15
|
+
|
16
|
+
it 'imports top level' do
|
17
|
+
assert_difference "Topic.count", +num_topics do
|
18
|
+
Topic.import new_topics, recursive: true
|
19
|
+
new_topics.each do |topic|
|
20
|
+
assert_not_nil topic.id
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'imports first level associations' do
|
26
|
+
assert_difference "Book.count", +num_books do
|
27
|
+
Topic.import new_topics, recursive: true
|
28
|
+
new_topics.each do |topic|
|
29
|
+
topic.books.each do |book|
|
30
|
+
assert_equal topic.id, book.topic_id
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'imports polymorphic associations' do
|
37
|
+
discounts = Array.new(1) { |i| Discount.new(amount: i) }
|
38
|
+
books = Array.new(1) { |i| Book.new(author_name: "Author ##{i}", title: "Book ##{i}") }
|
39
|
+
books.each do |book|
|
40
|
+
book.discounts << discounts
|
41
|
+
end
|
42
|
+
Book.import books, recursive: true
|
43
|
+
books.each do |book|
|
44
|
+
book.discounts.each do |discount|
|
45
|
+
assert_not_nil discount.discountable_id
|
46
|
+
assert_equal 'Book', discount.discountable_type
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
[{ recursive: false }, {}].each do |import_options|
|
52
|
+
it "skips recursion for #{import_options}" do
|
53
|
+
assert_difference "Book.count", 0 do
|
54
|
+
Topic.import new_topics, import_options
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'imports deeper nested associations' do
|
60
|
+
assert_difference "Chapter.count", +num_chapters do
|
61
|
+
assert_difference "EndNote.count", +num_endnotes do
|
62
|
+
Topic.import new_topics, recursive: true
|
63
|
+
new_topics.each do |topic|
|
64
|
+
topic.books.each do |book|
|
65
|
+
book.chapters.each do |chapter|
|
66
|
+
assert_equal book.id, chapter.book_id
|
67
|
+
end
|
68
|
+
book.end_notes.each do |endnote|
|
69
|
+
assert_equal book.id, endnote.book_id
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it "skips validation of the associations if requested" do
|
78
|
+
assert_difference "Chapter.count", +num_chapters do
|
79
|
+
Topic.import new_topics_with_invalid_chapter, validate: false, recursive: true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'imports has_one associations' do
|
84
|
+
assert_difference 'Rule.count' do
|
85
|
+
Question.import [new_question_with_rule], recursive: true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# These models dont validate associated. So we expect that books and topics get inserted, but not chapters
|
90
|
+
# Putting a transaction around everything wouldn't work, so if you want your chapters to prevent topics from
|
91
|
+
# being created, you would need to have validates_associated in your models and insert with validation
|
92
|
+
describe "all_or_none" do
|
93
|
+
[Book, Topic, EndNote].each do |type|
|
94
|
+
it "creates #{type}" do
|
95
|
+
assert_difference "#{type}.count", send("num_#{type.to_s.downcase}s") do
|
96
|
+
Topic.import new_topics_with_invalid_chapter, all_or_none: true, recursive: true
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
it "doesn't create chapters" do
|
101
|
+
assert_difference "Chapter.count", 0 do
|
102
|
+
Topic.import new_topics_with_invalid_chapter, all_or_none: true, recursive: true
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# If adapter supports on_duplicate_key_update, it is only applied to top level models so that SQL with invalid
|
108
|
+
# columns, keys, etc isn't generated for child associations when doing recursive import
|
109
|
+
describe "on_duplicate_key_update" do
|
110
|
+
let(:new_topics) { Build(1, :topic_with_book) }
|
111
|
+
|
112
|
+
it "imports objects with associations" do
|
113
|
+
assert_difference "Topic.count", +1 do
|
114
|
+
Topic.import new_topics, recursive: true, on_duplicate_key_update: [:updated_at], validate: false
|
115
|
+
new_topics.each do |topic|
|
116
|
+
assert_not_nil topic.id
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
describe ".synchronize" do
|
4
|
+
let(:topics) { Generate(3, :topics) }
|
5
|
+
let(:titles) { %w(one two three) }
|
6
|
+
|
7
|
+
setup do
|
8
|
+
# update records outside of ActiveRecord knowing about it
|
9
|
+
Topic.connection.execute( "UPDATE #{Topic.table_name} SET title='#{titles[0]}_haha' WHERE id=#{topics[0].id}", "Updating record 1 without ActiveRecord" )
|
10
|
+
Topic.connection.execute( "UPDATE #{Topic.table_name} SET title='#{titles[1]}_haha' WHERE id=#{topics[1].id}", "Updating record 2 without ActiveRecord" )
|
11
|
+
Topic.connection.execute( "UPDATE #{Topic.table_name} SET title='#{titles[2]}_haha' WHERE id=#{topics[2].id}", "Updating record 3 without ActiveRecord" )
|
12
|
+
end
|
13
|
+
|
14
|
+
it "reloads data for the specified records" do
|
15
|
+
Topic.synchronize topics
|
16
|
+
|
17
|
+
actual_titles = topics.map(&:title)
|
18
|
+
assert_equal "#{titles[0]}_haha", actual_titles[0], "the first record was not correctly updated"
|
19
|
+
assert_equal "#{titles[1]}_haha", actual_titles[1], "the second record was not correctly updated"
|
20
|
+
assert_equal "#{titles[2]}_haha", actual_titles[2], "the third record was not correctly updated"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "the synchronized records aren't dirty" do
|
24
|
+
# Update the in memory records so they're dirty
|
25
|
+
topics.each { |topic| topic.title = 'dirty title' }
|
26
|
+
|
27
|
+
Topic.synchronize topics
|
28
|
+
|
29
|
+
assert_equal false, topics[0].changed?, "the first record was dirty"
|
30
|
+
assert_equal false, topics[1].changed?, "the second record was dirty"
|
31
|
+
assert_equal false, topics[2].changed?, "the third record was dirty"
|
32
|
+
end
|
33
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
test_dir = Pathname.new File.dirname(__FILE__)
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
+
|
6
|
+
require "fileutils"
|
7
|
+
|
8
|
+
ENV["RAILS_ENV"] = "test"
|
9
|
+
|
10
|
+
require "bundler"
|
11
|
+
Bundler.setup
|
12
|
+
|
13
|
+
require 'pry' unless RbConfig::CONFIG["RUBY_INSTALL_NAME"] =~ /jruby/
|
14
|
+
|
15
|
+
require "active_record"
|
16
|
+
require "active_record/fixtures"
|
17
|
+
require "active_support/test_case"
|
18
|
+
|
19
|
+
if ActiveSupport::VERSION::STRING < "4.0"
|
20
|
+
require 'test/unit'
|
21
|
+
else
|
22
|
+
require 'active_support/testing/autorun'
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'timecop'
|
26
|
+
require 'chronic'
|
27
|
+
|
28
|
+
require "ruby-debug" if RUBY_VERSION.to_f < 1.9
|
29
|
+
|
30
|
+
adapter = ENV["ARE_DB"] || "sqlite3"
|
31
|
+
|
32
|
+
FileUtils.mkdir_p 'log'
|
33
|
+
ActiveRecord::Base.logger = Logger.new("log/test.log")
|
34
|
+
ActiveRecord::Base.logger.level = Logger::DEBUG
|
35
|
+
ActiveRecord::Base.configurations["test"] = YAML.load_file(test_dir.join("database.yml"))[adapter]
|
36
|
+
ActiveRecord::Base.default_timezone = :utc
|
37
|
+
|
38
|
+
require "activerecord-import"
|
39
|
+
ActiveRecord::Base.establish_connection :test
|
40
|
+
|
41
|
+
ActiveSupport::Notifications.subscribe(/active_record.sql/) do |_, _, _, _, hsh|
|
42
|
+
ActiveRecord::Base.logger.info hsh[:sql]
|
43
|
+
end
|
44
|
+
|
45
|
+
require "factory_girl"
|
46
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |file| require file }
|
47
|
+
|
48
|
+
# Load base/generic schema
|
49
|
+
require test_dir.join("schema/version")
|
50
|
+
require test_dir.join("schema/generic_schema")
|
51
|
+
adapter_schema = test_dir.join("schema/#{adapter}_schema.rb")
|
52
|
+
require adapter_schema if File.exist?(adapter_schema)
|
53
|
+
|
54
|
+
Dir[File.dirname(__FILE__) + "/models/*.rb"].each { |file| require file }
|
55
|
+
|
56
|
+
# Prevent this deprecation warning from breaking the tests.
|
57
|
+
Rake::FileList.send(:remove_method, :import)
|
58
|
+
|
59
|
+
ActiveSupport::TestCase.test_order = :random if ENV['AR_VERSION'].to_f >= 4.2
|
@@ -0,0 +1,62 @@
|
|
1
|
+
common: &common
|
2
|
+
username: root
|
3
|
+
password:
|
4
|
+
encoding: utf8
|
5
|
+
host: localhost
|
6
|
+
database: activerecord_import_test
|
7
|
+
|
8
|
+
jdbcpostgresql: &postgresql
|
9
|
+
<<: *common
|
10
|
+
username: postgres
|
11
|
+
adapter: jdbcpostgresql
|
12
|
+
min_messages: warning
|
13
|
+
|
14
|
+
jdbcmysql: &mysql2
|
15
|
+
<<: *common
|
16
|
+
adapter: jdbcmysql
|
17
|
+
|
18
|
+
mysql2: &mysql2
|
19
|
+
<<: *common
|
20
|
+
adapter: mysql2
|
21
|
+
|
22
|
+
mysql2spatial:
|
23
|
+
<<: *mysql2
|
24
|
+
|
25
|
+
mysql2_makara:
|
26
|
+
<<: *mysql2
|
27
|
+
|
28
|
+
oracle:
|
29
|
+
<<: *common
|
30
|
+
adapter: oracle
|
31
|
+
min_messages: debug
|
32
|
+
|
33
|
+
postgresql: &postgresql
|
34
|
+
<<: *common
|
35
|
+
username: postgres
|
36
|
+
adapter: postgresql
|
37
|
+
min_messages: warning
|
38
|
+
|
39
|
+
postresql_makara:
|
40
|
+
<<: *postgresql
|
41
|
+
|
42
|
+
postgis:
|
43
|
+
<<: *postgresql
|
44
|
+
|
45
|
+
seamless_database_pool:
|
46
|
+
<<: *common
|
47
|
+
adapter: seamless_database_pool
|
48
|
+
pool_adapter: mysql2
|
49
|
+
prepared_statements: false
|
50
|
+
master:
|
51
|
+
host: localhost
|
52
|
+
|
53
|
+
sqlite:
|
54
|
+
adapter: sqlite
|
55
|
+
dbfile: test.db
|
56
|
+
|
57
|
+
sqlite3: &sqlite3
|
58
|
+
adapter: sqlite3
|
59
|
+
database: ":memory:"
|
60
|
+
|
61
|
+
spatialite:
|
62
|
+
<<: *sqlite3
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
require 'activerecord-import/value_sets_parser'
|
4
|
+
|
5
|
+
describe ActiveRecord::Import::ValueSetsBytesParser do
|
6
|
+
context "#parse - computing insert value sets" do
|
7
|
+
let(:parser) { ActiveRecord::Import::ValueSetsBytesParser }
|
8
|
+
let(:base_sql) { "INSERT INTO atable (a,b,c)" }
|
9
|
+
let(:values) { ["(1,2,3)", "(2,3,4)", "(3,4,5)"] }
|
10
|
+
|
11
|
+
context "when the max allowed bytes is 33 and the base SQL is 26 bytes" do
|
12
|
+
it "should return 3 value sets when given 3 value sets of 7 bytes a piece" do
|
13
|
+
value_sets = parser.parse values, reserved_bytes: base_sql.size, max_bytes: 33
|
14
|
+
assert_equal 3, value_sets.size
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when the max allowed bytes is 40 and the base SQL is 26 bytes" do
|
19
|
+
it "should return 3 value sets when given 3 value sets of 7 bytes a piece" do
|
20
|
+
value_sets = parser.parse values, reserved_bytes: base_sql.size, max_bytes: 40
|
21
|
+
assert_equal 3, value_sets.size
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when the max allowed bytes is 41 and the base SQL is 26 bytes" do
|
26
|
+
it "should return 2 value sets when given 2 value sets of 7 bytes a piece" do
|
27
|
+
value_sets = parser.parse values, reserved_bytes: base_sql.size, max_bytes: 41
|
28
|
+
assert_equal 2, value_sets.size
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when the max allowed bytes is 48 and the base SQL is 26 bytes" do
|
33
|
+
it "should return 2 value sets when given 2 value sets of 7 bytes a piece" do
|
34
|
+
value_sets = parser.parse values, reserved_bytes: base_sql.size, max_bytes: 48
|
35
|
+
assert_equal 2, value_sets.size
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when the max allowed bytes is 49 and the base SQL is 26 bytes" do
|
40
|
+
it "should return 1 value sets when given 1 value sets of 7 bytes a piece" do
|
41
|
+
value_sets = parser.parse values, reserved_bytes: base_sql.size, max_bytes: 49
|
42
|
+
assert_equal 1, value_sets.size
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when the max allowed bytes is 999999 and the base SQL is 26 bytes" do
|
47
|
+
it "should return 1 value sets when given 1 value sets of 7 bytes a piece" do
|
48
|
+
value_sets = parser.parse values, reserved_bytes: base_sql.size, max_bytes: 999_999
|
49
|
+
assert_equal 1, value_sets.size
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should properly build insert value set based on max packet allowed" do
|
54
|
+
values = [
|
55
|
+
"('1','2','3')",
|
56
|
+
"('4','5','6')",
|
57
|
+
"('7','8','9')"]
|
58
|
+
|
59
|
+
base_sql_size_in_bytes = 15
|
60
|
+
max_bytes = 30
|
61
|
+
|
62
|
+
value_sets = parser.parse values, reserved_bytes: base_sql_size_in_bytes, max_bytes: max_bytes
|
63
|
+
assert_equal 3, value_sets.size, 'Three value sets were expected!'
|
64
|
+
|
65
|
+
# Each element in the value_sets array must be an array
|
66
|
+
value_sets.each_with_index do |e, i|
|
67
|
+
assert_kind_of Array, e, "Element #{i} was expected to be an Array!"
|
68
|
+
end
|
69
|
+
|
70
|
+
# Each element in the values array should have a 1:1 correlation to the elements
|
71
|
+
# in the returned value_sets arrays
|
72
|
+
assert_equal values[0], value_sets[0].first
|
73
|
+
assert_equal values[1], value_sets[1].first
|
74
|
+
assert_equal values[2], value_sets[2].first
|
75
|
+
end
|
76
|
+
|
77
|
+
context "data contains multi-byte chars" do
|
78
|
+
it "should properly build insert value set based on max packet allowed" do
|
79
|
+
# each accented e should be 2 bytes, so each entry is 6 bytes instead of 5
|
80
|
+
values = [
|
81
|
+
"('é')",
|
82
|
+
"('é')"]
|
83
|
+
|
84
|
+
base_sql_size_in_bytes = 15
|
85
|
+
max_bytes = 26
|
86
|
+
|
87
|
+
value_sets = parser.parse values, reserved_bytes: base_sql_size_in_bytes, max_bytes: max_bytes
|
88
|
+
|
89
|
+
assert_equal 2, value_sets.size, 'Two value sets were expected!'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
require 'activerecord-import/value_sets_parser'
|
4
|
+
|
5
|
+
describe "ActiveRecord::Import::ValueSetsRecordsParser" do
|
6
|
+
context "#parse - computing insert value sets" do
|
7
|
+
let(:parser) { ActiveRecord::Import::ValueSetsRecordsParser }
|
8
|
+
let(:base_sql) { "INSERT INTO atable (a,b,c)" }
|
9
|
+
let(:values) { ["(1,2,3)", "(2,3,4)", "(3,4,5)"] }
|
10
|
+
|
11
|
+
context "when the max number of records is 1" do
|
12
|
+
it "should return 3 value sets when given 3 values sets" do
|
13
|
+
value_sets = parser.parse values, max_records: 1
|
14
|
+
assert_equal 3, value_sets.size
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when the max number of records is 2" do
|
19
|
+
it "should return 2 value sets when given 3 values sets" do
|
20
|
+
value_sets = parser.parse values, max_records: 2
|
21
|
+
assert_equal 2, value_sets.size
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when the max number of records is 3" do
|
26
|
+
it "should return 1 value sets when given 3 values sets" do
|
27
|
+
value_sets = parser.parse values, max_records: 3
|
28
|
+
assert_equal 1, value_sets.size
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord-import-uuid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Zach Dennis
|
9
|
+
- Shiv Bharthur
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2016-09-11 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activerecord
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3.2'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '3.2'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: rake
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description: Extraction of the ActiveRecord::Base#import functionality from ar-extensions
|
48
|
+
for Rails 3 and beyond
|
49
|
+
email:
|
50
|
+
- zach.dennis@gmail.com
|
51
|
+
- shiv.bharthur@gmail.com
|
52
|
+
executables: []
|
53
|
+
extensions: []
|
54
|
+
extra_rdoc_files: []
|
55
|
+
files:
|
56
|
+
- .gitignore
|
57
|
+
- .rubocop.yml
|
58
|
+
- .rubocop_todo.yml
|
59
|
+
- .travis.yml
|
60
|
+
- Brewfile
|
61
|
+
- CHANGELOG.md
|
62
|
+
- Gemfile
|
63
|
+
- LICENSE
|
64
|
+
- README.markdown
|
65
|
+
- Rakefile
|
66
|
+
- activerecord-import.gemspec
|
67
|
+
- benchmarks/README
|
68
|
+
- benchmarks/benchmark.rb
|
69
|
+
- benchmarks/lib/base.rb
|
70
|
+
- benchmarks/lib/cli_parser.rb
|
71
|
+
- benchmarks/lib/float.rb
|
72
|
+
- benchmarks/lib/mysql2_benchmark.rb
|
73
|
+
- benchmarks/lib/output_to_csv.rb
|
74
|
+
- benchmarks/lib/output_to_html.rb
|
75
|
+
- benchmarks/models/test_innodb.rb
|
76
|
+
- benchmarks/models/test_memory.rb
|
77
|
+
- benchmarks/models/test_myisam.rb
|
78
|
+
- benchmarks/schema/mysql_schema.rb
|
79
|
+
- gemfiles/3.2.gemfile
|
80
|
+
- gemfiles/4.0.gemfile
|
81
|
+
- gemfiles/4.1.gemfile
|
82
|
+
- gemfiles/4.2.gemfile
|
83
|
+
- gemfiles/5.0.gemfile
|
84
|
+
- lib/activerecord-import.rb
|
85
|
+
- lib/activerecord-import/active_record/adapters/abstract_adapter.rb
|
86
|
+
- lib/activerecord-import/active_record/adapters/jdbcmysql_adapter.rb
|
87
|
+
- lib/activerecord-import/active_record/adapters/jdbcpostgresql_adapter.rb
|
88
|
+
- lib/activerecord-import/active_record/adapters/mysql2_adapter.rb
|
89
|
+
- lib/activerecord-import/active_record/adapters/postgresql_adapter.rb
|
90
|
+
- lib/activerecord-import/active_record/adapters/seamless_database_pool_adapter.rb
|
91
|
+
- lib/activerecord-import/active_record/adapters/sqlite3_adapter.rb
|
92
|
+
- lib/activerecord-import/adapters/abstract_adapter.rb
|
93
|
+
- lib/activerecord-import/adapters/em_mysql2_adapter.rb
|
94
|
+
- lib/activerecord-import/adapters/mysql2_adapter.rb
|
95
|
+
- lib/activerecord-import/adapters/mysql_adapter.rb
|
96
|
+
- lib/activerecord-import/adapters/postgresql_adapter.rb
|
97
|
+
- lib/activerecord-import/adapters/sqlite3_adapter.rb
|
98
|
+
- lib/activerecord-import/base.rb
|
99
|
+
- lib/activerecord-import/import.rb
|
100
|
+
- lib/activerecord-import/mysql2.rb
|
101
|
+
- lib/activerecord-import/postgresql.rb
|
102
|
+
- lib/activerecord-import/sqlite3.rb
|
103
|
+
- lib/activerecord-import/synchronize.rb
|
104
|
+
- lib/activerecord-import/value_sets_parser.rb
|
105
|
+
- lib/activerecord-import/version.rb
|
106
|
+
- test/adapters/jdbcmysql.rb
|
107
|
+
- test/adapters/jdbcpostgresql.rb
|
108
|
+
- test/adapters/mysql2.rb
|
109
|
+
- test/adapters/mysql2_makara.rb
|
110
|
+
- test/adapters/mysql2spatial.rb
|
111
|
+
- test/adapters/postgis.rb
|
112
|
+
- test/adapters/postgresql.rb
|
113
|
+
- test/adapters/postgresql_makara.rb
|
114
|
+
- test/adapters/seamless_database_pool.rb
|
115
|
+
- test/adapters/spatialite.rb
|
116
|
+
- test/adapters/sqlite3.rb
|
117
|
+
- test/database.yml.sample
|
118
|
+
- test/import_test.rb
|
119
|
+
- test/jdbcmysql/import_test.rb
|
120
|
+
- test/jdbcpostgresql/import_test.rb
|
121
|
+
- test/models/book.rb
|
122
|
+
- test/models/chapter.rb
|
123
|
+
- test/models/discount.rb
|
124
|
+
- test/models/end_note.rb
|
125
|
+
- test/models/group.rb
|
126
|
+
- test/models/promotion.rb
|
127
|
+
- test/models/question.rb
|
128
|
+
- test/models/rule.rb
|
129
|
+
- test/models/topic.rb
|
130
|
+
- test/models/widget.rb
|
131
|
+
- test/mysql2/import_test.rb
|
132
|
+
- test/mysql2_makara/import_test.rb
|
133
|
+
- test/mysqlspatial2/import_test.rb
|
134
|
+
- test/postgis/import_test.rb
|
135
|
+
- test/postgresql/import_test.rb
|
136
|
+
- test/schema/generic_schema.rb
|
137
|
+
- test/schema/mysql_schema.rb
|
138
|
+
- test/schema/version.rb
|
139
|
+
- test/sqlite3/import_test.rb
|
140
|
+
- test/support/active_support/test_case_extensions.rb
|
141
|
+
- test/support/assertions.rb
|
142
|
+
- test/support/factories.rb
|
143
|
+
- test/support/generate.rb
|
144
|
+
- test/support/mysql/import_examples.rb
|
145
|
+
- test/support/postgresql/import_examples.rb
|
146
|
+
- test/support/shared_examples/on_duplicate_key_update.rb
|
147
|
+
- test/support/shared_examples/recursive_import.rb
|
148
|
+
- test/synchronize_test.rb
|
149
|
+
- test/test_helper.rb
|
150
|
+
- test/travis/database.yml
|
151
|
+
- test/value_sets_bytes_parser_test.rb
|
152
|
+
- test/value_sets_records_parser_test.rb
|
153
|
+
homepage: http://github.com/bharthur/activerecord-import
|
154
|
+
licenses:
|
155
|
+
- Ruby
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
require_paths:
|
159
|
+
- lib
|
160
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: 1.9.2
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
none: false
|
168
|
+
requirements:
|
169
|
+
- - ! '>='
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
requirements: []
|
173
|
+
rubyforge_project:
|
174
|
+
rubygems_version: 1.8.23
|
175
|
+
signing_key:
|
176
|
+
specification_version: 3
|
177
|
+
summary: Bulk-loading extension for ActiveRecord
|
178
|
+
test_files:
|
179
|
+
- test/adapters/jdbcmysql.rb
|
180
|
+
- test/adapters/jdbcpostgresql.rb
|
181
|
+
- test/adapters/mysql2.rb
|
182
|
+
- test/adapters/mysql2_makara.rb
|
183
|
+
- test/adapters/mysql2spatial.rb
|
184
|
+
- test/adapters/postgis.rb
|
185
|
+
- test/adapters/postgresql.rb
|
186
|
+
- test/adapters/postgresql_makara.rb
|
187
|
+
- test/adapters/seamless_database_pool.rb
|
188
|
+
- test/adapters/spatialite.rb
|
189
|
+
- test/adapters/sqlite3.rb
|
190
|
+
- test/database.yml.sample
|
191
|
+
- test/import_test.rb
|
192
|
+
- test/jdbcmysql/import_test.rb
|
193
|
+
- test/jdbcpostgresql/import_test.rb
|
194
|
+
- test/models/book.rb
|
195
|
+
- test/models/chapter.rb
|
196
|
+
- test/models/discount.rb
|
197
|
+
- test/models/end_note.rb
|
198
|
+
- test/models/group.rb
|
199
|
+
- test/models/promotion.rb
|
200
|
+
- test/models/question.rb
|
201
|
+
- test/models/rule.rb
|
202
|
+
- test/models/topic.rb
|
203
|
+
- test/models/widget.rb
|
204
|
+
- test/mysql2/import_test.rb
|
205
|
+
- test/mysql2_makara/import_test.rb
|
206
|
+
- test/mysqlspatial2/import_test.rb
|
207
|
+
- test/postgis/import_test.rb
|
208
|
+
- test/postgresql/import_test.rb
|
209
|
+
- test/schema/generic_schema.rb
|
210
|
+
- test/schema/mysql_schema.rb
|
211
|
+
- test/schema/version.rb
|
212
|
+
- test/sqlite3/import_test.rb
|
213
|
+
- test/support/active_support/test_case_extensions.rb
|
214
|
+
- test/support/assertions.rb
|
215
|
+
- test/support/factories.rb
|
216
|
+
- test/support/generate.rb
|
217
|
+
- test/support/mysql/import_examples.rb
|
218
|
+
- test/support/postgresql/import_examples.rb
|
219
|
+
- test/support/shared_examples/on_duplicate_key_update.rb
|
220
|
+
- test/support/shared_examples/recursive_import.rb
|
221
|
+
- test/synchronize_test.rb
|
222
|
+
- test/test_helper.rb
|
223
|
+
- test/travis/database.yml
|
224
|
+
- test/value_sets_bytes_parser_test.rb
|
225
|
+
- test/value_sets_records_parser_test.rb
|