activerecord-oracle_enhanced-adapter 8.1.0-java
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 +7 -0
- data/History.md +1971 -0
- data/License.txt +20 -0
- data/README.md +947 -0
- data/VERSION +1 -0
- data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +7 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +24 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +137 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +359 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/database_limits.rb +47 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +325 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +63 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/dbms_output.rb +71 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +629 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +38 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/lob.rb +57 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +465 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +44 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +195 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +186 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +95 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +99 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +197 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +739 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +394 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/type_metadata.rb +34 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +3 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +886 -0
- data/lib/active_record/type/oracle_enhanced/boolean.rb +19 -0
- data/lib/active_record/type/oracle_enhanced/character_string.rb +36 -0
- data/lib/active_record/type/oracle_enhanced/integer.rb +14 -0
- data/lib/active_record/type/oracle_enhanced/json.rb +10 -0
- data/lib/active_record/type/oracle_enhanced/national_character_string.rb +26 -0
- data/lib/active_record/type/oracle_enhanced/national_character_text.rb +36 -0
- data/lib/active_record/type/oracle_enhanced/raw.rb +25 -0
- data/lib/active_record/type/oracle_enhanced/string.rb +29 -0
- data/lib/active_record/type/oracle_enhanced/text.rb +32 -0
- data/lib/active_record/type/oracle_enhanced/timestampltz.rb +25 -0
- data/lib/active_record/type/oracle_enhanced/timestamptz.rb +25 -0
- data/lib/activerecord-oracle_enhanced-adapter.rb +25 -0
- data/lib/arel/visitors/oracle.rb +216 -0
- data/lib/arel/visitors/oracle12.rb +121 -0
- data/lib/arel/visitors/oracle_common.rb +51 -0
- data/spec/active_record/connection_adapters/emulation/oracle_adapter_spec.rb +24 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/compatibility_spec.rb +40 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/composite_spec.rb +84 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb +589 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/context_index_spec.rb +431 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/database_tasks_spec.rb +122 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/dbconsole_spec.rb +63 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/dbms_output_spec.rb +69 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/procedures_spec.rb +362 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/quoting_spec.rb +181 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/schema_dumper_spec.rb +492 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/schema_statements_spec.rb +1318 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/structure_dump_spec.rb +485 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +815 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +230 -0
- data/spec/active_record/oracle_enhanced/type/binary_spec.rb +119 -0
- data/spec/active_record/oracle_enhanced/type/boolean_spec.rb +206 -0
- data/spec/active_record/oracle_enhanced/type/character_string_spec.rb +67 -0
- data/spec/active_record/oracle_enhanced/type/custom_spec.rb +90 -0
- data/spec/active_record/oracle_enhanced/type/decimal_spec.rb +56 -0
- data/spec/active_record/oracle_enhanced/type/dirty_spec.rb +141 -0
- data/spec/active_record/oracle_enhanced/type/float_spec.rb +48 -0
- data/spec/active_record/oracle_enhanced/type/integer_spec.rb +101 -0
- data/spec/active_record/oracle_enhanced/type/json_spec.rb +56 -0
- data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +55 -0
- data/spec/active_record/oracle_enhanced/type/national_character_text_spec.rb +230 -0
- data/spec/active_record/oracle_enhanced/type/raw_spec.rb +137 -0
- data/spec/active_record/oracle_enhanced/type/text_spec.rb +295 -0
- data/spec/active_record/oracle_enhanced/type/timestamp_spec.rb +107 -0
- data/spec/spec_config.yaml.template +11 -0
- data/spec/spec_helper.rb +225 -0
- data/spec/support/alter_system_set_open_cursors.sql +1 -0
- data/spec/support/alter_system_user_password.sql +2 -0
- data/spec/support/create_oracle_enhanced_users.sql +31 -0
- metadata +181 -0
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
describe "OracleEnhancedAdapter schema dump" do
|
|
4
|
+
include SchemaSpecHelper
|
|
5
|
+
include SchemaDumpingHelper
|
|
6
|
+
|
|
7
|
+
before(:all) do
|
|
8
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
|
9
|
+
@conn = ActiveRecord::Base.connection
|
|
10
|
+
@oracle11g_or_higher = !! @conn.select_value(
|
|
11
|
+
"select * from product_component_version where product like 'Oracle%' and to_number(substr(version,1,2)) >= 11")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def standard_dump(options = {})
|
|
15
|
+
stream = StringIO.new
|
|
16
|
+
ActiveRecord::SchemaDumper.ignore_tables = options[:ignore_tables] || []
|
|
17
|
+
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection_pool, stream)
|
|
18
|
+
stream.string
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def create_test_posts_table(options = {})
|
|
22
|
+
options[:force] = true
|
|
23
|
+
schema_define do
|
|
24
|
+
create_table :test_posts, **options do |t|
|
|
25
|
+
t.string :title
|
|
26
|
+
t.timestamps null: true
|
|
27
|
+
end
|
|
28
|
+
add_index :test_posts, :title
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def drop_test_posts_table
|
|
33
|
+
schema_define do
|
|
34
|
+
drop_table :test_posts
|
|
35
|
+
end
|
|
36
|
+
rescue
|
|
37
|
+
nil
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe "tables" do
|
|
41
|
+
after(:each) do
|
|
42
|
+
drop_test_posts_table
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should not include ignored table names in schema dump" do
|
|
46
|
+
create_test_posts_table
|
|
47
|
+
expect(standard_dump(ignore_tables: %w(test_posts))).not_to match(/create_table "test_posts"/)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should not include ignored table regexes in schema dump" do
|
|
51
|
+
create_test_posts_table
|
|
52
|
+
expect(standard_dump(ignore_tables: [ /test_posts/i ])).not_to match(/create_table "test_posts"/)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe "dumping default values" do
|
|
57
|
+
before :each do
|
|
58
|
+
schema_define do
|
|
59
|
+
create_table "test_defaults", force: true do |t|
|
|
60
|
+
t.string "regular", default: "c"
|
|
61
|
+
t.string "special_c", default: "\n"
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
after(:each) do
|
|
67
|
+
schema_define do
|
|
68
|
+
drop_table "test_defaults"
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "should be able to dump default values using special characters" do
|
|
73
|
+
output = dump_table_schema "test_defaults"
|
|
74
|
+
expect(output).to match(/t.string "special_c", default: "\\n"/)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
describe "table with non-default primary key" do
|
|
79
|
+
after(:each) do
|
|
80
|
+
drop_test_posts_table
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "should include non-default primary key in schema dump" do
|
|
84
|
+
create_test_posts_table(primary_key: "post_id")
|
|
85
|
+
output = dump_table_schema "test_posts"
|
|
86
|
+
expect(output).to match(/create_table "test_posts", primary_key: "post_id"/)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
describe "table with ntext columns" do
|
|
91
|
+
before :each do
|
|
92
|
+
schema_define do
|
|
93
|
+
create_table "test_ntexts", force: true do |t|
|
|
94
|
+
t.ntext :ntext_column
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
after(:each) do
|
|
100
|
+
schema_define do
|
|
101
|
+
drop_table "test_ntexts"
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "should be able to dump ntext columns" do
|
|
106
|
+
output = dump_table_schema "test_ntexts"
|
|
107
|
+
expect(output).to match(/t.ntext "ntext_column"/)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
describe "foreign key constraints" do
|
|
112
|
+
before(:all) do
|
|
113
|
+
schema_define do
|
|
114
|
+
create_table :test_posts, force: true do |t|
|
|
115
|
+
t.string :title
|
|
116
|
+
end
|
|
117
|
+
create_table :test_comments, force: true do |t|
|
|
118
|
+
t.string :body, limit: 4000
|
|
119
|
+
t.references :test_post
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
after(:each) do
|
|
125
|
+
schema_define do
|
|
126
|
+
remove_foreign_key :test_comments, :test_posts rescue nil
|
|
127
|
+
remove_foreign_key :test_comments, name: "comments_posts_baz_fooz_fk" rescue nil
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
after(:all) do
|
|
132
|
+
schema_define do
|
|
133
|
+
drop_table :test_comments, if_exists: true
|
|
134
|
+
drop_table :test_posts, if_exists: true
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it "should include foreign key in schema dump" do
|
|
139
|
+
schema_define do
|
|
140
|
+
add_foreign_key :test_comments, :test_posts
|
|
141
|
+
end
|
|
142
|
+
output = dump_table_schema "test_comments"
|
|
143
|
+
expect(output).to match(/add_foreign_key "test_comments", "test_posts"/)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it "should include foreign key with delete dependency in schema dump" do
|
|
147
|
+
schema_define do
|
|
148
|
+
add_foreign_key :test_comments, :test_posts, on_delete: :cascade
|
|
149
|
+
end
|
|
150
|
+
output = dump_table_schema "test_comments"
|
|
151
|
+
expect(output).to match(/add_foreign_key "test_comments", "test_posts", on_delete: :cascade/)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it "should include foreign key with nullify dependency in schema dump" do
|
|
155
|
+
schema_define do
|
|
156
|
+
add_foreign_key :test_comments, :test_posts, on_delete: :nullify
|
|
157
|
+
end
|
|
158
|
+
output = dump_table_schema "test_comments"
|
|
159
|
+
expect(output).to match(/add_foreign_key "test_comments", "test_posts", on_delete: :nullify/)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "should not include foreign keys on ignored table names in schema dump" do
|
|
163
|
+
schema_define do
|
|
164
|
+
add_foreign_key :test_comments, :test_posts
|
|
165
|
+
end
|
|
166
|
+
expect(standard_dump(ignore_tables: %w(test_comments))).not_to match(/add_foreign_key "test_comments"/)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it "should not include foreign keys on ignored table regexes in schema dump" do
|
|
170
|
+
schema_define do
|
|
171
|
+
add_foreign_key :test_comments, :test_posts
|
|
172
|
+
end
|
|
173
|
+
expect(standard_dump(ignore_tables: [ /test_comments/i ])).not_to match(/add_foreign_key "test_comments"/)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
it "should include foreign keys referencing ignored table names in schema dump" do
|
|
177
|
+
schema_define do
|
|
178
|
+
add_foreign_key :test_comments, :test_posts
|
|
179
|
+
end
|
|
180
|
+
expect(standard_dump(ignore_tables: %w(test_posts))).to match(/add_foreign_key "test_comments"/)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
it "should include foreign keys referencing ignored table regexes in schema dump" do
|
|
184
|
+
schema_define do
|
|
185
|
+
add_foreign_key :test_comments, :test_posts
|
|
186
|
+
end
|
|
187
|
+
expect(standard_dump(ignore_tables: [ /test_posts/i ])).to match(/add_foreign_key "test_comments"/)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
it "should include foreign keys following all tables" do
|
|
191
|
+
# if foreign keys precede declaration of all tables
|
|
192
|
+
# it can cause problems when using db:test rake tasks
|
|
193
|
+
schema_define do
|
|
194
|
+
add_foreign_key :test_comments, :test_posts
|
|
195
|
+
end
|
|
196
|
+
dump = standard_dump
|
|
197
|
+
expect(dump.rindex("create_table")).to be < dump.index("add_foreign_key")
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
it "should include primary_key when reference column name is not 'id'" do
|
|
201
|
+
schema_define do
|
|
202
|
+
create_table :test_posts, force: true, primary_key: "baz_id" do |t|
|
|
203
|
+
t.string :title
|
|
204
|
+
end
|
|
205
|
+
create_table :test_comments, force: true do |t|
|
|
206
|
+
t.string :body, limit: 4000
|
|
207
|
+
t.integer :baz_id
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
@conn.execute <<~SQL
|
|
212
|
+
ALTER TABLE TEST_COMMENTS
|
|
213
|
+
ADD CONSTRAINT TEST_COMMENTS_BAZ_ID_FK FOREIGN KEY (baz_id) REFERENCES test_posts(baz_id)
|
|
214
|
+
SQL
|
|
215
|
+
|
|
216
|
+
output = dump_table_schema "test_comments"
|
|
217
|
+
expect(output).to match(/add_foreign_key "test_comments", "test_posts", column: "baz_id", primary_key: "baz_id", name: "test_comments_baz_id_fk"/)
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
describe "synonyms" do
|
|
222
|
+
after(:each) do
|
|
223
|
+
schema_define do
|
|
224
|
+
remove_synonym :test_synonym
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
it "should include synonym to other schema table in schema dump" do
|
|
229
|
+
schema_define do
|
|
230
|
+
add_synonym :test_synonym, "schema_name.table_name", force: true
|
|
231
|
+
end
|
|
232
|
+
expect(standard_dump).to match(/add_synonym "test_synonym", "schema_name.table_name", force: true/)
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
it "should not include ignored table names in schema dump" do
|
|
236
|
+
schema_define do
|
|
237
|
+
add_synonym :test_synonym, "schema_name.table_name", force: true
|
|
238
|
+
end
|
|
239
|
+
expect(standard_dump(ignore_tables: %w(test_synonym))).not_to match(/add_synonym "test_synonym"/)
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
it "should not include ignored table regexes in schema dump" do
|
|
243
|
+
schema_define do
|
|
244
|
+
add_synonym :test_synonym, "schema_name.table_name", force: true
|
|
245
|
+
end
|
|
246
|
+
expect(standard_dump(ignore_tables: [ /test_synonym/i ])).not_to match(/add_synonym "test_synonym"/)
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
it "should include synonyms to ignored table regexes in schema dump" do
|
|
250
|
+
schema_define do
|
|
251
|
+
add_synonym :test_synonym, "schema_name.table_name", force: true
|
|
252
|
+
end
|
|
253
|
+
expect(standard_dump(ignore_tables: [ /table_name/i ])).to match(/add_synonym "test_synonym"/)
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
describe "temporary tables" do
|
|
258
|
+
after(:each) do
|
|
259
|
+
drop_test_posts_table
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
it "should include temporary options" do
|
|
263
|
+
create_test_posts_table(temporary: true)
|
|
264
|
+
output = dump_table_schema "test_posts"
|
|
265
|
+
expect(output).to match(/create_table "test_posts", temporary: true/)
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
describe "indexes" do
|
|
270
|
+
after(:each) do
|
|
271
|
+
drop_test_posts_table
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
it "should not specify default tablespace in add index" do
|
|
275
|
+
create_test_posts_table
|
|
276
|
+
output = dump_table_schema "test_posts"
|
|
277
|
+
expect(output).to match(/t\.index \["title"\], name: "index_test_posts_on_title"$/)
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
it "should specify non-default tablespace in add index" do
|
|
281
|
+
tablespace_name = @conn.default_tablespace
|
|
282
|
+
allow(@conn).to receive(:default_tablespace).and_return("dummy")
|
|
283
|
+
create_test_posts_table
|
|
284
|
+
output = dump_table_schema "test_posts"
|
|
285
|
+
expect(output).to match(/t\.index \["title"\], name: "index_test_posts_on_title", tablespace: "#{tablespace_name}"$/)
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
it "should create and dump function-based indexes" do
|
|
289
|
+
create_test_posts_table
|
|
290
|
+
@conn.add_index :test_posts, "NVL(created_at, updated_at)", name: "index_test_posts_cr_upd_at"
|
|
291
|
+
output = dump_table_schema "test_posts"
|
|
292
|
+
expect(output).to match(/t\.index \["NVL\(\\"CREATED_AT\\",\\"UPDATED_AT\\"\)"\], name: "index_test_posts_cr_upd_at"$/)
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
describe "materialized views" do
|
|
297
|
+
after(:each) do
|
|
298
|
+
@conn.execute "DROP MATERIALIZED VIEW test_posts_mv" rescue nil
|
|
299
|
+
drop_test_posts_table
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
it "should not include materialized views in schema dump" do
|
|
303
|
+
create_test_posts_table
|
|
304
|
+
@conn.execute "CREATE MATERIALIZED VIEW test_posts_mv AS SELECT * FROM test_posts"
|
|
305
|
+
expect(standard_dump).not_to match(/create_table "test_posts_mv"/)
|
|
306
|
+
end
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
describe "context indexes" do
|
|
310
|
+
before(:each) do
|
|
311
|
+
schema_define do
|
|
312
|
+
create_table :test_context_indexed_posts, force: true do |t|
|
|
313
|
+
t.string :title
|
|
314
|
+
t.string :body
|
|
315
|
+
t.index :title
|
|
316
|
+
end
|
|
317
|
+
add_context_index :test_context_indexed_posts, :body, sync: "ON COMMIT"
|
|
318
|
+
end
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
after(:each) do
|
|
322
|
+
schema_define do
|
|
323
|
+
drop_table :test_context_indexed_posts
|
|
324
|
+
end
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
it "should dump the context index" do
|
|
328
|
+
expect(standard_dump).to include(%(add_context_index "test_context_indexed_posts", ["body"]))
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
it "dumps the sync option" do
|
|
332
|
+
expect(standard_dump).to include(%(sync: "ON COMMIT"))
|
|
333
|
+
end
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
describe "virtual columns" do
|
|
337
|
+
before(:all) do
|
|
338
|
+
skip "Not supported in this database version" unless @oracle11g_or_higher
|
|
339
|
+
schema_define do
|
|
340
|
+
create_table :test_names, force: true do |t|
|
|
341
|
+
t.string :first_name
|
|
342
|
+
t.string :last_name
|
|
343
|
+
t.virtual :full_name, as: "first_name || ', ' || last_name"
|
|
344
|
+
t.virtual :short_name, as: "COALESCE(first_name, last_name)", type: :string, limit: 300
|
|
345
|
+
t.virtual :abbrev_name, as: "SUBSTR(first_name,1,50) || ' ' || SUBSTR(last_name,1,1) || '.'", type: "VARCHAR(100)"
|
|
346
|
+
t.virtual :name_ratio, as: "(LENGTH(first_name)*10/LENGTH(last_name)*10)"
|
|
347
|
+
t.column :full_name_length, :virtual, as: "length(first_name || ', ' || last_name)", type: :integer
|
|
348
|
+
t.virtual :field_with_leading_space, as: "' ' || first_name || ' '", limit: 300, type: :string
|
|
349
|
+
end
|
|
350
|
+
end
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
before(:each) do
|
|
354
|
+
if @oracle11g_or_higher
|
|
355
|
+
class ::TestName < ActiveRecord::Base
|
|
356
|
+
self.table_name = "test_names"
|
|
357
|
+
end
|
|
358
|
+
end
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
after(:all) do
|
|
362
|
+
if @oracle11g_or_higher
|
|
363
|
+
schema_define do
|
|
364
|
+
drop_table :test_names
|
|
365
|
+
end
|
|
366
|
+
end
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
it "should dump correctly" do
|
|
370
|
+
output = dump_table_schema "test_names"
|
|
371
|
+
expect(output).to match(/t\.virtual "full_name",(\s*)type: :string,(\s*)limit: 512,(\s*)as: "\\"FIRST_NAME\\"\|\|', '\|\|\\"LAST_NAME\\""/)
|
|
372
|
+
expect(output).to match(/t\.virtual "short_name",(\s*)type: :string,(\s*)limit: 300,(\s*)as:(.*)/)
|
|
373
|
+
expect(output).to match(/t\.virtual "full_name_length",(\s*)type: :integer,(\s*)precision: 38,(\s*)as:(.*)/)
|
|
374
|
+
expect(output).to match(/t\.virtual "name_ratio",(\s*)as:(.*)"$/) # no :type
|
|
375
|
+
expect(output).to match(/t\.virtual "abbrev_name",(\s*)type: :string,(\s*)limit: 100,(\s*)as:(.*)/)
|
|
376
|
+
expect(output).to match(/t\.virtual "field_with_leading_space",(\s*)type: :string,(\s*)limit: 300,(\s*)as: "' '\|\|\\"FIRST_NAME\\"\|\|' '"/)
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
context "with index on virtual column" do
|
|
380
|
+
before(:all) do
|
|
381
|
+
if @oracle11g_or_higher
|
|
382
|
+
schema_define do
|
|
383
|
+
add_index "test_names", "field_with_leading_space", name: "index_on_virtual_col"
|
|
384
|
+
end
|
|
385
|
+
end
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
after(:all) do
|
|
389
|
+
if @oracle11g_or_higher
|
|
390
|
+
schema_define do
|
|
391
|
+
remove_index "test_names", name: "index_on_virtual_col"
|
|
392
|
+
end
|
|
393
|
+
end
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
it "should dump correctly" do
|
|
397
|
+
output = dump_table_schema "test_names"
|
|
398
|
+
expect(output).not_to match(/t\.index .+FIRST_NAME.+$/)
|
|
399
|
+
expect(output).to match(/t\.index .+field_with_leading_space.+$/)
|
|
400
|
+
end
|
|
401
|
+
end
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
describe ":float datatype" do
|
|
405
|
+
before(:each) do
|
|
406
|
+
schema_define do
|
|
407
|
+
create_table :test_floats, force: true do |t|
|
|
408
|
+
t.float :hourly_rate
|
|
409
|
+
end
|
|
410
|
+
end
|
|
411
|
+
end
|
|
412
|
+
|
|
413
|
+
after(:each) do
|
|
414
|
+
schema_define do
|
|
415
|
+
drop_table :test_floats
|
|
416
|
+
end
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
it "should dump float type correctly" do
|
|
420
|
+
output = dump_table_schema "test_floats"
|
|
421
|
+
expect(output).to match(/t\.float "hourly_rate"$/)
|
|
422
|
+
end
|
|
423
|
+
end
|
|
424
|
+
|
|
425
|
+
describe "table comments" do
|
|
426
|
+
before(:each) do
|
|
427
|
+
schema_define do
|
|
428
|
+
create_table :test_table_comments, comment: "this is a \"table comment\"!", force: true do |t|
|
|
429
|
+
t.string :blah
|
|
430
|
+
end
|
|
431
|
+
end
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
after(:each) do
|
|
435
|
+
schema_define do
|
|
436
|
+
drop_table :test_table_comments
|
|
437
|
+
end
|
|
438
|
+
end
|
|
439
|
+
|
|
440
|
+
it "should dump table comments" do
|
|
441
|
+
output = dump_table_schema "test_table_comments"
|
|
442
|
+
expect(output).to match(/create_table "test_table_comments", comment: "this is a \\"table comment\\"!", force: :cascade do \|t\|$/)
|
|
443
|
+
end
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
describe "column comments" do
|
|
447
|
+
before(:each) do
|
|
448
|
+
schema_define do
|
|
449
|
+
create_table :test_column_comments, force: true do |t|
|
|
450
|
+
t.string :blah, comment: "this is a \"column comment\"!"
|
|
451
|
+
end
|
|
452
|
+
end
|
|
453
|
+
end
|
|
454
|
+
|
|
455
|
+
after(:each) do
|
|
456
|
+
schema_define do
|
|
457
|
+
drop_table :test_column_comments
|
|
458
|
+
end
|
|
459
|
+
end
|
|
460
|
+
|
|
461
|
+
it "should dump column comments" do
|
|
462
|
+
output = dump_table_schema "test_column_comments"
|
|
463
|
+
expect(output).to match(/comment: "this is a \\"column comment\\"!"/)
|
|
464
|
+
end
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
describe "schema.rb format" do
|
|
468
|
+
before do
|
|
469
|
+
create_test_posts_table
|
|
470
|
+
|
|
471
|
+
schema_define do
|
|
472
|
+
create_table :test_comments, force: true do |t|
|
|
473
|
+
t.string :title
|
|
474
|
+
end
|
|
475
|
+
|
|
476
|
+
add_index :test_comments, :title
|
|
477
|
+
end
|
|
478
|
+
end
|
|
479
|
+
|
|
480
|
+
it "should be only one blank line between create_table methods in schema dump" do
|
|
481
|
+
expect(standard_dump).to match(/end\n\n create_table/)
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
after do
|
|
485
|
+
schema_define do
|
|
486
|
+
drop_table :test_comments, if_exists: true
|
|
487
|
+
end
|
|
488
|
+
|
|
489
|
+
drop_test_posts_table
|
|
490
|
+
end
|
|
491
|
+
end
|
|
492
|
+
end
|