activerecord-import 0.10.0 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +49 -0
  4. data/.rubocop_todo.yml +36 -0
  5. data/.travis.yml +64 -8
  6. data/CHANGELOG.md +475 -0
  7. data/Gemfile +32 -15
  8. data/LICENSE +21 -56
  9. data/README.markdown +564 -35
  10. data/Rakefile +20 -3
  11. data/activerecord-import.gemspec +7 -7
  12. data/benchmarks/README +2 -2
  13. data/benchmarks/benchmark.rb +68 -64
  14. data/benchmarks/lib/base.rb +138 -137
  15. data/benchmarks/lib/cli_parser.rb +107 -103
  16. data/benchmarks/lib/{mysql_benchmark.rb → mysql2_benchmark.rb} +19 -22
  17. data/benchmarks/lib/output_to_csv.rb +5 -4
  18. data/benchmarks/lib/output_to_html.rb +8 -13
  19. data/benchmarks/models/test_innodb.rb +1 -1
  20. data/benchmarks/models/test_memory.rb +1 -1
  21. data/benchmarks/models/test_myisam.rb +1 -1
  22. data/benchmarks/schema/mysql2_schema.rb +16 -0
  23. data/gemfiles/3.2.gemfile +2 -4
  24. data/gemfiles/4.0.gemfile +2 -4
  25. data/gemfiles/4.1.gemfile +2 -4
  26. data/gemfiles/4.2.gemfile +2 -4
  27. data/gemfiles/5.0.gemfile +2 -0
  28. data/gemfiles/5.1.gemfile +2 -0
  29. data/gemfiles/5.2.gemfile +2 -0
  30. data/gemfiles/6.0.gemfile +2 -0
  31. data/gemfiles/6.1.gemfile +1 -0
  32. data/lib/activerecord-import/active_record/adapters/jdbcsqlite3_adapter.rb +6 -0
  33. data/lib/activerecord-import/active_record/adapters/sqlite3_adapter.rb +0 -1
  34. data/lib/activerecord-import/adapters/abstract_adapter.rb +23 -17
  35. data/lib/activerecord-import/adapters/mysql_adapter.rb +52 -25
  36. data/lib/activerecord-import/adapters/postgresql_adapter.rb +187 -10
  37. data/lib/activerecord-import/adapters/sqlite3_adapter.rb +148 -17
  38. data/lib/activerecord-import/base.rb +15 -9
  39. data/lib/activerecord-import/import.rb +740 -191
  40. data/lib/activerecord-import/synchronize.rb +21 -21
  41. data/lib/activerecord-import/value_sets_parser.rb +33 -8
  42. data/lib/activerecord-import/version.rb +1 -1
  43. data/lib/activerecord-import.rb +4 -15
  44. data/test/adapters/jdbcsqlite3.rb +1 -0
  45. data/test/adapters/makara_postgis.rb +1 -0
  46. data/test/adapters/mysql2_makara.rb +1 -0
  47. data/test/adapters/mysql2spatial.rb +1 -1
  48. data/test/adapters/postgis.rb +1 -1
  49. data/test/adapters/postgresql.rb +1 -1
  50. data/test/adapters/postgresql_makara.rb +1 -0
  51. data/test/adapters/spatialite.rb +1 -1
  52. data/test/adapters/sqlite3.rb +1 -1
  53. data/test/database.yml.sample +13 -18
  54. data/test/import_test.rb +608 -89
  55. data/test/jdbcmysql/import_test.rb +2 -3
  56. data/test/jdbcpostgresql/import_test.rb +0 -2
  57. data/test/jdbcsqlite3/import_test.rb +4 -0
  58. data/test/makara_postgis/import_test.rb +8 -0
  59. data/test/models/account.rb +3 -0
  60. data/test/models/alarm.rb +2 -0
  61. data/test/models/animal.rb +6 -0
  62. data/test/models/bike_maker.rb +7 -0
  63. data/test/models/book.rb +7 -6
  64. data/test/models/car.rb +3 -0
  65. data/test/models/chapter.rb +2 -2
  66. data/test/models/dictionary.rb +4 -0
  67. data/test/models/discount.rb +3 -0
  68. data/test/models/end_note.rb +2 -2
  69. data/test/models/promotion.rb +3 -0
  70. data/test/models/question.rb +3 -0
  71. data/test/models/rule.rb +3 -0
  72. data/test/models/tag.rb +4 -0
  73. data/test/models/topic.rb +17 -3
  74. data/test/models/user.rb +3 -0
  75. data/test/models/user_token.rb +4 -0
  76. data/test/models/vendor.rb +7 -0
  77. data/test/models/widget.rb +19 -2
  78. data/test/mysql2/import_test.rb +2 -3
  79. data/test/{em_mysql2 → mysql2_makara}/import_test.rb +1 -1
  80. data/test/mysqlspatial2/import_test.rb +2 -2
  81. data/test/postgis/import_test.rb +5 -1
  82. data/test/schema/generic_schema.rb +159 -85
  83. data/test/schema/jdbcpostgresql_schema.rb +1 -0
  84. data/test/schema/mysql2_schema.rb +19 -0
  85. data/test/schema/postgis_schema.rb +1 -0
  86. data/test/schema/postgresql_schema.rb +61 -0
  87. data/test/schema/sqlite3_schema.rb +13 -0
  88. data/test/sqlite3/import_test.rb +2 -50
  89. data/test/support/active_support/test_case_extensions.rb +21 -13
  90. data/test/support/{mysql/assertions.rb → assertions.rb} +20 -2
  91. data/test/support/factories.rb +39 -14
  92. data/test/support/generate.rb +10 -10
  93. data/test/support/mysql/import_examples.rb +49 -98
  94. data/test/support/postgresql/import_examples.rb +535 -57
  95. data/test/support/shared_examples/on_duplicate_key_ignore.rb +43 -0
  96. data/test/support/shared_examples/on_duplicate_key_update.rb +378 -0
  97. data/test/support/shared_examples/recursive_import.rb +225 -0
  98. data/test/support/sqlite3/import_examples.rb +231 -0
  99. data/test/synchronize_test.rb +10 -2
  100. data/test/test_helper.rb +36 -8
  101. data/test/travis/database.yml +26 -17
  102. data/test/value_sets_bytes_parser_test.rb +25 -17
  103. data/test/value_sets_records_parser_test.rb +6 -6
  104. metadata +86 -42
  105. data/benchmarks/boot.rb +0 -18
  106. data/benchmarks/schema/mysql_schema.rb +0 -16
  107. data/gemfiles/3.1.gemfile +0 -4
  108. data/lib/activerecord-import/active_record/adapters/em_mysql2_adapter.rb +0 -8
  109. data/lib/activerecord-import/active_record/adapters/mysql_adapter.rb +0 -6
  110. data/lib/activerecord-import/em_mysql2.rb +0 -7
  111. data/lib/activerecord-import/mysql.rb +0 -7
  112. data/test/adapters/em_mysql2.rb +0 -1
  113. data/test/adapters/mysql.rb +0 -1
  114. data/test/adapters/mysqlspatial.rb +0 -1
  115. data/test/mysql/import_test.rb +0 -6
  116. data/test/mysqlspatial/import_test.rb +0 -6
  117. data/test/schema/mysql_schema.rb +0 -18
  118. data/test/travis/build.sh +0 -30
@@ -1,6 +1,5 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/../support/mysql/assertions')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../support/assertions')
4
3
  require File.expand_path(File.dirname(__FILE__) + '/../support/mysql/import_examples')
5
4
 
6
- should_support_mysql_import_functionality
5
+ should_support_mysql_import_functionality
@@ -1,6 +1,4 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
-
3
- #require File.expand_path(File.dirname(__FILE__) + '/../support/postgresql/assertions')
4
2
  require File.expand_path(File.dirname(__FILE__) + '/../support/postgresql/import_examples')
5
3
 
6
4
  should_support_postgresql_import_functionality
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../support/sqlite3/import_examples')
3
+
4
+ should_support_sqlite3_import_functionality
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../support/postgresql/import_examples')
3
+
4
+ should_support_postgresql_import_functionality
5
+
6
+ if ActiveRecord::Base.connection.supports_on_duplicate_key_update?
7
+ should_support_postgresql_upsert_functionality
8
+ end
@@ -0,0 +1,3 @@
1
+ class Account < ActiveRecord::Base
2
+ self.locking_column = :lock
3
+ end
@@ -0,0 +1,2 @@
1
+ class Alarm < ActiveRecord::Base
2
+ end
@@ -0,0 +1,6 @@
1
+ class Animal < ActiveRecord::Base
2
+ after_initialize :validate_name_presence, if: :new_record?
3
+ def validate_name_presence
4
+ raise ArgumentError if name.nil?
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ module Bike
2
+ def self.table_name_prefix
3
+ 'bike_'
4
+ end
5
+ class Maker < ActiveRecord::Base
6
+ end
7
+ end
data/test/models/book.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  class Book < ActiveRecord::Base
2
- belongs_to :topic, :inverse_of=>:books
3
- has_many :chapters, :autosave => true, :inverse_of => :book
4
- has_many :end_notes, :autosave => true, :inverse_of => :book
5
- if ENV['AR_VERSION'].to_i >= 4.1
6
- enum status: [:draft, :published]
7
- end
2
+ belongs_to :topic, inverse_of: :books
3
+ belongs_to :tag, foreign_key: [:tag_id, :parent_id]
4
+
5
+ has_many :chapters, inverse_of: :book
6
+ has_many :discounts, as: :discountable
7
+ has_many :end_notes, inverse_of: :book
8
+ enum status: [:draft, :published] if ENV['AR_VERSION'].to_f >= 4.1
8
9
  end
@@ -0,0 +1,3 @@
1
+ class Car < ActiveRecord::Base
2
+ self.primary_key = :Name
3
+ end
@@ -1,4 +1,4 @@
1
1
  class Chapter < ActiveRecord::Base
2
- belongs_to :book, :inverse_of=>:chapters
3
- validates :title, :presence => true
2
+ belongs_to :book, inverse_of: :chapters
3
+ validates :title, presence: true
4
4
  end
@@ -0,0 +1,4 @@
1
+ require_relative 'book'
2
+
3
+ class Dictionary < Book
4
+ end
@@ -0,0 +1,3 @@
1
+ class Discount < ActiveRecord::Base
2
+ belongs_to :discountable, polymorphic: true
3
+ end
@@ -1,4 +1,4 @@
1
1
  class EndNote < ActiveRecord::Base
2
- belongs_to :book, :inverse_of=>:end_notes
3
- validates :note, :presence => true
2
+ belongs_to :book, inverse_of: :end_notes
3
+ validates :note, presence: true
4
4
  end
@@ -0,0 +1,3 @@
1
+ class Promotion < ActiveRecord::Base
2
+ self.primary_key = :promotion_id
3
+ end
@@ -0,0 +1,3 @@
1
+ class Question < ActiveRecord::Base
2
+ has_one :rule
3
+ end
@@ -0,0 +1,3 @@
1
+ class Rule < ActiveRecord::Base
2
+ belongs_to :question
3
+ end
@@ -0,0 +1,4 @@
1
+ class Tag < ActiveRecord::Base
2
+ self.primary_keys = :tag_id, :publisher_id unless ENV["SKIP_COMPOSITE_PK"]
3
+ has_many :books, inverse_of: :tag
4
+ end
data/test/models/topic.rb CHANGED
@@ -1,9 +1,23 @@
1
1
  class Topic < ActiveRecord::Base
2
2
  validates_presence_of :author_name
3
3
  validates :title, numericality: { only_integer: true }, on: :context_test
4
+ validates :title, uniqueness: true
5
+ validates :content, uniqueness: true
6
+ validates :word_count, numericality: { greater_than: 0 }, if: :content?
4
7
 
5
- has_many :books, :autosave=>true, :inverse_of=>:topic
6
- belongs_to :parent, :class_name => "Topic"
8
+ validate -> { errors.add(:title, :validate_failed) if title == 'validate_failed' }
9
+ before_validation -> { errors.add(:title, :invalid) if title == 'invalid' }
7
10
 
8
- composed_of :description, :mapping => [ %w(title title), %w(author_name author_name)], :allow_nil => true, :class_name => "TopicDescription"
11
+ has_many :books, inverse_of: :topic
12
+ belongs_to :parent, class_name: "Topic"
13
+
14
+ composed_of :description, mapping: [%w(title title), %w(author_name author_name)], allow_nil: true, class_name: "TopicDescription"
15
+
16
+ default_scope { where(approved: true) }
17
+
18
+ private
19
+
20
+ def word_count
21
+ @word_count ||= content.to_s.scan(/\w+/).count
22
+ end
9
23
  end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ has_many :user_tokens, primary_key: :name, foreign_key: :user_name
3
+ end
@@ -0,0 +1,4 @@
1
+ class UserToken < ActiveRecord::Base
2
+ belongs_to :user, primary_key: :name, foreign_key: :user_name
3
+ validates :user, presence: true
4
+ end
@@ -0,0 +1,7 @@
1
+ class Vendor < ActiveRecord::Base
2
+ store :preferences, accessors: [:color], coder: JSON
3
+
4
+ store_accessor :data, :size
5
+ store_accessor :config, :contact
6
+ store_accessor :settings, :charge_code
7
+ end
@@ -1,7 +1,24 @@
1
+ class CustomCoder
2
+ def load(value)
3
+ if value.nil?
4
+ {}
5
+ else
6
+ YAML.load(value)
7
+ end
8
+ end
9
+
10
+ def dump(value)
11
+ YAML.dump(value)
12
+ end
13
+ end
14
+
1
15
  class Widget < ActiveRecord::Base
2
16
  self.primary_key = :w_id
3
17
 
4
- default_scope lambda { where(active: true) }
18
+ default_scope -> { where(active: true) }
5
19
 
6
20
  serialize :data, Hash
7
- end
21
+ serialize :json_data, JSON
22
+ serialize :unspecified_data
23
+ serialize :custom_data, CustomCoder.new
24
+ end
@@ -1,6 +1,5 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/../support/mysql/assertions')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../support/assertions')
4
3
  require File.expand_path(File.dirname(__FILE__) + '/../support/mysql/import_examples')
5
4
 
6
- should_support_mysql_import_functionality
5
+ should_support_mysql_import_functionality
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
2
 
3
- require File.expand_path(File.dirname(__FILE__) + '/../support/mysql/assertions')
3
+ require File.expand_path(File.dirname(__FILE__) + '/../support/assertions')
4
4
  require File.expand_path(File.dirname(__FILE__) + '/../support/mysql/import_examples')
5
5
 
6
6
  should_support_mysql_import_functionality
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
2
 
3
- require File.expand_path(File.dirname(__FILE__) + '/../support/mysql/assertions')
3
+ require File.expand_path(File.dirname(__FILE__) + '/../support/assertions')
4
4
  require File.expand_path(File.dirname(__FILE__) + '/../support/mysql/import_examples')
5
5
 
6
- should_support_mysql_import_functionality
6
+ should_support_mysql_import_functionality
@@ -1,4 +1,8 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
2
  require File.expand_path(File.dirname(__FILE__) + '/../support/postgresql/import_examples')
3
3
 
4
- should_support_postgresql_import_functionality
4
+ should_support_postgresql_import_functionality
5
+
6
+ if ActiveRecord::Base.connection.supports_on_duplicate_key_update?
7
+ should_support_postgresql_upsert_functionality
8
+ end
@@ -1,120 +1,194 @@
1
1
  ActiveRecord::Schema.define do
2
+ create_table :schema_info, force: :cascade do |t|
3
+ t.integer :version, unique: true
4
+ end
5
+ SchemaInfo.create version: SchemaInfo::VERSION
6
+
7
+ create_table :group, force: :cascade do |t|
8
+ t.string :order
9
+ t.timestamps null: true
10
+ end
2
11
 
3
- create_table :schema_info, :force=>true do |t|
4
- t.column :version, :integer, :unique=>true
12
+ create_table :topics, force: :cascade do |t|
13
+ t.string :title, null: false
14
+ t.string :author_name
15
+ t.string :author_email_address
16
+ t.datetime :written_on
17
+ t.time :bonus_time
18
+ t.datetime :last_read
19
+ t.text :content
20
+ t.boolean :approved, default: '1'
21
+ t.integer :replies_count
22
+ t.integer :parent_id
23
+ t.string :type
24
+ t.datetime :created_at
25
+ t.datetime :created_on
26
+ t.datetime :updated_at
27
+ t.datetime :updated_on
5
28
  end
6
- SchemaInfo.create :version=>SchemaInfo::VERSION
7
29
 
8
- create_table :group, :force => true do |t|
9
- t.column :order, :string
10
- t.timestamps
30
+ create_table :projects, force: :cascade do |t|
31
+ t.string :name
32
+ t.string :type
11
33
  end
12
34
 
13
- create_table :topics, :force=>true do |t|
14
- t.column :title, :string, :null => false
15
- t.column :author_name, :string
16
- t.column :author_email_address, :string
17
- t.column :written_on, :datetime
18
- t.column :bonus_time, :time
19
- t.column :last_read, :datetime
20
- t.column :content, :text
21
- t.column :approved, :boolean, :default=>'1'
22
- t.column :replies_count, :integer
23
- t.column :parent_id, :integer
24
- t.column :type, :string
25
- t.column :created_at, :datetime
26
- t.column :created_on, :datetime
27
- t.column :updated_at, :datetime
28
- t.column :updated_on, :datetime
35
+ create_table :developers, force: :cascade do |t|
36
+ t.string :name
37
+ t.integer :salary, default: '70000'
38
+ t.datetime :created_at
39
+ t.integer :team_id
40
+ t.datetime :updated_at
29
41
  end
30
42
 
31
- create_table :projects, :force=>true do |t|
32
- t.column :name, :string
33
- t.column :type, :string
43
+ create_table :addresses, force: :cascade do |t|
44
+ t.string :address
45
+ t.string :city
46
+ t.string :state
47
+ t.string :zip
48
+ t.integer :developer_id
34
49
  end
35
50
 
36
- create_table :developers, :force=>true do |t|
37
- t.column :name, :string
38
- t.column :salary, :integer, :default=>'70000'
39
- t.column :created_at, :datetime
40
- t.column :team_id, :integer
41
- t.column :updated_at, :datetime
51
+ create_table :teams, force: :cascade do |t|
52
+ t.string :name
42
53
  end
43
54
 
44
- create_table :addresses, :force=>true do |t|
45
- t.column :address, :string
46
- t.column :city, :string
47
- t.column :state, :string
48
- t.column :zip, :string
49
- t.column :developer_id, :integer
55
+ create_table :books, force: :cascade do |t|
56
+ t.string :title, null: false
57
+ t.string :publisher, null: false, default: 'Default Publisher'
58
+ t.string :author_name, null: false
59
+ t.datetime :created_at
60
+ t.datetime :created_on
61
+ t.datetime :updated_at
62
+ t.datetime :updated_on
63
+ t.date :publish_date
64
+ t.integer :topic_id
65
+ t.integer :tag_id
66
+ t.integer :publisher_id
67
+ t.boolean :for_sale, default: true
68
+ t.integer :status, default: 0
69
+ t.string :type
50
70
  end
51
71
 
52
- create_table :teams, :force=>true do |t|
53
- t.column :name, :string
72
+ create_table :chapters, force: :cascade do |t|
73
+ t.string :title
74
+ t.integer :book_id, null: false
75
+ t.datetime :created_at
76
+ t.datetime :updated_at
54
77
  end
55
78
 
56
- create_table :books, :force=>true do |t|
57
- t.column :title, :string, :null=>false
58
- t.column :publisher, :string, :null=>false, :default => 'Default Publisher'
59
- t.column :author_name, :string, :null=>false
60
- t.column :created_at, :datetime
61
- t.column :created_on, :datetime
62
- t.column :updated_at, :datetime
63
- t.column :updated_on, :datetime
64
- t.column :publish_date, :date
65
- t.column :topic_id, :integer
66
- t.column :for_sale, :boolean, :default => true
67
- t.column :status, :integer
79
+ create_table :end_notes, primary_key: :end_note_id, force: :cascade do |t|
80
+ t.string :note
81
+ t.integer :book_id, null: false
82
+ t.datetime :created_at
83
+ t.datetime :updated_at
68
84
  end
69
85
 
70
- create_table :chapters, :force => true do |t|
71
- t.column :title, :string
72
- t.column :book_id, :integer, :null => false
73
- t.column :created_at, :datetime
74
- t.column :updated_at, :datetime
86
+ create_table :languages, force: :cascade do |t|
87
+ t.string :name
88
+ t.integer :developer_id
75
89
  end
76
90
 
77
- create_table :end_notes, :force => true do |t|
78
- t.column :note, :string
79
- t.column :book_id, :integer, :null => false
80
- t.column :created_at, :datetime
81
- t.column :updated_at, :datetime
91
+ create_table :shopping_carts, force: :cascade do |t|
92
+ t.string :name, null: true
93
+ t.datetime :created_at
94
+ t.datetime :updated_at
82
95
  end
83
96
 
97
+ create_table :cart_items, force: :cascade do |t|
98
+ t.string :shopping_cart_id, null: false
99
+ t.string :book_id, null: false
100
+ t.integer :copies, default: 1
101
+ t.datetime :created_at
102
+ t.datetime :updated_at
103
+ end
104
+
105
+ add_index :cart_items, [:shopping_cart_id, :book_id], unique: true, name: 'uk_shopping_cart_books'
84
106
 
85
- create_table :languages, :force=>true do |t|
86
- t.column :name, :string
87
- t.column :developer_id, :integer
107
+ create_table :animals, force: :cascade do |t|
108
+ t.string :name, null: false
109
+ t.string :size, default: nil
110
+ t.datetime :created_at
111
+ t.datetime :updated_at
88
112
  end
89
113
 
90
- create_table :shopping_carts, :force=>true do |t|
91
- t.column :name, :string, :null => true
92
- t.column :created_at, :datetime
93
- t.column :updated_at, :datetime
114
+ add_index :animals, [:name], unique: true, name: 'uk_animals'
115
+
116
+ create_table :widgets, id: false, force: :cascade do |t|
117
+ t.integer :w_id, primary_key: true
118
+ t.boolean :active, default: false
119
+ t.text :data
120
+ t.text :json_data
121
+ t.text :unspecified_data
122
+ t.text :custom_data
94
123
  end
95
124
 
96
- create_table :cart_items, :force => true do |t|
97
- t.column :shopping_cart_id, :string, :null => false
98
- t.column :book_id, :string, :null => false
99
- t.column :copies, :integer, :default => 1
100
- t.column :created_at, :datetime
101
- t.column :updated_at, :datetime
125
+ create_table :promotions, primary_key: :promotion_id, force: :cascade do |t|
126
+ t.string :code
127
+ t.string :description
128
+ t.decimal :discount
102
129
  end
103
130
 
104
- add_index :cart_items, [:shopping_cart_id, :book_id], :unique => true, :name => 'uk_shopping_cart_books'
131
+ add_index :promotions, [:code], unique: true, name: 'uk_code'
105
132
 
106
- create_table :animals, :force => true do |t|
107
- t.column :name, :string, :null => false
108
- t.column :size, :string, :default => nil
109
- t.column :created_at, :datetime
110
- t.column :updated_at, :datetime
133
+ create_table :discounts, force: :cascade do |t|
134
+ t.decimal :amount
135
+ t.integer :discountable_id
136
+ t.string :discountable_type
111
137
  end
112
138
 
113
- add_index :animals, [:name], :unique => true, :name => 'uk_animals'
139
+ create_table :rules, id: false, force: :cascade do |t|
140
+ t.integer :id
141
+ t.string :condition_text
142
+ t.integer :question_id
143
+ end
144
+
145
+ create_table :questions, force: :cascade do |t|
146
+ t.string :body
147
+ end
148
+
149
+ create_table :vendors, force: :cascade do |t|
150
+ t.string :name, null: true
151
+ t.text :preferences
152
+ t.text :data
153
+ t.text :config
154
+ t.text :settings
155
+ end
156
+
157
+ create_table :cars, id: false, force: :cascade do |t|
158
+ t.string :Name, null: true
159
+ t.string :Features
160
+ end
161
+
162
+ create_table :users, force: :cascade do |t|
163
+ t.string :name, null: false
164
+ t.integer :lock_version, null: false, default: 0
165
+ end
166
+
167
+ create_table :user_tokens, force: :cascade do |t|
168
+ t.string :user_name, null: false
169
+ t.string :token, null: false
170
+ end
171
+
172
+ create_table :accounts, force: :cascade do |t|
173
+ t.string :name, null: false
174
+ t.integer :lock, null: false, default: 0
175
+ end
176
+
177
+ create_table :bike_makers, force: :cascade do |t|
178
+ t.string :name, null: false
179
+ t.integer :lock_version, null: false, default: 0
180
+ end
114
181
 
115
- create_table :widgets, :id => false, :force => true do |t|
116
- t.integer :w_id
117
- t.boolean :active, :default => false
118
- t.text :data
182
+ add_index :cars, :Name, unique: true
183
+
184
+ unless ENV["SKIP_COMPOSITE_PK"]
185
+ execute %(
186
+ CREATE TABLE IF NOT EXISTS tags (
187
+ tag_id INT NOT NULL,
188
+ publisher_id INT NOT NULL,
189
+ tag VARCHAR(50),
190
+ PRIMARY KEY (tag_id, publisher_id)
191
+ );
192
+ ).split.join(' ').strip
119
193
  end
120
194
  end
@@ -0,0 +1 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/postgresql_schema')
@@ -0,0 +1,19 @@
1
+ ActiveRecord::Schema.define do
2
+ create_table :books, force: :cascade do |t|
3
+ t.string :title, null: false
4
+ t.virtual :upper_title, type: :string, as: "upper(`title`)" if t.respond_to?(:virtual)
5
+ t.string :publisher, null: false, default: 'Default Publisher'
6
+ t.string :author_name, null: false
7
+ t.datetime :created_at
8
+ t.datetime :created_on
9
+ t.datetime :updated_at
10
+ t.datetime :updated_on
11
+ t.date :publish_date
12
+ t.integer :topic_id
13
+ t.integer :tag_id
14
+ t.integer :publisher_id
15
+ t.boolean :for_sale, default: true
16
+ t.integer :status, default: 0
17
+ t.string :type
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/postgresql_schema')
@@ -0,0 +1,61 @@
1
+ ActiveRecord::Schema.define do
2
+ execute('CREATE extension IF NOT EXISTS "hstore";')
3
+ execute('CREATE extension IF NOT EXISTS "pgcrypto";')
4
+ execute('CREATE extension IF NOT EXISTS "uuid-ossp";')
5
+
6
+ # create ENUM if it does not exist yet
7
+ begin
8
+ execute('CREATE TYPE vendor_type AS ENUM (\'wholesaler\', \'retailer\');')
9
+ rescue ActiveRecord::StatementInvalid => e
10
+ # since PostgreSQL does not support IF NOT EXISTS when creating a TYPE,
11
+ # rescue the error and check the error class
12
+ raise unless e.cause.is_a? PG::DuplicateObject
13
+ execute('ALTER TYPE vendor_type ADD VALUE IF NOT EXISTS \'wholesaler\';')
14
+ execute('ALTER TYPE vendor_type ADD VALUE IF NOT EXISTS \'retailer\';')
15
+ end
16
+
17
+ create_table :vendors, id: :uuid, force: :cascade do |t|
18
+ t.string :name, null: true
19
+ t.text :hours
20
+ t.text :preferences
21
+
22
+ if t.respond_to?(:json)
23
+ t.json :pure_json_data
24
+ t.json :data
25
+ else
26
+ t.text :data
27
+ end
28
+
29
+ if t.respond_to?(:hstore)
30
+ t.hstore :config
31
+ else
32
+ t.text :config
33
+ end
34
+
35
+ if t.respond_to?(:jsonb)
36
+ t.jsonb :pure_jsonb_data
37
+ t.jsonb :settings
38
+ t.jsonb :json_data, null: false, default: {}
39
+ else
40
+ t.text :settings
41
+ t.text :json_data
42
+ end
43
+
44
+ t.column :vendor_type, :vendor_type
45
+
46
+ t.datetime :created_at
47
+ t.datetime :updated_at
48
+ end
49
+
50
+ create_table :alarms, force: true do |t|
51
+ t.column :device_id, :integer, null: false
52
+ t.column :alarm_type, :integer, null: false
53
+ t.column :status, :integer, null: false
54
+ t.column :metadata, :text
55
+ t.column :secret_key, :binary
56
+ t.datetime :created_at
57
+ t.datetime :updated_at
58
+ end
59
+
60
+ add_index :alarms, [:device_id, :alarm_type], unique: true, where: 'status <> 0'
61
+ end
@@ -0,0 +1,13 @@
1
+ ActiveRecord::Schema.define do
2
+ create_table :alarms, force: true do |t|
3
+ t.column :device_id, :integer, null: false
4
+ t.column :alarm_type, :integer, null: false
5
+ t.column :status, :integer, null: false
6
+ t.column :metadata, :text
7
+ t.column :secret_key, :binary
8
+ t.datetime :created_at
9
+ t.datetime :updated_at
10
+ end
11
+
12
+ add_index :alarms, [:device_id, :alarm_type], unique: true, where: 'status <> 0'
13
+ end