activerecord-import 1.0.2 → 1.5.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/.github/workflows/test.yaml +113 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +74 -8
- data/.rubocop_todo.yml +6 -16
- data/Brewfile +3 -1
- data/CHANGELOG.md +115 -3
- data/Gemfile +12 -10
- data/LICENSE +21 -56
- data/README.markdown +71 -60
- data/Rakefile +2 -0
- data/activerecord-import.gemspec +6 -5
- data/benchmarks/benchmark.rb +10 -4
- data/benchmarks/lib/base.rb +4 -2
- data/benchmarks/lib/cli_parser.rb +4 -2
- data/benchmarks/lib/float.rb +2 -0
- data/benchmarks/lib/mysql2_benchmark.rb +2 -0
- data/benchmarks/lib/output_to_csv.rb +2 -0
- data/benchmarks/lib/output_to_html.rb +4 -2
- data/benchmarks/models/test_innodb.rb +2 -0
- data/benchmarks/models/test_memory.rb +2 -0
- data/benchmarks/models/test_myisam.rb +2 -0
- data/benchmarks/schema/{mysql_schema.rb → mysql2_schema.rb} +2 -0
- data/gemfiles/4.2.gemfile +2 -0
- data/gemfiles/5.0.gemfile +2 -0
- data/gemfiles/5.1.gemfile +2 -0
- data/gemfiles/5.2.gemfile +2 -0
- data/gemfiles/6.0.gemfile +4 -1
- data/gemfiles/6.1.gemfile +4 -1
- data/gemfiles/7.0.gemfile +4 -0
- data/lib/activerecord-import/active_record/adapters/abstract_adapter.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/jdbcmysql_adapter.rb +6 -4
- data/lib/activerecord-import/active_record/adapters/jdbcpostgresql_adapter.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/jdbcsqlite3_adapter.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/mysql2_adapter.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/postgresql_adapter.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/seamless_database_pool_adapter.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/sqlite3_adapter.rb +2 -0
- data/lib/activerecord-import/adapters/abstract_adapter.rb +14 -5
- data/lib/activerecord-import/adapters/em_mysql2_adapter.rb +2 -0
- data/lib/activerecord-import/adapters/mysql2_adapter.rb +2 -0
- data/lib/activerecord-import/adapters/mysql_adapter.rb +33 -25
- data/lib/activerecord-import/adapters/postgresql_adapter.rb +69 -56
- data/lib/activerecord-import/adapters/sqlite3_adapter.rb +39 -39
- data/lib/activerecord-import/base.rb +10 -2
- data/lib/activerecord-import/import.rb +143 -62
- data/lib/activerecord-import/mysql2.rb +2 -0
- data/lib/activerecord-import/postgresql.rb +2 -0
- data/lib/activerecord-import/sqlite3.rb +2 -0
- data/lib/activerecord-import/synchronize.rb +3 -1
- data/lib/activerecord-import/value_sets_parser.rb +5 -0
- data/lib/activerecord-import/version.rb +3 -1
- data/lib/activerecord-import.rb +3 -1
- data/test/adapters/jdbcmysql.rb +2 -0
- data/test/adapters/jdbcpostgresql.rb +2 -0
- data/test/adapters/jdbcsqlite3.rb +2 -0
- data/test/adapters/makara_postgis.rb +2 -0
- data/test/adapters/mysql2.rb +2 -0
- data/test/adapters/mysql2_makara.rb +2 -0
- data/test/adapters/mysql2spatial.rb +2 -0
- data/test/adapters/postgis.rb +2 -0
- data/test/adapters/postgresql.rb +2 -0
- data/test/adapters/postgresql_makara.rb +2 -0
- data/test/adapters/seamless_database_pool.rb +2 -0
- data/test/adapters/spatialite.rb +2 -0
- data/test/adapters/sqlite3.rb +2 -0
- data/test/{travis → github}/database.yml +3 -1
- data/test/import_test.rb +93 -2
- data/test/jdbcmysql/import_test.rb +5 -3
- data/test/jdbcpostgresql/import_test.rb +4 -2
- data/test/jdbcsqlite3/import_test.rb +4 -2
- data/test/makara_postgis/import_test.rb +4 -2
- data/test/models/account.rb +2 -0
- data/test/models/alarm.rb +2 -0
- data/test/models/animal.rb +8 -0
- data/test/models/bike_maker.rb +3 -0
- data/test/models/book.rb +2 -0
- data/test/models/car.rb +2 -0
- data/test/models/card.rb +5 -0
- data/test/models/chapter.rb +2 -0
- data/test/models/customer.rb +8 -0
- data/test/models/deck.rb +8 -0
- data/test/models/dictionary.rb +2 -0
- data/test/models/discount.rb +2 -0
- data/test/models/end_note.rb +2 -0
- data/test/models/group.rb +2 -0
- data/test/models/order.rb +8 -0
- data/test/models/playing_card.rb +4 -0
- data/test/models/promotion.rb +2 -0
- data/test/models/question.rb +2 -0
- data/test/models/rule.rb +2 -0
- data/test/models/tag.rb +3 -0
- data/test/models/tag_alias.rb +5 -0
- data/test/models/topic.rb +7 -0
- data/test/models/user.rb +2 -0
- data/test/models/user_token.rb +2 -0
- data/test/models/vendor.rb +2 -0
- data/test/models/widget.rb +2 -0
- data/test/mysql2/import_test.rb +5 -3
- data/test/mysql2_makara/import_test.rb +5 -3
- data/test/mysqlspatial2/import_test.rb +5 -3
- data/test/postgis/import_test.rb +4 -2
- data/test/postgresql/import_test.rb +4 -2
- data/test/schema/generic_schema.rb +34 -0
- data/test/schema/jdbcpostgresql_schema.rb +3 -1
- data/test/schema/mysql2_schema.rb +2 -0
- data/test/schema/postgis_schema.rb +3 -1
- data/test/schema/postgresql_schema.rb +16 -0
- data/test/schema/sqlite3_schema.rb +2 -0
- data/test/schema/version.rb +2 -0
- data/test/sqlite3/import_test.rb +4 -2
- data/test/support/active_support/test_case_extensions.rb +2 -0
- data/test/support/assertions.rb +2 -0
- data/test/support/factories.rb +2 -0
- data/test/support/generate.rb +4 -2
- data/test/support/mysql/import_examples.rb +2 -1
- data/test/support/postgresql/import_examples.rb +96 -2
- data/test/support/shared_examples/on_duplicate_key_ignore.rb +2 -0
- data/test/support/shared_examples/on_duplicate_key_update.rb +50 -9
- data/test/support/shared_examples/recursive_import.rb +32 -1
- data/test/support/sqlite3/import_examples.rb +2 -1
- data/test/synchronize_test.rb +2 -0
- data/test/test_helper.rb +30 -5
- data/test/value_sets_bytes_parser_test.rb +3 -1
- data/test/value_sets_records_parser_test.rb +3 -1
- metadata +27 -16
- data/.travis.yml +0 -70
- data/gemfiles/3.2.gemfile +0 -2
- data/gemfiles/4.0.gemfile +0 -2
- data/gemfiles/4.1.gemfile +0 -2
data/test/import_test.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require File.expand_path('../test_helper', __FILE__)
|
|
2
4
|
|
|
3
5
|
describe "#import" do
|
|
@@ -159,6 +161,25 @@ describe "#import" do
|
|
|
159
161
|
Tag.import columns, values, validate: false
|
|
160
162
|
end
|
|
161
163
|
end
|
|
164
|
+
|
|
165
|
+
it "should import models that are required to belong to models with composite primary keys" do
|
|
166
|
+
tag = Tag.create!(tag_id: 1, publisher_id: 1, tag: 'Mystery')
|
|
167
|
+
valid_tag_alias = TagAlias.new(tag_id: tag.tag_id, parent_id: tag.publisher_id, alias: 'Detective')
|
|
168
|
+
invalid_tag_aliases = [
|
|
169
|
+
TagAlias.new(tag_id: nil, parent_id: nil, alias: 'Detective'),
|
|
170
|
+
TagAlias.new(tag_id: tag.tag_id, parent_id: nil, alias: 'Detective'),
|
|
171
|
+
TagAlias.new(tag_id: nil, parent_id: tag.publisher_id, alias: 'Detective'),
|
|
172
|
+
]
|
|
173
|
+
|
|
174
|
+
assert_difference "TagAlias.count", +1 do
|
|
175
|
+
TagAlias.import [valid_tag_alias]
|
|
176
|
+
end
|
|
177
|
+
invalid_tag_aliases.each do |invalid_tag_alias|
|
|
178
|
+
assert_no_difference "TagAlias.count" do
|
|
179
|
+
TagAlias.import [invalid_tag_alias]
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
end
|
|
162
183
|
end
|
|
163
184
|
end
|
|
164
185
|
|
|
@@ -169,7 +190,17 @@ describe "#import" do
|
|
|
169
190
|
assert_difference "Dictionary.count", +1 do
|
|
170
191
|
Dictionary.import dictionaries
|
|
171
192
|
end
|
|
172
|
-
assert_equal "Dictionary", Dictionary.
|
|
193
|
+
assert_equal "Dictionary", Dictionary.last.type
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
it "should import arrays successfully" do
|
|
197
|
+
columns = [:author_name, :title]
|
|
198
|
+
values = [["Noah Webster", "Webster's Dictionary"]]
|
|
199
|
+
|
|
200
|
+
assert_difference "Dictionary.count", +1 do
|
|
201
|
+
Dictionary.import columns, values
|
|
202
|
+
end
|
|
203
|
+
assert_equal "Dictionary", Dictionary.last.type
|
|
173
204
|
end
|
|
174
205
|
end
|
|
175
206
|
|
|
@@ -252,6 +283,16 @@ describe "#import" do
|
|
|
252
283
|
end
|
|
253
284
|
end
|
|
254
285
|
|
|
286
|
+
it "should index the failed instances by their poistion in the set if `track_failures` is true" do
|
|
287
|
+
index_offset = valid_values.length
|
|
288
|
+
results = Topic.import columns, valid_values + invalid_values, validate: true, track_validation_failures: true
|
|
289
|
+
assert_equal invalid_values.size, results.failed_instances.size
|
|
290
|
+
invalid_values.each_with_index do |value_set, index|
|
|
291
|
+
assert_equal index + index_offset, results.failed_instances[index].first
|
|
292
|
+
assert_equal value_set.first, results.failed_instances[index].last.title
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
|
|
255
296
|
it "should set ids in valid models if adapter supports setting primary key of imported objects" do
|
|
256
297
|
if ActiveRecord::Base.supports_setting_primary_key_of_imported_objects?
|
|
257
298
|
Topic.import (invalid_models + valid_models), validate: true
|
|
@@ -395,6 +436,15 @@ describe "#import" do
|
|
|
395
436
|
assert_equal 3, result.num_inserts if Topic.supports_import?
|
|
396
437
|
end
|
|
397
438
|
end
|
|
439
|
+
|
|
440
|
+
it "should accept and call an optional callable to run after each batch" do
|
|
441
|
+
lambda_called = 0
|
|
442
|
+
|
|
443
|
+
my_proc = ->(_row_count, _batches, _batch, _duration) { lambda_called += 1 }
|
|
444
|
+
Topic.import Build(10, :topics), batch_size: 4, batch_progress: my_proc
|
|
445
|
+
|
|
446
|
+
assert_equal 3, lambda_called
|
|
447
|
+
end
|
|
398
448
|
end
|
|
399
449
|
|
|
400
450
|
context "with :synchronize option" do
|
|
@@ -526,7 +576,11 @@ describe "#import" do
|
|
|
526
576
|
context "when the timestamps columns are present" do
|
|
527
577
|
setup do
|
|
528
578
|
@existing_book = Book.create(title: "Fell", author_name: "Curry", publisher: "Bayer", created_at: 2.years.ago.utc, created_on: 2.years.ago.utc, updated_at: 2.years.ago.utc, updated_on: 2.years.ago.utc)
|
|
529
|
-
ActiveRecord
|
|
579
|
+
if ActiveRecord.respond_to?(:default_timezone)
|
|
580
|
+
ActiveRecord.default_timezone = :utc
|
|
581
|
+
else
|
|
582
|
+
ActiveRecord::Base.default_timezone = :utc
|
|
583
|
+
end
|
|
530
584
|
Timecop.freeze(time) do
|
|
531
585
|
assert_difference "Book.count", +2 do
|
|
532
586
|
Book.import %w(title author_name publisher created_at created_on updated_at updated_on), [["LDAP", "Big Bird", "Del Rey", nil, nil, nil, nil], [@existing_book.title, @existing_book.author_name, @existing_book.publisher, @existing_book.created_at, @existing_book.created_on, @existing_book.updated_at, @existing_book.updated_on]]
|
|
@@ -642,6 +696,14 @@ describe "#import" do
|
|
|
642
696
|
assert_equal [val1, val2], scope.map(&column).sort
|
|
643
697
|
end
|
|
644
698
|
|
|
699
|
+
context "for cards and decks" do
|
|
700
|
+
it "works when the polymorphic name is different than base class name" do
|
|
701
|
+
deck = Deck.create(id: 1, name: 'test')
|
|
702
|
+
deck.cards.import [:id, :deck_type], [[1, 'PlayingCard']]
|
|
703
|
+
assert_equal deck.cards.first.deck_type, "PlayingCard"
|
|
704
|
+
end
|
|
705
|
+
end
|
|
706
|
+
|
|
645
707
|
it "works importing array of hashes" do
|
|
646
708
|
scope.import [{ column => val1 }, { column => val2 }]
|
|
647
709
|
|
|
@@ -900,4 +962,33 @@ describe "#import" do
|
|
|
900
962
|
end
|
|
901
963
|
end
|
|
902
964
|
end
|
|
965
|
+
describe "importing model with after_initialize callback" do
|
|
966
|
+
let(:columns) { %w(name size) }
|
|
967
|
+
let(:valid_values) { [%w("Deer", "Small"), %w("Monkey", "Medium")] }
|
|
968
|
+
let(:invalid_values) do
|
|
969
|
+
[
|
|
970
|
+
{ name: "giraffe", size: "Large" },
|
|
971
|
+
{ size: "Medium" } # name is missing
|
|
972
|
+
]
|
|
973
|
+
end
|
|
974
|
+
context "with validation checks turned off" do
|
|
975
|
+
it "should import valid data" do
|
|
976
|
+
Animal.import(columns, valid_values, validate: false)
|
|
977
|
+
assert_equal 2, Animal.count
|
|
978
|
+
end
|
|
979
|
+
it "should raise ArgumentError" do
|
|
980
|
+
assert_raise(ArgumentError) { Animal.import(invalid_values, validate: false) }
|
|
981
|
+
end
|
|
982
|
+
end
|
|
983
|
+
|
|
984
|
+
context "with validation checks turned on" do
|
|
985
|
+
it "should import valid data" do
|
|
986
|
+
Animal.import(columns, valid_values, validate: true)
|
|
987
|
+
assert_equal 2, Animal.count
|
|
988
|
+
end
|
|
989
|
+
it "should raise ArgumentError" do
|
|
990
|
+
assert_raise(ArgumentError) { Animal.import(invalid_values, validate: true) }
|
|
991
|
+
end
|
|
992
|
+
end
|
|
993
|
+
end
|
|
903
994
|
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require File.expand_path(File.dirname(__FILE__)
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
|
4
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/assertions")
|
|
5
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/mysql/import_examples")
|
|
4
6
|
|
|
5
7
|
should_support_mysql_import_functionality
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
|
4
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/postgresql/import_examples")
|
|
3
5
|
|
|
4
6
|
should_support_postgresql_import_functionality
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
|
4
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/sqlite3/import_examples")
|
|
3
5
|
|
|
4
6
|
should_support_sqlite3_import_functionality
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
|
4
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/postgresql/import_examples")
|
|
3
5
|
|
|
4
6
|
should_support_postgresql_import_functionality
|
|
5
7
|
|
data/test/models/account.rb
CHANGED
data/test/models/alarm.rb
CHANGED
data/test/models/bike_maker.rb
CHANGED
data/test/models/book.rb
CHANGED
data/test/models/car.rb
CHANGED
data/test/models/card.rb
ADDED
data/test/models/chapter.rb
CHANGED
data/test/models/deck.rb
ADDED
data/test/models/dictionary.rb
CHANGED
data/test/models/discount.rb
CHANGED
data/test/models/end_note.rb
CHANGED
data/test/models/group.rb
CHANGED
data/test/models/promotion.rb
CHANGED
data/test/models/question.rb
CHANGED
data/test/models/rule.rb
CHANGED
data/test/models/tag.rb
CHANGED
data/test/models/topic.rb
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class Topic < ActiveRecord::Base
|
|
4
|
+
if ENV['AR_VERSION'].to_i >= 6.0
|
|
5
|
+
self.ignored_columns = [:priority]
|
|
6
|
+
end
|
|
7
|
+
alias_attribute :name, :title
|
|
8
|
+
|
|
2
9
|
validates_presence_of :author_name
|
|
3
10
|
validates :title, numericality: { only_integer: true }, on: :context_test
|
|
4
11
|
validates :title, uniqueness: true
|
data/test/models/user.rb
CHANGED
data/test/models/user_token.rb
CHANGED
data/test/models/vendor.rb
CHANGED
data/test/models/widget.rb
CHANGED
data/test/mysql2/import_test.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require File.expand_path(File.dirname(__FILE__)
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
|
4
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/assertions")
|
|
5
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/mysql/import_examples")
|
|
4
6
|
|
|
5
7
|
should_support_mysql_import_functionality
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require File.expand_path(File.dirname(__FILE__)
|
|
4
|
-
|
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
|
4
|
+
|
|
5
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/assertions")
|
|
6
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/mysql/import_examples")
|
|
5
7
|
|
|
6
8
|
should_support_mysql_import_functionality
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require File.expand_path(File.dirname(__FILE__)
|
|
4
|
-
|
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
|
4
|
+
|
|
5
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/assertions")
|
|
6
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/mysql/import_examples")
|
|
5
7
|
|
|
6
8
|
should_support_mysql_import_functionality
|
data/test/postgis/import_test.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
|
4
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/postgresql/import_examples")
|
|
3
5
|
|
|
4
6
|
should_support_postgresql_import_functionality
|
|
5
7
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
|
4
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/postgresql/import_examples")
|
|
3
5
|
|
|
4
6
|
should_support_postgresql_import_functionality
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
ActiveRecord::Schema.define do
|
|
2
4
|
create_table :schema_info, force: :cascade do |t|
|
|
3
5
|
t.integer :version, unique: true
|
|
@@ -20,6 +22,7 @@ ActiveRecord::Schema.define do
|
|
|
20
22
|
t.boolean :approved, default: '1'
|
|
21
23
|
t.integer :replies_count
|
|
22
24
|
t.integer :parent_id
|
|
25
|
+
t.integer :priority, default: 0
|
|
23
26
|
t.string :type
|
|
24
27
|
t.datetime :created_at
|
|
25
28
|
t.datetime :created_on
|
|
@@ -52,6 +55,20 @@ ActiveRecord::Schema.define do
|
|
|
52
55
|
t.string :name
|
|
53
56
|
end
|
|
54
57
|
|
|
58
|
+
create_table :cards, force: :cascade do |t|
|
|
59
|
+
t.string :name
|
|
60
|
+
t.string :deck_type
|
|
61
|
+
t.integer :deck_id
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
create_table :decks, force: :cascade do |t|
|
|
65
|
+
t.string :name
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
create_table :playing_cards, force: :cascade do |t|
|
|
69
|
+
t.string :name
|
|
70
|
+
end
|
|
71
|
+
|
|
55
72
|
create_table :books, force: :cascade do |t|
|
|
56
73
|
t.string :title, null: false
|
|
57
74
|
t.string :publisher, null: false, default: 'Default Publisher'
|
|
@@ -190,5 +207,22 @@ ActiveRecord::Schema.define do
|
|
|
190
207
|
PRIMARY KEY (tag_id, publisher_id)
|
|
191
208
|
);
|
|
192
209
|
).split.join(' ').strip
|
|
210
|
+
|
|
211
|
+
create_table :tag_aliases, force: :cascade do |t|
|
|
212
|
+
t.integer :tag_id, null: false
|
|
213
|
+
t.integer :parent_id, null: false
|
|
214
|
+
t.string :alias, null: false
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
create_table :customers, force: :cascade do |t|
|
|
219
|
+
t.integer :account_id
|
|
220
|
+
t.string :name
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
create_table :orders, force: :cascade do |t|
|
|
224
|
+
t.integer :account_id
|
|
225
|
+
t.integer :customer_id
|
|
226
|
+
t.integer :amount
|
|
193
227
|
end
|
|
194
228
|
end
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
ActiveRecord::Schema.define do
|
|
2
4
|
execute('CREATE extension IF NOT EXISTS "hstore";')
|
|
3
5
|
execute('CREATE extension IF NOT EXISTS "pgcrypto";')
|
|
4
6
|
execute('CREATE extension IF NOT EXISTS "uuid-ossp";')
|
|
5
7
|
|
|
8
|
+
# create ENUM if it does not exist yet
|
|
9
|
+
begin
|
|
10
|
+
execute('CREATE TYPE vendor_type AS ENUM (\'wholesaler\', \'retailer\');')
|
|
11
|
+
rescue ActiveRecord::StatementInvalid => e
|
|
12
|
+
# since PostgreSQL does not support IF NOT EXISTS when creating a TYPE,
|
|
13
|
+
# rescue the error and check the error class
|
|
14
|
+
raise unless e.cause.is_a? PG::DuplicateObject
|
|
15
|
+
execute('ALTER TYPE vendor_type ADD VALUE IF NOT EXISTS \'wholesaler\';')
|
|
16
|
+
execute('ALTER TYPE vendor_type ADD VALUE IF NOT EXISTS \'retailer\';')
|
|
17
|
+
end
|
|
18
|
+
|
|
6
19
|
create_table :vendors, id: :uuid, force: :cascade do |t|
|
|
7
20
|
t.string :name, null: true
|
|
21
|
+
t.text :hours
|
|
8
22
|
t.text :preferences
|
|
9
23
|
|
|
10
24
|
if t.respond_to?(:json)
|
|
@@ -29,6 +43,8 @@ ActiveRecord::Schema.define do
|
|
|
29
43
|
t.text :json_data
|
|
30
44
|
end
|
|
31
45
|
|
|
46
|
+
t.column :vendor_type, :vendor_type
|
|
47
|
+
|
|
32
48
|
t.datetime :created_at
|
|
33
49
|
t.datetime :updated_at
|
|
34
50
|
end
|
data/test/schema/version.rb
CHANGED
data/test/sqlite3/import_test.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
|
4
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/sqlite3/import_examples")
|
|
3
5
|
|
|
4
6
|
should_support_sqlite3_import_functionality
|
data/test/support/assertions.rb
CHANGED
data/test/support/factories.rb
CHANGED
data/test/support/generate.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class ActiveSupport::TestCase
|
|
2
|
-
def Build(*args) # rubocop:disable
|
|
4
|
+
def Build(*args) # rubocop:disable Naming/MethodName
|
|
3
5
|
n = args.shift if args.first.is_a?(Numeric)
|
|
4
6
|
factory = args.shift
|
|
5
7
|
factory_bot_args = args.shift || {}
|
|
@@ -13,7 +15,7 @@ class ActiveSupport::TestCase
|
|
|
13
15
|
end
|
|
14
16
|
end
|
|
15
17
|
|
|
16
|
-
def Generate(*args) # rubocop:disable
|
|
18
|
+
def Generate(*args) # rubocop:disable Naming/MethodName
|
|
17
19
|
n = args.shift if args.first.is_a?(Numeric)
|
|
18
20
|
factory = args.shift
|
|
19
21
|
factory_bot_args = args.shift || {}
|