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.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rubocop.yml +49 -0
- data/.rubocop_todo.yml +36 -0
- data/.travis.yml +64 -8
- data/CHANGELOG.md +475 -0
- data/Gemfile +32 -15
- data/LICENSE +21 -56
- data/README.markdown +564 -35
- data/Rakefile +20 -3
- data/activerecord-import.gemspec +7 -7
- data/benchmarks/README +2 -2
- data/benchmarks/benchmark.rb +68 -64
- data/benchmarks/lib/base.rb +138 -137
- data/benchmarks/lib/cli_parser.rb +107 -103
- data/benchmarks/lib/{mysql_benchmark.rb → mysql2_benchmark.rb} +19 -22
- data/benchmarks/lib/output_to_csv.rb +5 -4
- data/benchmarks/lib/output_to_html.rb +8 -13
- data/benchmarks/models/test_innodb.rb +1 -1
- data/benchmarks/models/test_memory.rb +1 -1
- data/benchmarks/models/test_myisam.rb +1 -1
- data/benchmarks/schema/mysql2_schema.rb +16 -0
- data/gemfiles/3.2.gemfile +2 -4
- data/gemfiles/4.0.gemfile +2 -4
- data/gemfiles/4.1.gemfile +2 -4
- data/gemfiles/4.2.gemfile +2 -4
- 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 +2 -0
- data/gemfiles/6.1.gemfile +1 -0
- data/lib/activerecord-import/active_record/adapters/jdbcsqlite3_adapter.rb +6 -0
- data/lib/activerecord-import/active_record/adapters/sqlite3_adapter.rb +0 -1
- data/lib/activerecord-import/adapters/abstract_adapter.rb +23 -17
- data/lib/activerecord-import/adapters/mysql_adapter.rb +52 -25
- data/lib/activerecord-import/adapters/postgresql_adapter.rb +187 -10
- data/lib/activerecord-import/adapters/sqlite3_adapter.rb +148 -17
- data/lib/activerecord-import/base.rb +15 -9
- data/lib/activerecord-import/import.rb +740 -191
- data/lib/activerecord-import/synchronize.rb +21 -21
- data/lib/activerecord-import/value_sets_parser.rb +33 -8
- data/lib/activerecord-import/version.rb +1 -1
- data/lib/activerecord-import.rb +4 -15
- data/test/adapters/jdbcsqlite3.rb +1 -0
- data/test/adapters/makara_postgis.rb +1 -0
- data/test/adapters/mysql2_makara.rb +1 -0
- data/test/adapters/mysql2spatial.rb +1 -1
- data/test/adapters/postgis.rb +1 -1
- data/test/adapters/postgresql.rb +1 -1
- data/test/adapters/postgresql_makara.rb +1 -0
- data/test/adapters/spatialite.rb +1 -1
- data/test/adapters/sqlite3.rb +1 -1
- data/test/database.yml.sample +13 -18
- data/test/import_test.rb +608 -89
- data/test/jdbcmysql/import_test.rb +2 -3
- data/test/jdbcpostgresql/import_test.rb +0 -2
- data/test/jdbcsqlite3/import_test.rb +4 -0
- data/test/makara_postgis/import_test.rb +8 -0
- data/test/models/account.rb +3 -0
- data/test/models/alarm.rb +2 -0
- data/test/models/animal.rb +6 -0
- data/test/models/bike_maker.rb +7 -0
- data/test/models/book.rb +7 -6
- data/test/models/car.rb +3 -0
- data/test/models/chapter.rb +2 -2
- data/test/models/dictionary.rb +4 -0
- data/test/models/discount.rb +3 -0
- data/test/models/end_note.rb +2 -2
- data/test/models/promotion.rb +3 -0
- data/test/models/question.rb +3 -0
- data/test/models/rule.rb +3 -0
- data/test/models/tag.rb +4 -0
- data/test/models/topic.rb +17 -3
- data/test/models/user.rb +3 -0
- data/test/models/user_token.rb +4 -0
- data/test/models/vendor.rb +7 -0
- data/test/models/widget.rb +19 -2
- data/test/mysql2/import_test.rb +2 -3
- data/test/{em_mysql2 → mysql2_makara}/import_test.rb +1 -1
- data/test/mysqlspatial2/import_test.rb +2 -2
- data/test/postgis/import_test.rb +5 -1
- data/test/schema/generic_schema.rb +159 -85
- data/test/schema/jdbcpostgresql_schema.rb +1 -0
- data/test/schema/mysql2_schema.rb +19 -0
- data/test/schema/postgis_schema.rb +1 -0
- data/test/schema/postgresql_schema.rb +61 -0
- data/test/schema/sqlite3_schema.rb +13 -0
- data/test/sqlite3/import_test.rb +2 -50
- data/test/support/active_support/test_case_extensions.rb +21 -13
- data/test/support/{mysql/assertions.rb → assertions.rb} +20 -2
- data/test/support/factories.rb +39 -14
- data/test/support/generate.rb +10 -10
- data/test/support/mysql/import_examples.rb +49 -98
- data/test/support/postgresql/import_examples.rb +535 -57
- data/test/support/shared_examples/on_duplicate_key_ignore.rb +43 -0
- data/test/support/shared_examples/on_duplicate_key_update.rb +378 -0
- data/test/support/shared_examples/recursive_import.rb +225 -0
- data/test/support/sqlite3/import_examples.rb +231 -0
- data/test/synchronize_test.rb +10 -2
- data/test/test_helper.rb +36 -8
- data/test/travis/database.yml +26 -17
- data/test/value_sets_bytes_parser_test.rb +25 -17
- data/test/value_sets_records_parser_test.rb +6 -6
- metadata +86 -42
- data/benchmarks/boot.rb +0 -18
- data/benchmarks/schema/mysql_schema.rb +0 -16
- data/gemfiles/3.1.gemfile +0 -4
- data/lib/activerecord-import/active_record/adapters/em_mysql2_adapter.rb +0 -8
- data/lib/activerecord-import/active_record/adapters/mysql_adapter.rb +0 -6
- data/lib/activerecord-import/em_mysql2.rb +0 -7
- data/lib/activerecord-import/mysql.rb +0 -7
- data/test/adapters/em_mysql2.rb +0 -1
- data/test/adapters/mysql.rb +0 -1
- data/test/adapters/mysqlspatial.rb +0 -1
- data/test/mysql/import_test.rb +0 -6
- data/test/mysqlspatial/import_test.rb +0 -6
- data/test/schema/mysql_schema.rb +0 -18
- 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,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
|
data/test/models/book.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
class Book < ActiveRecord::Base
|
2
|
-
belongs_to :topic, :
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
data/test/models/car.rb
ADDED
data/test/models/chapter.rb
CHANGED
data/test/models/end_note.rb
CHANGED
data/test/models/rule.rb
ADDED
data/test/models/tag.rb
ADDED
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
|
-
|
6
|
-
|
8
|
+
validate -> { errors.add(:title, :validate_failed) if title == 'validate_failed' }
|
9
|
+
before_validation -> { errors.add(:title, :invalid) if title == 'invalid' }
|
7
10
|
|
8
|
-
|
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
|
data/test/models/user.rb
ADDED
data/test/models/widget.rb
CHANGED
@@ -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
|
18
|
+
default_scope -> { where(active: true) }
|
5
19
|
|
6
20
|
serialize :data, Hash
|
7
|
-
|
21
|
+
serialize :json_data, JSON
|
22
|
+
serialize :unspecified_data
|
23
|
+
serialize :custom_data, CustomCoder.new
|
24
|
+
end
|
data/test/mysql2/import_test.rb
CHANGED
@@ -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/
|
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/
|
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
|
data/test/postgis/import_test.rb
CHANGED
@@ -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 :
|
4
|
-
t.
|
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 :
|
9
|
-
t.
|
10
|
-
t.
|
30
|
+
create_table :projects, force: :cascade do |t|
|
31
|
+
t.string :name
|
32
|
+
t.string :type
|
11
33
|
end
|
12
34
|
|
13
|
-
create_table :
|
14
|
-
t.
|
15
|
-
t.
|
16
|
-
t.
|
17
|
-
t.
|
18
|
-
t.
|
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 :
|
32
|
-
t.
|
33
|
-
t.
|
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 :
|
37
|
-
t.
|
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 :
|
45
|
-
t.
|
46
|
-
t.
|
47
|
-
t.
|
48
|
-
t.
|
49
|
-
t.
|
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 :
|
53
|
-
t.
|
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 :
|
57
|
-
t.
|
58
|
-
t.
|
59
|
-
t.
|
60
|
-
t.
|
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 :
|
71
|
-
t.
|
72
|
-
t.
|
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 :
|
78
|
-
t.
|
79
|
-
t.
|
80
|
-
t.
|
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 :
|
86
|
-
t.
|
87
|
-
t.
|
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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
t.
|
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 :
|
97
|
-
t.
|
98
|
-
t.
|
99
|
-
t.
|
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 :
|
131
|
+
add_index :promotions, [:code], unique: true, name: 'uk_code'
|
105
132
|
|
106
|
-
create_table :
|
107
|
-
t.
|
108
|
-
t.
|
109
|
-
t.
|
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
|
-
|
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
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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
|