rom-sql 2.0.0.beta2 → 2.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +66 -0
  3. data/lib/rom/plugins/relation/sql/postgres/explain.rb +54 -0
  4. data/lib/rom/sql.rb +1 -1
  5. data/lib/rom/sql/attribute.rb +17 -18
  6. data/lib/rom/sql/errors.rb +3 -0
  7. data/lib/rom/sql/extensions/mysql.rb +1 -1
  8. data/lib/rom/sql/extensions/mysql/type_builder.rb +28 -0
  9. data/lib/rom/sql/extensions/postgres.rb +3 -1
  10. data/lib/rom/sql/extensions/postgres/commands.rb +30 -13
  11. data/lib/rom/sql/extensions/postgres/{attributes_inferrer.rb → type_builder.rb} +24 -28
  12. data/lib/rom/sql/extensions/postgres/type_serializer.rb +39 -0
  13. data/lib/rom/sql/extensions/postgres/types.rb +24 -477
  14. data/lib/rom/sql/extensions/postgres/types/array.rb +163 -0
  15. data/lib/rom/sql/extensions/postgres/types/geometric.rb +135 -0
  16. data/lib/rom/sql/extensions/postgres/types/json.rb +235 -0
  17. data/lib/rom/sql/extensions/postgres/types/network.rb +15 -0
  18. data/lib/rom/sql/extensions/sqlite.rb +1 -1
  19. data/lib/rom/sql/extensions/sqlite/{attributes_inferrer.rb → type_builder.rb} +5 -5
  20. data/lib/rom/sql/extensions/sqlite/types.rb +8 -3
  21. data/lib/rom/sql/foreign_key.rb +17 -0
  22. data/lib/rom/sql/function.rb +86 -8
  23. data/lib/rom/sql/gateway.rb +26 -26
  24. data/lib/rom/sql/index.rb +4 -0
  25. data/lib/rom/sql/migration.rb +3 -3
  26. data/lib/rom/sql/migration/inline_runner.rb +9 -83
  27. data/lib/rom/sql/migration/migrator.rb +35 -12
  28. data/lib/rom/sql/migration/recorder.rb +21 -0
  29. data/lib/rom/sql/migration/runner.rb +115 -0
  30. data/lib/rom/sql/migration/schema_diff.rb +108 -53
  31. data/lib/rom/sql/migration/writer.rb +61 -0
  32. data/lib/rom/sql/relation.rb +2 -1
  33. data/lib/rom/sql/relation/reading.rb +63 -3
  34. data/lib/rom/sql/relation/writing.rb +38 -0
  35. data/lib/rom/sql/schema.rb +9 -3
  36. data/lib/rom/sql/schema/attributes_inferrer.rb +3 -119
  37. data/lib/rom/sql/schema/inferrer.rb +99 -18
  38. data/lib/rom/sql/schema/type_builder.rb +94 -0
  39. data/lib/rom/sql/type_dsl.rb +30 -0
  40. data/lib/rom/sql/type_extensions.rb +11 -6
  41. data/lib/rom/sql/type_serializer.rb +46 -0
  42. data/lib/rom/sql/types.rb +12 -0
  43. data/lib/rom/sql/version.rb +1 -1
  44. metadata +26 -244
  45. data/.codeclimate.yml +0 -15
  46. data/.gitignore +0 -17
  47. data/.rspec +0 -3
  48. data/.travis.yml +0 -39
  49. data/.yardopts +0 -2
  50. data/Gemfile +0 -33
  51. data/Guardfile +0 -24
  52. data/LICENSE.txt +0 -22
  53. data/Rakefile +0 -19
  54. data/circle.yml +0 -10
  55. data/lib/rom/sql/extensions/mysql/attributes_inferrer.rb +0 -10
  56. data/lib/rom/sql/relation/sequel_api.rb +0 -133
  57. data/log/.gitkeep +0 -0
  58. data/rom-sql.gemspec +0 -29
  59. data/spec/extensions/postgres/attribute_spec.rb +0 -217
  60. data/spec/extensions/postgres/integration_spec.rb +0 -59
  61. data/spec/extensions/postgres/types_spec.rb +0 -252
  62. data/spec/extensions/sqlite/types_spec.rb +0 -11
  63. data/spec/fixtures/migrations/20150403090603_create_carrots.rb +0 -8
  64. data/spec/integration/associations/many_to_many/custom_fks_spec.rb +0 -76
  65. data/spec/integration/associations/many_to_many/from_view_spec.rb +0 -88
  66. data/spec/integration/associations/many_to_many_spec.rb +0 -162
  67. data/spec/integration/associations/many_to_one/custom_fks_spec.rb +0 -64
  68. data/spec/integration/associations/many_to_one/from_view_spec.rb +0 -84
  69. data/spec/integration/associations/many_to_one/self_ref_spec.rb +0 -53
  70. data/spec/integration/associations/many_to_one_spec.rb +0 -117
  71. data/spec/integration/associations/one_to_many/custom_fks_spec.rb +0 -54
  72. data/spec/integration/associations/one_to_many/from_view_spec.rb +0 -57
  73. data/spec/integration/associations/one_to_many/self_ref_spec.rb +0 -54
  74. data/spec/integration/associations/one_to_many_spec.rb +0 -86
  75. data/spec/integration/associations/one_to_one_spec.rb +0 -69
  76. data/spec/integration/associations/one_to_one_through_spec.rb +0 -92
  77. data/spec/integration/auto_migrations/errors_spec.rb +0 -31
  78. data/spec/integration/auto_migrations/indexes_spec.rb +0 -253
  79. data/spec/integration/auto_migrations/managing_columns_spec.rb +0 -156
  80. data/spec/integration/auto_migrations/postgres/column_types_spec.rb +0 -63
  81. data/spec/integration/combine_with_spec.rb +0 -43
  82. data/spec/integration/commands/create_spec.rb +0 -304
  83. data/spec/integration/commands/delete_spec.rb +0 -84
  84. data/spec/integration/commands/update_spec.rb +0 -90
  85. data/spec/integration/commands/upsert_spec.rb +0 -83
  86. data/spec/integration/gateway_spec.rb +0 -107
  87. data/spec/integration/migration_spec.rb +0 -55
  88. data/spec/integration/plugins/associates/many_to_many_spec.rb +0 -69
  89. data/spec/integration/plugins/associates_spec.rb +0 -250
  90. data/spec/integration/plugins/auto_restrictions_spec.rb +0 -74
  91. data/spec/integration/relation_schema_spec.rb +0 -271
  92. data/spec/integration/schema/call_spec.rb +0 -24
  93. data/spec/integration/schema/inferrer/mysql_spec.rb +0 -45
  94. data/spec/integration/schema/inferrer/postgres_spec.rb +0 -203
  95. data/spec/integration/schema/inferrer/sqlite_spec.rb +0 -37
  96. data/spec/integration/schema/inferrer_spec.rb +0 -390
  97. data/spec/integration/schema/prefix_spec.rb +0 -16
  98. data/spec/integration/schema/qualified_spec.rb +0 -16
  99. data/spec/integration/schema/rename_spec.rb +0 -21
  100. data/spec/integration/schema/view_spec.rb +0 -29
  101. data/spec/integration/sequel_api_spec.rb +0 -36
  102. data/spec/integration/setup_spec.rb +0 -26
  103. data/spec/integration/support/active_support_notifications_spec.rb +0 -24
  104. data/spec/integration/support/rails_log_subscriber_spec.rb +0 -30
  105. data/spec/integration/wrap_spec.rb +0 -91
  106. data/spec/shared/accounts.rb +0 -48
  107. data/spec/shared/database_setup.rb +0 -70
  108. data/spec/shared/notes.rb +0 -23
  109. data/spec/shared/posts.rb +0 -34
  110. data/spec/shared/puppies.rb +0 -15
  111. data/spec/shared/relations.rb +0 -8
  112. data/spec/shared/users.rb +0 -32
  113. data/spec/shared/users_and_tasks.rb +0 -50
  114. data/spec/spec_helper.rb +0 -122
  115. data/spec/support/env_helper.rb +0 -25
  116. data/spec/support/helpers.rb +0 -24
  117. data/spec/support/oracle/create_users.sql +0 -7
  118. data/spec/support/oracle/set_sys_passwords.sql +0 -2
  119. data/spec/support/test_configuration.rb +0 -16
  120. data/spec/unit/attribute_spec.rb +0 -104
  121. data/spec/unit/function_spec.rb +0 -48
  122. data/spec/unit/gateway_spec.rb +0 -70
  123. data/spec/unit/logger_spec.rb +0 -14
  124. data/spec/unit/migration_tasks_spec.rb +0 -111
  125. data/spec/unit/migrator_spec.rb +0 -25
  126. data/spec/unit/order_dsl_spec.rb +0 -43
  127. data/spec/unit/plugin/associates_spec.rb +0 -94
  128. data/spec/unit/plugin/pagination_spec.rb +0 -91
  129. data/spec/unit/plugin/timestamp_spec.rb +0 -117
  130. data/spec/unit/projection_dsl_spec.rb +0 -110
  131. data/spec/unit/relation/assoc_spec.rb +0 -87
  132. data/spec/unit/relation/associations_spec.rb +0 -27
  133. data/spec/unit/relation/avg_spec.rb +0 -11
  134. data/spec/unit/relation/by_pk_spec.rb +0 -62
  135. data/spec/unit/relation/dataset_spec.rb +0 -50
  136. data/spec/unit/relation/distinct_spec.rb +0 -15
  137. data/spec/unit/relation/exclude_spec.rb +0 -11
  138. data/spec/unit/relation/exist_predicate_spec.rb +0 -25
  139. data/spec/unit/relation/exists_spec.rb +0 -18
  140. data/spec/unit/relation/fetch_spec.rb +0 -21
  141. data/spec/unit/relation/group_spec.rb +0 -61
  142. data/spec/unit/relation/having_spec.rb +0 -22
  143. data/spec/unit/relation/inner_join_spec.rb +0 -158
  144. data/spec/unit/relation/inspect_spec.rb +0 -11
  145. data/spec/unit/relation/instrument_spec.rb +0 -45
  146. data/spec/unit/relation/invert_spec.rb +0 -11
  147. data/spec/unit/relation/left_join_spec.rb +0 -55
  148. data/spec/unit/relation/lock_spec.rb +0 -93
  149. data/spec/unit/relation/map_spec.rb +0 -16
  150. data/spec/unit/relation/max_spec.rb +0 -11
  151. data/spec/unit/relation/min_spec.rb +0 -11
  152. data/spec/unit/relation/order_spec.rb +0 -51
  153. data/spec/unit/relation/pluck_spec.rb +0 -11
  154. data/spec/unit/relation/prefix_spec.rb +0 -29
  155. data/spec/unit/relation/primary_key_spec.rb +0 -27
  156. data/spec/unit/relation/project_spec.rb +0 -24
  157. data/spec/unit/relation/qualified_columns_spec.rb +0 -30
  158. data/spec/unit/relation/qualified_spec.rb +0 -25
  159. data/spec/unit/relation/read_spec.rb +0 -25
  160. data/spec/unit/relation/rename_spec.rb +0 -23
  161. data/spec/unit/relation/right_join_spec.rb +0 -57
  162. data/spec/unit/relation/select_append_spec.rb +0 -21
  163. data/spec/unit/relation/select_spec.rb +0 -40
  164. data/spec/unit/relation/sum_spec.rb +0 -11
  165. data/spec/unit/relation/union_spec.rb +0 -19
  166. data/spec/unit/relation/unique_predicate_spec.rb +0 -18
  167. data/spec/unit/relation/where_spec.rb +0 -133
  168. data/spec/unit/restriction_dsl_spec.rb +0 -34
  169. data/spec/unit/schema_spec.rb +0 -25
  170. data/spec/unit/types_spec.rb +0 -65
@@ -1,37 +0,0 @@
1
- RSpec.describe 'ROM::SQL::Schema::SqliteInferrer', :sqlite do
2
- include_context 'database setup'
3
-
4
- before do
5
- inferrable_relations.concat %i(test_inferrence)
6
- end
7
-
8
- before do
9
- conn.create_table :test_inferrence do
10
- tinyint :tiny
11
- int8 :big
12
- bigint :long
13
- column :dummy, nil
14
- boolean :flag, null: false
15
- end
16
- end
17
-
18
- before do
19
- conf.relation(:test_inferrence) do
20
- schema(infer: true)
21
- end
22
- end
23
-
24
- let(:schema) { container.relations[:test_inferrence].schema }
25
- let(:source) { container.relations[:test_inferrence].name }
26
-
27
- it 'can infer attributes for dataset' do
28
- expect(schema.to_h).
29
- to eql(
30
- tiny: ROM::SQL::Types::Int.optional.meta(name: :tiny, source: source),
31
- big: ROM::SQL::Types::Int.optional.meta(name: :big, source: source),
32
- long: ROM::SQL::Types::Int.optional.meta(name: :long, source: source),
33
- dummy: ROM::SQL::Types::SQLite::Object.optional.meta(name: :dummy, source: source),
34
- flag: ROM::SQL::Types::Bool.meta(name: :flag, source: source)
35
- )
36
- end
37
- end
@@ -1,390 +0,0 @@
1
- RSpec.describe 'Schema inference for common datatypes', seeds: false do
2
- include_context 'users and tasks'
3
-
4
- before do
5
- inferrable_relations.concat %i(test_characters test_inferrence test_numeric)
6
- end
7
-
8
- let(:schema) { container.relations[dataset].schema }
9
-
10
- def trunc_ts(time, drop_usec: false)
11
- usec = drop_usec ? 0 : time.to_time.usec.floor
12
- Time.mktime(time.year, time.month, time.day, time.hour, time.min, time.sec, usec)
13
- end
14
-
15
- def index_by_name(indexes, name)
16
- indexes.find { |idx| idx.name == name }
17
- end
18
-
19
- with_adapters do |adapter|
20
- describe 'inferring attributes' do
21
- before do
22
- dataset = self.dataset
23
- conf.relation(dataset) do
24
- schema(dataset, infer: true)
25
- end
26
- end
27
-
28
- context 'for simple table' do
29
- let(:dataset) { :users }
30
- let(:source) { ROM::Relation::Name[dataset] }
31
-
32
- it 'can infer attributes for dataset' do
33
- expect(schema.to_h).
34
- to eql(
35
- id: ROM::SQL::Types::Serial.meta(name: :id, source: source),
36
- name: ROM::SQL::Types::String.meta(name: :name, limit: 255, source: source)
37
- )
38
- end
39
- end
40
-
41
- context 'for a table with FKs' do
42
- let(:dataset) { :tasks }
43
- let(:source) { ROM::Relation::Name[:tasks] }
44
-
45
- it 'can infer attributes for dataset' do |ex|
46
- expect(schema.to_h).
47
- to eql(
48
- id: ROM::SQL::Types::Serial.meta(name: :id, source: source),
49
- title: ROM::SQL::Types::String.meta(limit: 255).optional.meta(name: :title, source: source),
50
- user_id: ROM::SQL::Types::Int.optional.meta(
51
- name: :user_id,
52
- foreign_key: true,
53
- source: source,
54
- target: :users
55
- )
56
- )
57
- end
58
- end
59
-
60
- context 'for complex table' do
61
- before do |example|
62
- ctx = self
63
-
64
- conn.create_table :test_inferrence do
65
- primary_key :id
66
- String :text, text: false, null: false
67
- Time :time
68
- Date :date
69
-
70
- if ctx.oracle?(example)
71
- Date :datetime, null: false
72
- else
73
- DateTime :datetime, null: false
74
- end
75
-
76
- if ctx.sqlite?(example)
77
- add_constraint(:test_constraint) { char_length(text) > 3 }
78
- end
79
-
80
- if ctx.postgres?(example)
81
- Bytea :data
82
- else
83
- Blob :data
84
- end
85
- end
86
- end
87
-
88
- let(:dataset) { :test_inferrence }
89
- let(:source) { ROM::Relation::Name[dataset] }
90
-
91
- it 'can infer attributes for dataset' do |ex|
92
- date_type = oracle?(ex) ? ROM::SQL::Types::Time : ROM::SQL::Types::Date
93
-
94
- expect(schema.to_h).
95
- to eql(
96
- id: ROM::SQL::Types::Serial.meta(name: :id, source: source),
97
- text: ROM::SQL::Types::String.meta(name: :text, limit: 255, source: source),
98
- time: ROM::SQL::Types::Time.optional.meta(name: :time, source: source),
99
- date: date_type.optional.meta(name: :date, source: source),
100
- datetime: ROM::SQL::Types::Time.meta(name: :datetime, source: source),
101
- data: ROM::SQL::Types::Blob.optional.meta(name: :data, source: source),
102
- )
103
- end
104
- end
105
-
106
- context 'character datatypes' do
107
- before do
108
- conn.create_table :test_characters do
109
- String :text1, text: false, null: false
110
- String :text2, size: 100, null: false
111
- column :text3, 'char(100)', null: false
112
- column :text4, 'varchar', null: false
113
- column :text5, 'varchar(100)', null: false
114
- String :text6, size: 100
115
- end
116
- end
117
-
118
- let(:dataset) { :test_characters }
119
- let(:source) { ROM::Relation::Name[dataset] }
120
-
121
- let(:char_t) { ROM::SQL::Types::String.meta(source: source) }
122
-
123
- it 'infers attributes with limit' do
124
- expect(schema.to_h).to eql(
125
- text1: char_t.meta(name: :text1, limit: 255),
126
- text2: char_t.meta(name: :text2, limit: 100),
127
- text3: char_t.meta(name: :text3, limit: 100),
128
- text4: char_t.meta(name: :text4, limit: 255),
129
- text5: char_t.meta(name: :text5, limit: 100),
130
- text6: ROM::SQL::Types::String.meta(limit: 100).optional.meta(
131
- name: :text6, source: source
132
- )
133
- )
134
- end
135
- end
136
-
137
- context 'numeric datatypes' do
138
- before do
139
- conn.create_table :test_numeric do
140
- primary_key :id
141
- decimal :dec, null: false
142
- decimal :dec_prec, size: 12, null: false
143
- numeric :num, size: [5, 2], null: false
144
- smallint :small
145
- integer :int
146
- float :floating
147
- double :double_p
148
- end
149
- end
150
-
151
- let(:dataset) { :test_numeric }
152
- let(:source) { ROM::Relation::Name[dataset] }
153
-
154
- let(:integer) { ROM::SQL::Types::Int.meta(source: source) }
155
- let(:decimal) { ROM::SQL::Types::Decimal.meta(source: source) }
156
-
157
- it 'infers attributes with precision' do |example|
158
- if mysql?(example)
159
- default_precision = decimal.meta(name: :dec, precision: 10, scale: 0)
160
- elsif oracle?(example)
161
- # Oracle treats DECIMAL as NUMBER(38, 0)
162
- default_precision = integer.meta(name: :dec)
163
- else
164
- default_precision = decimal.meta(name: :dec)
165
- end
166
-
167
- pending 'Add precision inferrence for Oracle' if oracle?(example)
168
-
169
- expect(schema.to_h).
170
- to eql(
171
- id: ROM::SQL::Types::Serial.meta(name: :id, source: source),
172
- dec: default_precision,
173
- dec_prec: decimal.meta(name: :dec_prec, precision: 12, scale: 0),
174
- num: decimal.meta(name: :num, precision: 5, scale: 2),
175
- small: ROM::SQL::Types::Int.optional.meta(name: :small, source: source),
176
- int: ROM::SQL::Types::Int.optional.meta(name: :int, source: source),
177
- floating: ROM::SQL::Types::Float.optional.meta(name: :floating, source: source),
178
- double_p: ROM::SQL::Types::Float.optional.meta(name: :double_p, source: source),
179
- )
180
- end
181
- end
182
- end
183
-
184
- describe 'using commands with inferred schema' do
185
- before do
186
- inferrable_relations.concat %i(people)
187
- end
188
-
189
- let(:relation) { container.relations[:people] }
190
-
191
- before do
192
- conf.relation(:people) do
193
- schema(infer: true)
194
- end
195
-
196
- conf.commands(:people) do
197
- define(:create) do
198
- result :one
199
- end
200
- end
201
- end
202
-
203
- describe 'inserting' do
204
- let(:create) { commands[:people].create }
205
-
206
- context "Sequel's types" do
207
- before do
208
- conn.create_table :people do
209
- primary_key :id
210
- String :name, null: false
211
- end
212
- end
213
-
214
- it "doesn't coerce or check types on insert by default" do
215
- result = create.call(name: Sequel.function(:upper, 'Jade'))
216
-
217
- expect(result).to eql(id: 1, name: 'JADE')
218
- end
219
- end
220
-
221
- context 'nullable columns' do
222
- before do
223
- conn.create_table :people do
224
- primary_key :id
225
- String :name, null: false
226
- Integer :age, null: true
227
- end
228
- end
229
-
230
- it 'allows to insert records with nil value' do
231
- result = create.call(name: 'Jade', age: nil)
232
-
233
- expect(result).to eql(id: 1, name: 'Jade', age: nil)
234
- end
235
-
236
- it 'allows to omit nullable columns' do
237
- result = create.call(name: 'Jade')
238
-
239
- expect(result).to eql(id: 1, name: 'Jade', age: nil)
240
- end
241
- end
242
-
243
- context 'columns with default value' do
244
- before do
245
- conn.create_table :people do
246
- primary_key :id
247
- String :name, null: false
248
- Integer :age, null: false, default: 18
249
- end
250
- end
251
-
252
- it 'sets default value on missing key' do
253
- result = create.call(name: 'Jade')
254
-
255
- expect(result).to eql(id: 1, name: 'Jade', age: 18)
256
- end
257
-
258
- it 'raises an error on inserting nil value' do
259
- expect { create.call(name: 'Jade', age: nil) }.to raise_error(ROM::SQL::NotNullConstraintError)
260
- end
261
- end
262
-
263
- context 'coercions' do
264
- context 'date' do
265
- before do
266
- conn.create_table :people do
267
- primary_key :id
268
- String :name, null: false
269
- Date :birth_date, null: false
270
- end
271
- end
272
-
273
- it 'accetps Time' do |ex|
274
- time = Time.iso8601('1970-01-01T06:00:00')
275
- result = create.call(name: 'Jade', birth_date: time)
276
- # Oracle's Date type stores time
277
- expected_date = oracle?(ex) ? time : Date.iso8601('1970-01-01T00:00:00')
278
-
279
- expect(result).to eql(id: 1, name: 'Jade', birth_date: expected_date)
280
- end
281
- end
282
-
283
- unless metadata[:sqlite] && defined? JRUBY_VERSION
284
- context 'timestamp' do
285
- before do |ex|
286
- ctx = self
287
-
288
- conn.create_table :people do
289
- primary_key :id
290
- String :name, null: false
291
- # TODO: fix ROM, then Sequel to infer TIMESTAMP NOT NULL for Oracle
292
- Timestamp :created_at, null: ctx.oracle?(ex)
293
- end
294
- end
295
-
296
- it 'accepts Date' do
297
- date = Date.today
298
- result = create.call(name: 'Jade', created_at: date)
299
-
300
- expect(result).to eql(id: 1, name: 'Jade', created_at: date.to_time)
301
- end
302
-
303
- it 'accepts Time' do |ex|
304
- now = Time.now
305
- result = create.call(name: 'Jade', created_at: now)
306
-
307
- expected_time = trunc_ts(now, drop_usec: mysql?(ex))
308
- expect(result).to eql(id: 1, name: 'Jade', created_at: expected_time)
309
- end
310
-
311
- it 'accepts DateTime' do |ex|
312
- now = DateTime.now
313
- result = create.call(name: 'Jade', created_at: now)
314
-
315
- expected_time = trunc_ts(now, drop_usec: mysql?(ex))
316
- expect(result).to eql(id: 1, name: 'Jade', created_at: expected_time)
317
- end
318
-
319
- # TODO: Find out if Oracle's adapter really doesn't support RFCs
320
- if !metadata[:mysql] && !metadata[:oracle]
321
- it 'accepts strings in RFC 2822' do
322
- now = Time.now
323
- result = create.call(name: 'Jade', created_at: now.rfc822)
324
-
325
- expect(result).to eql(id: 1, name: 'Jade', created_at: trunc_ts(now, drop_usec: true))
326
- end
327
-
328
- it 'accepts strings in RFC 3339' do
329
- now = DateTime.now
330
- result = create.call(name: 'Jade', created_at: now.rfc3339)
331
-
332
- expect(result).to eql(id: 1, name: 'Jade', created_at: trunc_ts(now, drop_usec: true))
333
- end
334
- end
335
- end
336
- end
337
- end
338
- end
339
- end
340
-
341
- describe 'inferring indices', oracle: false do
342
- let(:dataset) { :test_inferrence }
343
- let(:source) { ROM::Relation::Name[dataset] }
344
-
345
- it 'infers types with indices' do
346
- conn.create_table :test_inferrence do
347
- primary_key :id
348
- Integer :foo
349
- Integer :bar, null: false
350
- Integer :baz, null: false
351
-
352
- index :foo, name: :foo_idx
353
- index :bar, name: :bar_idx
354
- index :baz, name: :baz1_idx
355
- index :baz, name: :baz2_idx
356
-
357
- index %i(bar baz), name: :composite_idx
358
- index %i(foo bar), name: :unique_idx, unique: true
359
- end
360
-
361
- conf.relation(:test_inferrence) { schema(infer: true) }
362
-
363
- expect(schema.indexes.map(&:name)).
364
- to match_array(%i(foo_idx bar_idx baz1_idx baz2_idx composite_idx unique_idx))
365
-
366
- unique_idx = index_by_name(schema.indexes, :unique_idx)
367
-
368
- expect(unique_idx).to be_unique
369
- end
370
-
371
- if metadata[:postgres]
372
- it 'infers cutsom index types' do
373
- pending 'Sequel not returning index type'
374
- conn.create_table :test_inferrence do
375
- primary_key :id
376
- Integer :foo
377
- index :foo, name: :foo_idx, type: :gist
378
- end
379
-
380
- conf.relation(:test_inferrence) { schema(infer: true) }
381
-
382
- index = schema.indexes.first
383
-
384
- expect(index.name).to eql(:foo_idx)
385
- expect(index.type).to eql(:gist)
386
- end
387
- end
388
- end
389
- end
390
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ROM::SQL::Schema, '#prefix', :postgres, seeds: false do
4
- include_context 'users'
5
-
6
- before do
7
- conf.relation(:users) do
8
- schema(infer: true)
9
- end
10
- end
11
-
12
- it 'auto-projects a relation with renamed columns using provided prefix' do
13
- expect(relations[:users].schema.prefix(:user).(relations[:users]).dataset.sql)
14
- .to eql('SELECT "id" AS "user_id", "name" AS "user_name" FROM "users" ORDER BY "users"."id"')
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ROM::SQL::Schema, '#qualified', :postgres, seeds: false do
4
- include_context 'users'
5
-
6
- before do
7
- conf.relation(:users) do
8
- schema(infer: true)
9
- end
10
- end
11
-
12
- it 'qualifies column names' do
13
- expect(relations[:users].schema.qualified.(relations[:users]).dataset.sql)
14
- .to eql('SELECT "users"."id", "users"."name" FROM "users" ORDER BY "users"."id"')
15
- end
16
- end