activerecord-oracle_enhanced-adapter 1.7.3 → 1.8.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/History.md +288 -0
- data/README.md +44 -0
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +7 -63
- data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +6 -52
- data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +13 -16
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +117 -119
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +33 -27
- data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +10 -10
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +59 -77
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +0 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +56 -82
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +4 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +77 -77
- data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +16 -45
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +60 -65
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +33 -51
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +149 -162
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +119 -122
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +3 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +69 -107
- data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +315 -538
- data/lib/active_record/oracle_enhanced/type/boolean.rb +7 -11
- data/lib/active_record/oracle_enhanced/type/integer.rb +4 -5
- data/lib/active_record/oracle_enhanced/type/json.rb +8 -0
- data/lib/active_record/oracle_enhanced/type/national_character_string.rb +1 -2
- data/lib/active_record/oracle_enhanced/type/raw.rb +2 -4
- data/lib/active_record/oracle_enhanced/type/string.rb +2 -3
- data/lib/active_record/oracle_enhanced/type/text.rb +2 -4
- data/lib/active_record/oracle_enhanced/type/timestamptz.rb +23 -0
- data/lib/activerecord-oracle_enhanced-adapter.rb +14 -13
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +129 -166
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +50 -33
- data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +44 -42
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +283 -378
- data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +14 -7
- data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +5 -7
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +118 -127
- data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +2 -3
- data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +74 -78
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +68 -83
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +308 -321
- data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +103 -48
- data/spec/spec_config.yaml.template +11 -0
- data/spec/spec_helper.rb +59 -60
- data/spec/support/alter_system_user_password.sql +2 -0
- data/spec/support/create_oracle_enhanced_users.sql +31 -0
- metadata +25 -25
- data/.rspec +0 -2
- data/Gemfile +0 -22
- data/RUNNING_TESTS.md +0 -50
- data/Rakefile +0 -45
- data/activerecord-oracle_enhanced-adapter.gemspec +0 -95
- data/lib/active_record/connection_adapters/oracle_enhanced/cpk.rb +0 -21
- data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +0 -113
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
require
|
|
2
|
-
|
|
3
|
-
require 'ruby-plsql'
|
|
1
|
+
require "ruby-plsql"
|
|
4
2
|
|
|
5
3
|
describe "OracleEnhancedAdapter custom methods for create, update and destroy" do
|
|
6
4
|
include LoggerSpecHelper
|
|
7
|
-
|
|
5
|
+
|
|
8
6
|
before(:all) do
|
|
9
7
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
|
10
8
|
@conn = ActiveRecord::Base.connection
|
|
@@ -67,7 +65,7 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
|
67
65
|
VALUES (p_employee_id, p_first_name, p_last_name, p_hire_date, p_salary, p_description,
|
|
68
66
|
1, SYSDATE, SYSDATE);
|
|
69
67
|
END create_employee;
|
|
70
|
-
|
|
68
|
+
|
|
71
69
|
PROCEDURE update_employee(
|
|
72
70
|
p_employee_id NUMBER,
|
|
73
71
|
p_first_name VARCHAR2,
|
|
@@ -85,7 +83,7 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
|
85
83
|
version = v_version + 1, update_time = SYSDATE
|
|
86
84
|
WHERE employee_id = p_employee_id;
|
|
87
85
|
END update_employee;
|
|
88
|
-
|
|
86
|
+
|
|
89
87
|
PROCEDURE delete_employee(
|
|
90
88
|
p_employee_id NUMBER)
|
|
91
89
|
IS
|
|
@@ -95,7 +93,6 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
|
95
93
|
END;
|
|
96
94
|
SQL
|
|
97
95
|
|
|
98
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
|
99
96
|
end
|
|
100
97
|
|
|
101
98
|
after(:all) do
|
|
@@ -111,59 +108,59 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
|
111
108
|
self.primary_key = :employee_id
|
|
112
109
|
|
|
113
110
|
validates_presence_of :first_name, :last_name, :hire_date
|
|
114
|
-
|
|
111
|
+
|
|
115
112
|
# should return ID of new record
|
|
116
113
|
set_create_method do
|
|
117
114
|
plsql.test_employees_pkg.create_employee(
|
|
118
|
-
:
|
|
119
|
-
:
|
|
120
|
-
:
|
|
121
|
-
:
|
|
122
|
-
:
|
|
123
|
-
:
|
|
115
|
+
p_first_name: first_name,
|
|
116
|
+
p_last_name: last_name,
|
|
117
|
+
p_hire_date: hire_date,
|
|
118
|
+
p_salary: salary,
|
|
119
|
+
p_description: "#{first_name} #{last_name}",
|
|
120
|
+
p_employee_id: nil
|
|
124
121
|
)[:p_employee_id]
|
|
125
122
|
end
|
|
126
123
|
|
|
127
124
|
# return value is ignored
|
|
128
125
|
set_update_method do
|
|
129
126
|
plsql.test_employees_pkg.update_employee(
|
|
130
|
-
:
|
|
131
|
-
:
|
|
132
|
-
:
|
|
133
|
-
:
|
|
134
|
-
:
|
|
135
|
-
:
|
|
127
|
+
p_employee_id: id,
|
|
128
|
+
p_first_name: first_name,
|
|
129
|
+
p_last_name: last_name,
|
|
130
|
+
p_hire_date: hire_date,
|
|
131
|
+
p_salary: salary,
|
|
132
|
+
p_description: "#{first_name} #{last_name}"
|
|
136
133
|
)
|
|
137
134
|
end
|
|
138
135
|
|
|
139
136
|
# return value is ignored
|
|
140
137
|
set_delete_method do
|
|
141
138
|
plsql.test_employees_pkg.delete_employee(
|
|
142
|
-
:
|
|
139
|
+
p_employee_id: id
|
|
143
140
|
)
|
|
144
141
|
end
|
|
145
142
|
|
|
146
143
|
private
|
|
147
144
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
def raise_make_transaction_rollback
|
|
146
|
+
raise "Make the transaction rollback"
|
|
147
|
+
end
|
|
151
148
|
end
|
|
152
149
|
|
|
153
|
-
@today = Date.new(2008,6,28)
|
|
150
|
+
@today = Date.new(2008, 6, 28)
|
|
154
151
|
@buffer = StringIO.new
|
|
155
152
|
end
|
|
156
153
|
|
|
157
154
|
after(:each) do
|
|
158
155
|
Object.send(:remove_const, "TestEmployee")
|
|
159
|
-
ActiveRecord::Base.clear_cache!
|
|
156
|
+
ActiveRecord::Base.clear_cache!
|
|
160
157
|
end
|
|
161
158
|
|
|
162
159
|
it "should create record" do
|
|
163
160
|
@employee = TestEmployee.create(
|
|
164
|
-
:
|
|
165
|
-
:
|
|
166
|
-
:
|
|
161
|
+
first_name: "First",
|
|
162
|
+
last_name: "Last",
|
|
163
|
+
hire_date: @today
|
|
167
164
|
)
|
|
168
165
|
@employee.reload
|
|
169
166
|
expect(@employee.first_name).to eq("First")
|
|
@@ -178,24 +175,24 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
|
178
175
|
TestEmployee.after_create :raise_make_transaction_rollback
|
|
179
176
|
|
|
180
177
|
@employee = TestEmployee.new(
|
|
181
|
-
:
|
|
182
|
-
:
|
|
183
|
-
:
|
|
178
|
+
first_name: "First",
|
|
179
|
+
last_name: "Last",
|
|
180
|
+
hire_date: @today
|
|
184
181
|
)
|
|
185
182
|
employees_count = TestEmployee.count
|
|
186
183
|
expect {
|
|
187
184
|
@employee.save
|
|
188
185
|
}.to raise_error("Make the transaction rollback")
|
|
189
|
-
expect(@employee.
|
|
186
|
+
expect(@employee.new_record?).to be_truthy
|
|
190
187
|
expect(TestEmployee.count).to eq(employees_count)
|
|
191
188
|
end
|
|
192
189
|
|
|
193
190
|
it "should update record" do
|
|
194
191
|
@employee = TestEmployee.create(
|
|
195
|
-
:
|
|
196
|
-
:
|
|
197
|
-
:
|
|
198
|
-
:
|
|
192
|
+
first_name: "First",
|
|
193
|
+
last_name: "Last",
|
|
194
|
+
hire_date: @today,
|
|
195
|
+
description: "description"
|
|
199
196
|
)
|
|
200
197
|
@employee.reload
|
|
201
198
|
@employee.first_name = "Second"
|
|
@@ -208,12 +205,11 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
|
208
205
|
TestEmployee.after_update :raise_make_transaction_rollback
|
|
209
206
|
|
|
210
207
|
@employee = TestEmployee.create(
|
|
211
|
-
:
|
|
212
|
-
:
|
|
213
|
-
:
|
|
214
|
-
:
|
|
208
|
+
first_name: "First",
|
|
209
|
+
last_name: "Last",
|
|
210
|
+
hire_date: @today,
|
|
211
|
+
description: "description"
|
|
215
212
|
)
|
|
216
|
-
empl_id = @employee.id
|
|
217
213
|
@employee.reload
|
|
218
214
|
@employee.first_name = "Second"
|
|
219
215
|
expect {
|
|
@@ -226,9 +222,9 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
|
226
222
|
it "should not update record if nothing is changed and partial writes are enabled" do
|
|
227
223
|
TestEmployee.partial_writes = true
|
|
228
224
|
@employee = TestEmployee.create(
|
|
229
|
-
:
|
|
230
|
-
:
|
|
231
|
-
:
|
|
225
|
+
first_name: "First",
|
|
226
|
+
last_name: "Last",
|
|
227
|
+
hire_date: @today
|
|
232
228
|
)
|
|
233
229
|
@employee.reload
|
|
234
230
|
@employee.save!
|
|
@@ -239,9 +235,9 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
|
239
235
|
it "should update record if nothing is changed and partial writes are disabled" do
|
|
240
236
|
TestEmployee.partial_writes = false
|
|
241
237
|
@employee = TestEmployee.create(
|
|
242
|
-
:
|
|
243
|
-
:
|
|
244
|
-
:
|
|
238
|
+
first_name: "First",
|
|
239
|
+
last_name: "Last",
|
|
240
|
+
hire_date: @today
|
|
245
241
|
)
|
|
246
242
|
@employee.reload
|
|
247
243
|
@employee.save!
|
|
@@ -251,9 +247,9 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
|
251
247
|
|
|
252
248
|
it "should delete record" do
|
|
253
249
|
@employee = TestEmployee.create(
|
|
254
|
-
:
|
|
255
|
-
:
|
|
256
|
-
:
|
|
250
|
+
first_name: "First",
|
|
251
|
+
last_name: "Last",
|
|
252
|
+
hire_date: @today
|
|
257
253
|
)
|
|
258
254
|
@employee.reload
|
|
259
255
|
empl_id = @employee.id
|
|
@@ -264,9 +260,9 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
|
264
260
|
|
|
265
261
|
it "should delete record and set destroyed flag" do
|
|
266
262
|
@employee = TestEmployee.create(
|
|
267
|
-
:
|
|
268
|
-
:
|
|
269
|
-
:
|
|
263
|
+
first_name: "First",
|
|
264
|
+
last_name: "Last",
|
|
265
|
+
hire_date: @today
|
|
270
266
|
)
|
|
271
267
|
@employee.reload
|
|
272
268
|
@employee.destroy
|
|
@@ -278,9 +274,9 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
|
278
274
|
TestEmployee.after_destroy :raise_make_transaction_rollback
|
|
279
275
|
|
|
280
276
|
@employee = TestEmployee.create(
|
|
281
|
-
:
|
|
282
|
-
:
|
|
283
|
-
:
|
|
277
|
+
first_name: "First",
|
|
278
|
+
last_name: "Last",
|
|
279
|
+
hire_date: @today
|
|
284
280
|
)
|
|
285
281
|
@employee.reload
|
|
286
282
|
empl_id = @employee.id
|
|
@@ -294,9 +290,9 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
|
294
290
|
|
|
295
291
|
it "should set timestamps when creating record" do
|
|
296
292
|
@employee = TestEmployee.create(
|
|
297
|
-
:
|
|
298
|
-
:
|
|
299
|
-
:
|
|
293
|
+
first_name: "First",
|
|
294
|
+
last_name: "Last",
|
|
295
|
+
hire_date: @today
|
|
300
296
|
)
|
|
301
297
|
expect(@employee.created_at).not_to be_nil
|
|
302
298
|
expect(@employee.updated_at).not_to be_nil
|
|
@@ -304,9 +300,9 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
|
304
300
|
|
|
305
301
|
it "should set timestamps when updating record" do
|
|
306
302
|
@employee = TestEmployee.create(
|
|
307
|
-
:
|
|
308
|
-
:
|
|
309
|
-
:
|
|
303
|
+
first_name: "First",
|
|
304
|
+
last_name: "Last",
|
|
305
|
+
hire_date: @today
|
|
310
306
|
)
|
|
311
307
|
@employee.reload
|
|
312
308
|
expect(@employee.created_at).to be_nil
|
|
@@ -320,9 +316,9 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
|
320
316
|
it "should log create record" do
|
|
321
317
|
set_logger
|
|
322
318
|
@employee = TestEmployee.create(
|
|
323
|
-
:
|
|
324
|
-
:
|
|
325
|
-
:
|
|
319
|
+
first_name: "First",
|
|
320
|
+
last_name: "Last",
|
|
321
|
+
hire_date: @today
|
|
326
322
|
)
|
|
327
323
|
expect(@logger.logged(:debug).last).to match(/^TestEmployee Create \(\d+\.\d+(ms)?\) custom create method$/)
|
|
328
324
|
clear_logger
|
|
@@ -331,9 +327,9 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
|
331
327
|
it "should log update record" do
|
|
332
328
|
(TestEmployee.partial_writes = false) rescue nil
|
|
333
329
|
@employee = TestEmployee.create(
|
|
334
|
-
:
|
|
335
|
-
:
|
|
336
|
-
:
|
|
330
|
+
first_name: "First",
|
|
331
|
+
last_name: "Last",
|
|
332
|
+
hire_date: @today
|
|
337
333
|
)
|
|
338
334
|
set_logger
|
|
339
335
|
@employee.save!
|
|
@@ -343,9 +339,9 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
|
343
339
|
|
|
344
340
|
it "should log delete record" do
|
|
345
341
|
@employee = TestEmployee.create(
|
|
346
|
-
:
|
|
347
|
-
:
|
|
348
|
-
:
|
|
342
|
+
first_name: "First",
|
|
343
|
+
last_name: "Last",
|
|
344
|
+
hire_date: @today
|
|
349
345
|
)
|
|
350
346
|
set_logger
|
|
351
347
|
@employee.destroy
|
|
@@ -355,8 +351,8 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
|
355
351
|
|
|
356
352
|
it "should validate new record before creation" do
|
|
357
353
|
@employee = TestEmployee.new(
|
|
358
|
-
:
|
|
359
|
-
:
|
|
354
|
+
last_name: "Last",
|
|
355
|
+
hire_date: @today
|
|
360
356
|
)
|
|
361
357
|
expect(@employee.save).to be_falsey
|
|
362
358
|
expect(@employee.errors[:first_name]).not_to be_blank
|
|
@@ -364,13 +360,13 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
|
364
360
|
|
|
365
361
|
it "should validate existing record before update" do
|
|
366
362
|
@employee = TestEmployee.create(
|
|
367
|
-
:
|
|
368
|
-
:
|
|
369
|
-
:
|
|
363
|
+
first_name: "First",
|
|
364
|
+
last_name: "Last",
|
|
365
|
+
hire_date: @today
|
|
370
366
|
)
|
|
371
367
|
@employee.first_name = nil
|
|
372
368
|
expect(@employee.save).to be_falsey
|
|
373
369
|
expect(@employee.errors[:first_name]).not_to be_blank
|
|
374
370
|
end
|
|
375
|
-
|
|
371
|
+
|
|
376
372
|
end
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
1
|
describe "OracleEnhancedAdapter schema dump" do
|
|
4
2
|
include SchemaSpecHelper
|
|
5
3
|
|
|
@@ -12,7 +10,7 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
|
12
10
|
|
|
13
11
|
def standard_dump(options = {})
|
|
14
12
|
stream = StringIO.new
|
|
15
|
-
ActiveRecord::SchemaDumper.ignore_tables = options[:ignore_tables]||[]
|
|
13
|
+
ActiveRecord::SchemaDumper.ignore_tables = options[:ignore_tables] || []
|
|
16
14
|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
|
|
17
15
|
stream.string
|
|
18
16
|
end
|
|
@@ -76,44 +74,45 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
|
76
74
|
describe "table prefixes and suffixes" do
|
|
77
75
|
after(:each) do
|
|
78
76
|
drop_test_posts_table
|
|
79
|
-
@conn.drop_table(ActiveRecord::
|
|
80
|
-
ActiveRecord::
|
|
81
|
-
ActiveRecord::Base.
|
|
77
|
+
@conn.drop_table(ActiveRecord::SchemaMigration.table_name) if @conn.table_exists?(ActiveRecord::SchemaMigration.table_name)
|
|
78
|
+
@conn.drop_table(ActiveRecord::InternalMetadata.table_name) if @conn.table_exists?(ActiveRecord::InternalMetadata.table_name)
|
|
79
|
+
ActiveRecord::Base.table_name_prefix = ""
|
|
80
|
+
ActiveRecord::Base.table_name_suffix = ""
|
|
82
81
|
end
|
|
83
82
|
|
|
84
83
|
it "should remove table prefix in schema dump" do
|
|
85
|
-
ActiveRecord::Base.table_name_prefix =
|
|
84
|
+
ActiveRecord::Base.table_name_prefix = "xxx_"
|
|
86
85
|
create_test_posts_table
|
|
87
|
-
expect(standard_dump).to match(/create_table "test_posts"
|
|
86
|
+
expect(standard_dump).to match(/create_table "test_posts"/m)
|
|
88
87
|
end
|
|
89
88
|
|
|
90
89
|
it "should remove table prefix with $ sign in schema dump" do
|
|
91
|
-
ActiveRecord::Base.table_name_prefix =
|
|
90
|
+
ActiveRecord::Base.table_name_prefix = "xxx$"
|
|
92
91
|
create_test_posts_table
|
|
93
|
-
expect(standard_dump).to match(/create_table "test_posts"
|
|
92
|
+
expect(standard_dump).to match(/create_table "test_posts"/m)
|
|
94
93
|
end
|
|
95
94
|
|
|
96
95
|
it "should remove table suffix in schema dump" do
|
|
97
|
-
ActiveRecord::Base.table_name_suffix =
|
|
96
|
+
ActiveRecord::Base.table_name_suffix = "_xxx"
|
|
98
97
|
create_test_posts_table
|
|
99
|
-
expect(standard_dump).to match(/create_table "test_posts"
|
|
98
|
+
expect(standard_dump).to match(/create_table "test_posts"/m)
|
|
100
99
|
end
|
|
101
100
|
|
|
102
101
|
it "should remove table suffix with $ sign in schema dump" do
|
|
103
|
-
ActiveRecord::Base.table_name_suffix =
|
|
102
|
+
ActiveRecord::Base.table_name_suffix = "$xxx"
|
|
104
103
|
create_test_posts_table
|
|
105
|
-
expect(standard_dump).to match(/create_table "test_posts"
|
|
104
|
+
expect(standard_dump).to match(/create_table "test_posts"/m)
|
|
106
105
|
end
|
|
107
106
|
|
|
108
107
|
it "should not include schema_migrations table with prefix in schema dump" do
|
|
109
|
-
ActiveRecord::Base.table_name_prefix =
|
|
110
|
-
|
|
108
|
+
ActiveRecord::Base.table_name_prefix = "xxx_"
|
|
109
|
+
ActiveRecord::SchemaMigration.create_table
|
|
111
110
|
expect(standard_dump).not_to match(/schema_migrations/)
|
|
112
111
|
end
|
|
113
112
|
|
|
114
113
|
it "should not include schema_migrations table with suffix in schema dump" do
|
|
115
|
-
ActiveRecord::Base.table_name_suffix =
|
|
116
|
-
|
|
114
|
+
ActiveRecord::Base.table_name_suffix = "_xxx"
|
|
115
|
+
ActiveRecord::SchemaMigration.create_table
|
|
117
116
|
expect(standard_dump).not_to match(/schema_migrations/)
|
|
118
117
|
end
|
|
119
118
|
|
|
@@ -125,7 +124,7 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
|
125
124
|
end
|
|
126
125
|
|
|
127
126
|
it "should include non-default primary key in schema dump" do
|
|
128
|
-
create_test_posts_table(primary_key:
|
|
127
|
+
create_test_posts_table(primary_key: "post_id")
|
|
129
128
|
expect(standard_dump).to match(/create_table "test_posts", primary_key: "post_id"/)
|
|
130
129
|
end
|
|
131
130
|
|
|
@@ -144,7 +143,7 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
|
144
143
|
end
|
|
145
144
|
|
|
146
145
|
it "should include primary key trigger with non-default primary key in schema dump" do
|
|
147
|
-
create_test_posts_table(primary_key_trigger: true, primary_key:
|
|
146
|
+
create_test_posts_table(primary_key_trigger: true, primary_key: "post_id")
|
|
148
147
|
expect(standard_dump).to match(/create_table "test_posts", primary_key: "post_id".*add_primary_key_trigger "test_posts", primary_key: "post_id"/m)
|
|
149
148
|
end
|
|
150
149
|
|
|
@@ -166,7 +165,7 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
|
166
165
|
after(:each) do
|
|
167
166
|
schema_define do
|
|
168
167
|
remove_foreign_key :test_comments, :test_posts rescue nil
|
|
169
|
-
remove_foreign_key :test_comments, name:
|
|
168
|
+
remove_foreign_key :test_comments, name: "comments_posts_baz_fooz_fk" rescue nil
|
|
170
169
|
end
|
|
171
170
|
end
|
|
172
171
|
after(:all) do
|
|
@@ -185,14 +184,14 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
|
185
184
|
|
|
186
185
|
it "should include foreign key with delete dependency in schema dump" do
|
|
187
186
|
schema_define do
|
|
188
|
-
add_foreign_key :test_comments, :test_posts,
|
|
187
|
+
add_foreign_key :test_comments, :test_posts, on_delete: :cascade
|
|
189
188
|
end
|
|
190
189
|
expect(standard_dump).to match(/add_foreign_key "test_comments", "test_posts", on_delete: :cascade/)
|
|
191
190
|
end
|
|
192
191
|
|
|
193
192
|
it "should include foreign key with nullify dependency in schema dump" do
|
|
194
193
|
schema_define do
|
|
195
|
-
add_foreign_key :test_comments, :test_posts,
|
|
194
|
+
add_foreign_key :test_comments, :test_posts, on_delete: :nullify
|
|
196
195
|
end
|
|
197
196
|
expect(standard_dump).to match(/add_foreign_key "test_comments", "test_posts", on_delete: :nullify/)
|
|
198
197
|
end
|
|
@@ -234,10 +233,10 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
|
234
233
|
dump = standard_dump
|
|
235
234
|
expect(dump.rindex("create_table")).to be < dump.index("add_foreign_key")
|
|
236
235
|
end
|
|
237
|
-
|
|
236
|
+
|
|
238
237
|
it "should include primary_key when reference column name is not 'id'" do
|
|
239
238
|
schema_define do
|
|
240
|
-
create_table :test_posts, force: true, :
|
|
239
|
+
create_table :test_posts, force: true, primary_key: "baz_id" do |t|
|
|
241
240
|
t.string :title
|
|
242
241
|
end
|
|
243
242
|
create_table :test_comments, force: true do |t|
|
|
@@ -253,7 +252,7 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
|
253
252
|
|
|
254
253
|
expect(standard_dump).to match(/add_foreign_key "test_comments", "test_posts", column: "baz_id", primary_key: "baz_id", name: "test_comments_baz_id_fk"/)
|
|
255
254
|
end
|
|
256
|
-
|
|
255
|
+
|
|
257
256
|
end
|
|
258
257
|
|
|
259
258
|
describe "synonyms" do
|
|
@@ -318,20 +317,20 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
|
318
317
|
|
|
319
318
|
it "should not specify default tablespace in add index" do
|
|
320
319
|
create_test_posts_table
|
|
321
|
-
expect(standard_dump).to match(/
|
|
320
|
+
expect(standard_dump).to match(/t\.index \["title"\], name: "index_test_posts_on_title"$/)
|
|
322
321
|
end
|
|
323
322
|
|
|
324
323
|
it "should specify non-default tablespace in add index" do
|
|
325
324
|
tablespace_name = @conn.default_tablespace
|
|
326
|
-
allow(@conn).to receive(:default_tablespace).and_return(
|
|
325
|
+
allow(@conn).to receive(:default_tablespace).and_return("dummy")
|
|
327
326
|
create_test_posts_table
|
|
328
|
-
expect(standard_dump).to match(/
|
|
327
|
+
expect(standard_dump).to match(/t\.index \["title"\], name: "index_test_posts_on_title", tablespace: "#{tablespace_name}"$/)
|
|
329
328
|
end
|
|
330
329
|
|
|
331
330
|
it "should create and dump function-based indexes" do
|
|
332
331
|
create_test_posts_table
|
|
333
332
|
@conn.add_index :test_posts, "NVL(created_at, updated_at)", name: "index_test_posts_cr_upd_at"
|
|
334
|
-
expect(standard_dump).to match(/
|
|
333
|
+
expect(standard_dump).to match(/t\.index \["NVL\(\\"CREATED_AT\\",\\"UPDATED_AT\\"\)"\], name: "index_test_posts_cr_upd_at"$/)
|
|
335
334
|
end
|
|
336
335
|
|
|
337
336
|
end
|
|
@@ -349,19 +348,19 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
|
349
348
|
end
|
|
350
349
|
end
|
|
351
350
|
|
|
352
|
-
describe
|
|
351
|
+
describe "virtual columns" do
|
|
353
352
|
before(:all) do
|
|
354
353
|
skip "Not supported in this database version" unless @oracle11g_or_higher
|
|
355
354
|
schema_define do
|
|
356
|
-
create_table :test_names, :
|
|
355
|
+
create_table :test_names, force: true do |t|
|
|
357
356
|
t.string :first_name
|
|
358
357
|
t.string :last_name
|
|
359
|
-
t.virtual :full_name, :
|
|
360
|
-
t.virtual :short_name, :
|
|
361
|
-
t.virtual :abbrev_name, :
|
|
362
|
-
t.virtual :name_ratio, :
|
|
363
|
-
t.column :full_name_length, :virtual, :
|
|
364
|
-
t.virtual :field_with_leading_space, :
|
|
358
|
+
t.virtual :full_name, as: "first_name || ', ' || last_name"
|
|
359
|
+
t.virtual :short_name, as: "COALESCE(first_name, last_name)", type: :string, limit: 300
|
|
360
|
+
t.virtual :abbrev_name, as: "SUBSTR(first_name,1,50) || ' ' || SUBSTR(last_name,1,1) || '.'", type: "VARCHAR(100)"
|
|
361
|
+
t.virtual :name_ratio, as: "(LENGTH(first_name)*10/LENGTH(last_name)*10)"
|
|
362
|
+
t.column :full_name_length, :virtual, as: "length(first_name || ', ' || last_name)", type: :integer
|
|
363
|
+
t.virtual :field_with_leading_space, as: "' ' || first_name || ' '", limit: 300, type: :string
|
|
365
364
|
end
|
|
366
365
|
end
|
|
367
366
|
end
|
|
@@ -382,16 +381,16 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
|
382
381
|
end
|
|
383
382
|
end
|
|
384
383
|
|
|
385
|
-
it
|
|
386
|
-
expect(standard_dump).to match(/t\.virtual "full_name",(\s*)limit: 512,(\s*)as: "\\"FIRST_NAME\\"\|\|', '\|\|\\"LAST_NAME\\""
|
|
387
|
-
expect(standard_dump).to match(/t\.virtual "short_name",(\s*)
|
|
388
|
-
expect(standard_dump).to match(/t\.virtual "full_name_length",(\s*)
|
|
384
|
+
it "should dump correctly" do
|
|
385
|
+
expect(standard_dump).to match(/t\.virtual "full_name",(\s*)type: :string,(\s*)limit: 512,(\s*)as: "\\"FIRST_NAME\\"\|\|', '\|\|\\"LAST_NAME\\""/)
|
|
386
|
+
expect(standard_dump).to match(/t\.virtual "short_name",(\s*)type: :string,(\s*)limit: 300,(\s*)as:(.*)/)
|
|
387
|
+
expect(standard_dump).to match(/t\.virtual "full_name_length",(\s*)type: :integer,(\s*)precision: 38,(\s*)as:(.*)/)
|
|
389
388
|
expect(standard_dump).to match(/t\.virtual "name_ratio",(\s*)as:(.*)\"$/) # no :type
|
|
390
|
-
expect(standard_dump).to match(/t\.virtual "abbrev_name",(\s*)
|
|
391
|
-
expect(standard_dump).to match(/t\.virtual "field_with_leading_space",(\s*)limit: 300,(\s*)as: "' '\|\|\\"FIRST_NAME\\"\|\|' '"
|
|
389
|
+
expect(standard_dump).to match(/t\.virtual "abbrev_name",(\s*)type: :string,(\s*)limit: 100,(\s*)as:(.*)/)
|
|
390
|
+
expect(standard_dump).to match(/t\.virtual "field_with_leading_space",(\s*)type: :string,(\s*)limit: 300,(\s*)as: "' '\|\|\\"FIRST_NAME\\"\|\|' '"/)
|
|
392
391
|
end
|
|
393
392
|
|
|
394
|
-
context
|
|
393
|
+
context "with column cache" do
|
|
395
394
|
before(:all) do
|
|
396
395
|
@old_cache = ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.cache_columns
|
|
397
396
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.cache_columns = true
|
|
@@ -399,8 +398,8 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
|
399
398
|
after(:all) do
|
|
400
399
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.cache_columns = @old_cache
|
|
401
400
|
end
|
|
402
|
-
it
|
|
403
|
-
col = TestName.columns.detect{|c| c.name ==
|
|
401
|
+
it "should not change column defaults after several dumps" do
|
|
402
|
+
col = TestName.columns.detect { |c| c.name == "full_name" }
|
|
404
403
|
expect(col).not_to be_nil
|
|
405
404
|
expect(col.virtual_column_data_default).not_to match(/:as/)
|
|
406
405
|
|
|
@@ -415,21 +414,21 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
|
415
414
|
context "with index on virtual column" do
|
|
416
415
|
before(:all) do
|
|
417
416
|
if @oracle11g_or_higher
|
|
418
|
-
schema_define do
|
|
419
|
-
add_index
|
|
417
|
+
schema_define do
|
|
418
|
+
add_index "test_names", "field_with_leading_space", name: "index_on_virtual_col"
|
|
420
419
|
end
|
|
421
420
|
end
|
|
422
421
|
end
|
|
423
422
|
after(:all) do
|
|
424
423
|
if @oracle11g_or_higher
|
|
425
424
|
schema_define do
|
|
426
|
-
remove_index
|
|
425
|
+
remove_index "test_names", name: "index_on_virtual_col"
|
|
427
426
|
end
|
|
428
427
|
end
|
|
429
428
|
end
|
|
430
|
-
it
|
|
431
|
-
expect(standard_dump).not_to match(/
|
|
432
|
-
expect(standard_dump).to match(/
|
|
429
|
+
it "should dump correctly" do
|
|
430
|
+
expect(standard_dump).not_to match(/t\.index .+FIRST_NAME.+$/)
|
|
431
|
+
expect(standard_dump).to match(/t\.index .+field_with_leading_space.+$/)
|
|
433
432
|
end
|
|
434
433
|
end
|
|
435
434
|
end
|
|
@@ -457,7 +456,7 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
|
457
456
|
describe "table comments" do
|
|
458
457
|
before(:each) do
|
|
459
458
|
schema_define do
|
|
460
|
-
create_table :test_table_comments, :
|
|
459
|
+
create_table :test_table_comments, comment: "this is a \"table comment\"!", force: true do |t|
|
|
461
460
|
t.string :blah
|
|
462
461
|
end
|
|
463
462
|
end
|
|
@@ -470,7 +469,7 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
|
470
469
|
end
|
|
471
470
|
|
|
472
471
|
it "should dump table comments" do
|
|
473
|
-
standard_dump.
|
|
472
|
+
expect(standard_dump).to match(/comment: "this is a \\"table comment\\"!"/)
|
|
474
473
|
end
|
|
475
474
|
end
|
|
476
475
|
|
|
@@ -478,7 +477,7 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
|
478
477
|
before(:each) do
|
|
479
478
|
schema_define do
|
|
480
479
|
create_table :test_column_comments, force: true do |t|
|
|
481
|
-
t.string :blah, :
|
|
480
|
+
t.string :blah, comment: "this is a \"column comment\"!"
|
|
482
481
|
end
|
|
483
482
|
end
|
|
484
483
|
end
|
|
@@ -490,47 +489,33 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
|
490
489
|
end
|
|
491
490
|
|
|
492
491
|
it "should dump column comments" do
|
|
493
|
-
standard_dump.
|
|
492
|
+
expect(standard_dump).to match(/comment: "this is a \\"column comment\\"!"/)
|
|
494
493
|
end
|
|
495
494
|
end
|
|
496
495
|
|
|
497
|
-
describe "
|
|
498
|
-
before
|
|
496
|
+
describe "schema.rb format" do
|
|
497
|
+
before do
|
|
498
|
+
create_test_posts_table
|
|
499
|
+
|
|
499
500
|
schema_define do
|
|
500
|
-
create_table :
|
|
501
|
-
t.string :
|
|
501
|
+
create_table :test_comments, force: true do |t|
|
|
502
|
+
t.string :title
|
|
502
503
|
end
|
|
503
|
-
end
|
|
504
|
-
end
|
|
505
504
|
|
|
506
|
-
|
|
507
|
-
schema_define do
|
|
508
|
-
drop_table :test_table_comments
|
|
505
|
+
add_index :test_comments, :title
|
|
509
506
|
end
|
|
510
507
|
end
|
|
511
508
|
|
|
512
|
-
it "should
|
|
513
|
-
standard_dump.
|
|
514
|
-
end
|
|
515
|
-
end
|
|
516
|
-
|
|
517
|
-
describe "column comments" do
|
|
518
|
-
before(:each) do
|
|
519
|
-
schema_define do
|
|
520
|
-
create_table :test_column_comments, force: true do |t|
|
|
521
|
-
t.string :blah, :comment => "this is a \"column comment\"!"
|
|
522
|
-
end
|
|
523
|
-
end
|
|
509
|
+
it "should be only one blank line between create_table methods in schema dump" do
|
|
510
|
+
expect(standard_dump).to match(/end\n\n create_table/)
|
|
524
511
|
end
|
|
525
512
|
|
|
526
|
-
after
|
|
513
|
+
after do
|
|
527
514
|
schema_define do
|
|
528
|
-
drop_table :
|
|
515
|
+
drop_table :test_comments rescue nil
|
|
529
516
|
end
|
|
530
|
-
end
|
|
531
517
|
|
|
532
|
-
|
|
533
|
-
standard_dump.should =~ /comment: "this is a \\"column comment\\"!"/
|
|
518
|
+
drop_test_posts_table
|
|
534
519
|
end
|
|
535
520
|
end
|
|
536
521
|
end
|