activerecord-oracle_enhanced-adapter 6.0.0.beta1 → 6.0.0.rc1
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 +25 -1
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +2 -2
- data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +21 -21
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +57 -57
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +3 -3
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +5 -5
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +5 -2
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +41 -40
- data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +35 -35
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +26 -22
- data/spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb +1 -1
- data/spec/active_record/connection_adapters/oracle_enhanced/dbms_output_spec.rb +17 -17
- data/spec/active_record/connection_adapters/oracle_enhanced/procedures_spec.rb +2 -2
- data/spec/active_record/connection_adapters/oracle_enhanced/schema_dumper_spec.rb +1 -1
- data/spec/active_record/connection_adapters/oracle_enhanced/structure_dump_spec.rb +24 -24
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +2 -2
- data/spec/active_record/oracle_enhanced/type/boolean_spec.rb +2 -2
- data/spec/active_record/oracle_enhanced/type/character_string_spec.rb +1 -1
- data/spec/active_record/oracle_enhanced/type/integer_spec.rb +2 -2
- data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +1 -1
- metadata +4 -4
@@ -8,7 +8,7 @@ module ActiveRecord #:nodoc:
|
|
8
8
|
STATEMENT_TOKEN = "\n\n/\n\n"
|
9
9
|
|
10
10
|
def structure_dump #:nodoc:
|
11
|
-
sequences = select(
|
11
|
+
sequences = select(<<~SQL.squish, "sequences to dump at structure dump")
|
12
12
|
SELECT sequence_name, min_value, max_value, increment_by, order_flag, cycle_flag
|
13
13
|
FROM all_sequences
|
14
14
|
where sequence_owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1
|
@@ -17,7 +17,7 @@ module ActiveRecord #:nodoc:
|
|
17
17
|
structure = sequences.map do |result|
|
18
18
|
"CREATE SEQUENCE #{quote_table_name(result["sequence_name"])} MINVALUE #{result["min_value"]} MAXVALUE #{result["max_value"]} INCREMENT BY #{result["increment_by"]} #{result["order_flag"] == 'Y' ? "ORDER" : "NOORDER"} #{result["cycle_flag"] == 'Y' ? "CYCLE" : "NOCYCLE"}"
|
19
19
|
end
|
20
|
-
tables = select_values(
|
20
|
+
tables = select_values(<<~SQL.squish, "tables at structure dump")
|
21
21
|
SELECT table_name FROM all_tables t
|
22
22
|
WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N'
|
23
23
|
AND NOT EXISTS (SELECT mv.mview_name FROM all_mviews mv
|
@@ -29,7 +29,7 @@ module ActiveRecord #:nodoc:
|
|
29
29
|
tables.each do |table_name|
|
30
30
|
virtual_columns = virtual_columns_for(table_name) if supports_virtual_columns?
|
31
31
|
ddl = +"CREATE#{ ' GLOBAL TEMPORARY' if temporary_table?(table_name)} TABLE \"#{table_name}\" (\n"
|
32
|
-
columns = select_all(
|
32
|
+
columns = select_all(<<~SQL.squish, "columns at structure dump")
|
33
33
|
SELECT column_name, data_type, data_length, char_used, char_length,
|
34
34
|
data_precision, data_scale, data_default, nullable
|
35
35
|
FROM all_tab_columns
|
@@ -89,16 +89,16 @@ module ActiveRecord #:nodoc:
|
|
89
89
|
|
90
90
|
def structure_dump_primary_key(table) #:nodoc:
|
91
91
|
opts = { name: "", cols: [] }
|
92
|
-
pks = select_all(
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
92
|
+
pks = select_all(<<~SQL.squish, "Primary Keys")
|
93
|
+
SELECT a.constraint_name, a.column_name, a.position
|
94
|
+
FROM all_cons_columns a
|
95
|
+
JOIN all_constraints c
|
96
|
+
ON a.constraint_name = c.constraint_name
|
97
|
+
WHERE c.table_name = '#{table.upcase}'
|
98
|
+
AND c.constraint_type = 'P'
|
99
|
+
AND a.owner = c.owner
|
100
|
+
AND c.owner = SYS_CONTEXT('userenv', 'current_schema')
|
101
|
+
SQL
|
102
102
|
pks.each do |row|
|
103
103
|
opts[:name] = row["constraint_name"]
|
104
104
|
opts[:cols][row["position"] - 1] = row["column_name"]
|
@@ -108,16 +108,16 @@ module ActiveRecord #:nodoc:
|
|
108
108
|
|
109
109
|
def structure_dump_unique_keys(table) #:nodoc:
|
110
110
|
keys = {}
|
111
|
-
uks = select_all(
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
111
|
+
uks = select_all(<<~SQL.squish, "Primary Keys")
|
112
|
+
SELECT a.constraint_name, a.column_name, a.position
|
113
|
+
FROM all_cons_columns a
|
114
|
+
JOIN all_constraints c
|
115
|
+
ON a.constraint_name = c.constraint_name
|
116
|
+
WHERE c.table_name = '#{table.upcase}'
|
117
|
+
AND c.constraint_type = 'U'
|
118
|
+
AND a.owner = c.owner
|
119
|
+
AND c.owner = SYS_CONTEXT('userenv', 'current_schema')
|
120
|
+
SQL
|
121
121
|
uks.each do |uk|
|
122
122
|
keys[uk["constraint_name"]] ||= []
|
123
123
|
keys[uk["constraint_name"]][uk["position"] - 1] = uk["column_name"]
|
@@ -144,7 +144,7 @@ module ActiveRecord #:nodoc:
|
|
144
144
|
end
|
145
145
|
|
146
146
|
def structure_dump_fk_constraints #:nodoc:
|
147
|
-
foreign_keys = select_all(
|
147
|
+
foreign_keys = select_all(<<~SQL.squish, "foreign keys at structure dump")
|
148
148
|
SELECT table_name FROM all_tables
|
149
149
|
WHERE owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1
|
150
150
|
SQL
|
@@ -172,7 +172,7 @@ module ActiveRecord #:nodoc:
|
|
172
172
|
|
173
173
|
def structure_dump_column_comments(table_name)
|
174
174
|
comments = []
|
175
|
-
columns = select_values(
|
175
|
+
columns = select_values(<<~SQL.squish, "column comments at structure dump")
|
176
176
|
SELECT column_name FROM user_tab_columns
|
177
177
|
WHERE table_name = '#{table_name}' ORDER BY column_id
|
178
178
|
SQL
|
@@ -206,7 +206,7 @@ module ActiveRecord #:nodoc:
|
|
206
206
|
# Extract all stored procedures, packages, synonyms.
|
207
207
|
def structure_dump_db_stored_code #:nodoc:
|
208
208
|
structure = []
|
209
|
-
all_source = select_all(
|
209
|
+
all_source = select_all(<<~SQL.squish, "stored program at structure dump")
|
210
210
|
SELECT DISTINCT name, type
|
211
211
|
FROM all_source
|
212
212
|
WHERE type IN ('PROCEDURE', 'PACKAGE', 'PACKAGE BODY', 'FUNCTION', 'TRIGGER', 'TYPE')
|
@@ -215,7 +215,7 @@ module ActiveRecord #:nodoc:
|
|
215
215
|
SQL
|
216
216
|
all_source.each do |source|
|
217
217
|
ddl = +"CREATE OR REPLACE \n"
|
218
|
-
texts = select_all(
|
218
|
+
texts = select_all(<<~SQL.squish, "all source at structure dump")
|
219
219
|
SELECT text
|
220
220
|
FROM all_source
|
221
221
|
WHERE name = '#{source['name']}'
|
@@ -238,7 +238,7 @@ module ActiveRecord #:nodoc:
|
|
238
238
|
|
239
239
|
def structure_dump_views #:nodoc:
|
240
240
|
structure = []
|
241
|
-
views = select_all(
|
241
|
+
views = select_all(<<~SQL.squish, "views at structure dump")
|
242
242
|
SELECT view_name, text FROM all_views
|
243
243
|
WHERE owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY view_name ASC
|
244
244
|
SQL
|
@@ -250,7 +250,7 @@ module ActiveRecord #:nodoc:
|
|
250
250
|
|
251
251
|
def structure_dump_synonyms #:nodoc:
|
252
252
|
structure = []
|
253
|
-
synonyms = select_all(
|
253
|
+
synonyms = select_all(<<~SQL.squish, "synonyms at structure dump")
|
254
254
|
SELECT owner, synonym_name, table_name, table_owner
|
255
255
|
FROM all_synonyms
|
256
256
|
WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
|
@@ -263,13 +263,13 @@ module ActiveRecord #:nodoc:
|
|
263
263
|
end
|
264
264
|
|
265
265
|
def structure_drop #:nodoc:
|
266
|
-
sequences = select_values(
|
266
|
+
sequences = select_values(<<~SQL.squish, "sequences to drop at structure dump")
|
267
267
|
SELECT sequence_name FROM all_sequences where sequence_owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1
|
268
268
|
SQL
|
269
269
|
statements = sequences.map do |seq|
|
270
270
|
"DROP SEQUENCE \"#{seq}\""
|
271
271
|
end
|
272
|
-
tables = select_values(
|
272
|
+
tables = select_values(<<~SQL.squish, "tables to drop at structure dump")
|
273
273
|
SELECT table_name from all_tables t
|
274
274
|
WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N'
|
275
275
|
AND NOT EXISTS (SELECT mv.mview_name FROM all_mviews mv
|
@@ -285,7 +285,7 @@ module ActiveRecord #:nodoc:
|
|
285
285
|
end
|
286
286
|
|
287
287
|
def temp_table_drop #:nodoc:
|
288
|
-
temporary_tables = select_values(
|
288
|
+
temporary_tables = select_values(<<~SQL.squish, "temporary tables to drop at structure dump")
|
289
289
|
SELECT table_name FROM all_tables
|
290
290
|
WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
|
291
291
|
AND secondary = 'N' AND temporary = 'Y' ORDER BY 1
|
@@ -320,7 +320,7 @@ module ActiveRecord #:nodoc:
|
|
320
320
|
# Called only if `supports_virtual_columns?` returns true
|
321
321
|
# return [{'column_name' => 'FOOS', 'data_default' => '...'}, ...]
|
322
322
|
def virtual_columns_for(table)
|
323
|
-
select_all(
|
323
|
+
select_all(<<~SQL.squish, "virtual columns for")
|
324
324
|
SELECT column_name, data_default
|
325
325
|
FROM all_tab_cols
|
326
326
|
WHERE virtual_column = 'YES'
|
@@ -331,7 +331,7 @@ module ActiveRecord #:nodoc:
|
|
331
331
|
|
332
332
|
def drop_sql_for_feature(type)
|
333
333
|
short_type = type == "materialized view" ? "mview" : type
|
334
|
-
features = select_values(
|
334
|
+
features = select_values(<<~SQL.squish, "features to drop")
|
335
335
|
SELECT #{short_type}_name FROM all_#{short_type.tableize}
|
336
336
|
where owner = SYS_CONTEXT('userenv', 'current_schema')
|
337
337
|
SQL
|
@@ -342,7 +342,7 @@ module ActiveRecord #:nodoc:
|
|
342
342
|
end
|
343
343
|
|
344
344
|
def drop_sql_for_object(type)
|
345
|
-
objects = select_values(
|
345
|
+
objects = select_values(<<~SQL.squish, "objects to drop")
|
346
346
|
SELECT object_name FROM all_objects
|
347
347
|
WHERE object_type = '#{type.upcase}' and owner = SYS_CONTEXT('userenv', 'current_schema')
|
348
348
|
SQL
|
@@ -269,7 +269,7 @@ module ActiveRecord
|
|
269
269
|
end
|
270
270
|
|
271
271
|
def supports_fetch_first_n_rows_and_offset?
|
272
|
-
if !use_old_oracle_visitor &&
|
272
|
+
if !use_old_oracle_visitor && database_version.first >= 12
|
273
273
|
true
|
274
274
|
else
|
275
275
|
false
|
@@ -285,11 +285,11 @@ module ActiveRecord
|
|
285
285
|
end
|
286
286
|
|
287
287
|
def supports_multi_insert?
|
288
|
-
|
288
|
+
database_version.to_s >= [11, 2].to_s
|
289
289
|
end
|
290
290
|
|
291
291
|
def supports_virtual_columns?
|
292
|
-
|
292
|
+
database_version.first >= 11
|
293
293
|
end
|
294
294
|
|
295
295
|
def supports_json?
|
@@ -324,7 +324,7 @@ module ActiveRecord
|
|
324
324
|
end
|
325
325
|
|
326
326
|
def supports_longer_identifier?
|
327
|
-
if !use_shorter_identifier &&
|
327
|
+
if !use_shorter_identifier && database_version.to_s >= [12, 2].to_s
|
328
328
|
true
|
329
329
|
else
|
330
330
|
false
|
@@ -449,7 +449,7 @@ module ActiveRecord
|
|
449
449
|
# if sequence_name is set to :autogenerated then it means that primary key will be populated by trigger
|
450
450
|
raise ArgumentError "Trigger based primary key is not supported" if sequence_name == AUTOGENERATED_SEQUENCE_NAME
|
451
451
|
# call directly connection method to avoid prepared statement which causes fetching of next sequence value twice
|
452
|
-
select_value(
|
452
|
+
select_value(<<~SQL.squish, "next sequence value")
|
453
453
|
SELECT #{quote_table_name(sequence_name)}.NEXTVAL FROM dual
|
454
454
|
SQL
|
455
455
|
end
|
@@ -487,7 +487,7 @@ module ActiveRecord
|
|
487
487
|
end
|
488
488
|
|
489
489
|
if primary_key && sequence_name
|
490
|
-
new_start_value = select_value(
|
490
|
+
new_start_value = select_value(<<~SQL.squish, "new start value")
|
491
491
|
select NVL(max(#{quote_column_name(primary_key)}),0) + 1 from #{quote_table_name(table_name)}
|
492
492
|
SQL
|
493
493
|
|
@@ -498,32 +498,32 @@ module ActiveRecord
|
|
498
498
|
|
499
499
|
# Current database name
|
500
500
|
def current_database
|
501
|
-
select_value(
|
501
|
+
select_value(<<~SQL.squish, "current database on CDB ")
|
502
502
|
SELECT SYS_CONTEXT('userenv', 'con_name') FROM dual
|
503
503
|
SQL
|
504
504
|
rescue ActiveRecord::StatementInvalid
|
505
|
-
select_value(
|
505
|
+
select_value(<<~SQL.squish, "current database")
|
506
506
|
SELECT SYS_CONTEXT('userenv', 'db_name') FROM dual
|
507
507
|
SQL
|
508
508
|
end
|
509
509
|
|
510
510
|
# Current database session user
|
511
511
|
def current_user
|
512
|
-
select_value(
|
512
|
+
select_value(<<~SQL.squish, "current user")
|
513
513
|
SELECT SYS_CONTEXT('userenv', 'session_user') FROM dual
|
514
514
|
SQL
|
515
515
|
end
|
516
516
|
|
517
517
|
# Current database session schema
|
518
518
|
def current_schema
|
519
|
-
select_value(
|
519
|
+
select_value(<<~SQL.squish, "current schema")
|
520
520
|
SELECT SYS_CONTEXT('userenv', 'current_schema') FROM dual
|
521
521
|
SQL
|
522
522
|
end
|
523
523
|
|
524
524
|
# Default tablespace name of current user
|
525
525
|
def default_tablespace
|
526
|
-
select_value(
|
526
|
+
select_value(<<~SQL.squish, "default tablespace")
|
527
527
|
SELECT LOWER(default_tablespace) FROM user_users
|
528
528
|
WHERE username = SYS_CONTEXT('userenv', 'current_schema')
|
529
529
|
SQL
|
@@ -532,7 +532,7 @@ module ActiveRecord
|
|
532
532
|
def column_definitions(table_name)
|
533
533
|
(owner, desc_table_name) = @connection.describe(table_name)
|
534
534
|
|
535
|
-
select_all(
|
535
|
+
select_all(<<~SQL.squish, "Column definitions")
|
536
536
|
SELECT cols.column_name AS name, cols.data_type AS sql_type,
|
537
537
|
cols.data_default, cols.nullable, cols.virtual_column, cols.hidden_column,
|
538
538
|
cols.data_type_owner AS sql_type_owner,
|
@@ -564,7 +564,7 @@ module ActiveRecord
|
|
564
564
|
def pk_and_sequence_for(table_name, owner = nil, desc_table_name = nil) #:nodoc:
|
565
565
|
(owner, desc_table_name) = @connection.describe(table_name)
|
566
566
|
|
567
|
-
seqs = select_values(
|
567
|
+
seqs = select_values(<<~SQL.squish, "Sequence")
|
568
568
|
select us.sequence_name
|
569
569
|
from all_sequences us
|
570
570
|
where us.sequence_owner = '#{owner}'
|
@@ -572,7 +572,7 @@ module ActiveRecord
|
|
572
572
|
SQL
|
573
573
|
|
574
574
|
# changed back from user_constraints to all_constraints for consistency
|
575
|
-
pks = select_values(
|
575
|
+
pks = select_values(<<~SQL.squish, "Primary Key")
|
576
576
|
SELECT cc.column_name
|
577
577
|
FROM all_constraints c, all_cons_columns cc
|
578
578
|
WHERE c.owner = '#{owner}'
|
@@ -606,7 +606,7 @@ module ActiveRecord
|
|
606
606
|
def primary_keys(table_name) # :nodoc:
|
607
607
|
(_owner, desc_table_name) = @connection.describe(table_name)
|
608
608
|
|
609
|
-
pks = select_values(
|
609
|
+
pks = select_values(<<~SQL.squish, "Primary Keys", [bind_string("table_name", desc_table_name)])
|
610
610
|
SELECT cc.column_name
|
611
611
|
FROM all_constraints c, all_cons_columns cc
|
612
612
|
WHERE c.owner = SYS_CONTEXT('userenv', 'current_schema')
|
@@ -636,7 +636,7 @@ module ActiveRecord
|
|
636
636
|
end
|
637
637
|
|
638
638
|
def temporary_table?(table_name) #:nodoc:
|
639
|
-
select_value(
|
639
|
+
select_value(<<~SQL.squish, "temporary table", [bind_string("table_name", table_name.upcase)]) == "Y"
|
640
640
|
SELECT temporary FROM all_tables WHERE table_name = :table_name and owner = SYS_CONTEXT('userenv', 'current_schema')
|
641
641
|
SQL
|
642
642
|
end
|
@@ -647,15 +647,19 @@ module ActiveRecord
|
|
647
647
|
alias table_alias_length max_identifier_length
|
648
648
|
alias index_name_length max_identifier_length
|
649
649
|
|
650
|
-
|
651
|
-
|
652
|
-
|
650
|
+
def get_database_version
|
651
|
+
@connection.database_version
|
652
|
+
end
|
653
653
|
|
654
|
-
|
655
|
-
|
656
|
-
|
654
|
+
def check_version
|
655
|
+
version = get_database_version.join(".").to_f
|
656
|
+
|
657
|
+
if version < 10
|
658
|
+
raise "Your version of Oracle (#{version}) is too old. Active Record Oracle enhanced adapter supports Oracle >= 10g."
|
657
659
|
end
|
660
|
+
end
|
658
661
|
|
662
|
+
private
|
659
663
|
def initialize_type_map(m = type_map)
|
660
664
|
super
|
661
665
|
# oracle
|
@@ -344,7 +344,7 @@ describe "OracleEnhancedConnection" do
|
|
344
344
|
it "should execute prepared statement with decimal bind parameter " do
|
345
345
|
cursor = @conn.prepare("INSERT INTO test_employees VALUES(:1)")
|
346
346
|
type_metadata = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: "NUMBER", type: :decimal, limit: 10, precision: nil, scale: 2)
|
347
|
-
column = ActiveRecord::ConnectionAdapters::OracleEnhanced::Column.new("age", nil, type_metadata, false,
|
347
|
+
column = ActiveRecord::ConnectionAdapters::OracleEnhanced::Column.new("age", nil, type_metadata, false, comment: nil)
|
348
348
|
expect(column.type).to eq(:decimal)
|
349
349
|
# Here 1.5 expects that this value has been type casted already
|
350
350
|
# it should use bind_params in the long term.
|
@@ -5,23 +5,23 @@ describe "OracleEnhancedAdapter logging dbms_output from plsql" do
|
|
5
5
|
|
6
6
|
before(:all) do
|
7
7
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
8
|
-
ActiveRecord::Base.connection.execute
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
8
|
+
ActiveRecord::Base.connection.execute <<~SQL
|
9
|
+
CREATE or REPLACE
|
10
|
+
FUNCTION MORE_THAN_FIVE_CHARACTERS_LONG (some_text VARCHAR2) RETURN INTEGER
|
11
|
+
AS
|
12
|
+
longer_than_five INTEGER;
|
13
|
+
BEGIN
|
14
|
+
dbms_output.put_line('before the if -' || some_text || '-');
|
15
|
+
IF length(some_text) > 5 THEN
|
16
|
+
dbms_output.put_line('it is longer than 5');
|
17
|
+
longer_than_five := 1;
|
18
|
+
ELSE
|
19
|
+
dbms_output.put_line('it is 5 or shorter');
|
20
|
+
longer_than_five := 0;
|
21
|
+
END IF;
|
22
|
+
dbms_output.put_line('about to return: ' || longer_than_five);
|
23
|
+
RETURN longer_than_five;
|
24
|
+
END;
|
25
25
|
SQL
|
26
26
|
end
|
27
27
|
|
@@ -23,7 +23,7 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
23
23
|
t.timestamps null: true
|
24
24
|
end
|
25
25
|
end
|
26
|
-
@conn.execute
|
26
|
+
@conn.execute <<~SQL
|
27
27
|
CREATE OR REPLACE PACKAGE test_employees_pkg IS
|
28
28
|
PROCEDURE create_employee(
|
29
29
|
p_first_name VARCHAR2,
|
@@ -43,7 +43,7 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
43
43
|
p_employee_id NUMBER);
|
44
44
|
END;
|
45
45
|
SQL
|
46
|
-
@conn.execute
|
46
|
+
@conn.execute <<~SQL
|
47
47
|
CREATE OR REPLACE PACKAGE BODY test_employees_pkg IS
|
48
48
|
PROCEDURE create_employee(
|
49
49
|
p_first_name VARCHAR2,
|
@@ -47,13 +47,13 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should dump composite primary keys" do
|
50
|
-
pk = @conn.send(:select_one,
|
50
|
+
pk = @conn.send(:select_one, <<~SQL)
|
51
51
|
select constraint_name from user_constraints where table_name = 'TEST_POSTS' and constraint_type='P'
|
52
52
|
SQL
|
53
|
-
@conn.execute
|
53
|
+
@conn.execute <<~SQL
|
54
54
|
alter table test_posts drop constraint #{pk["constraint_name"]}
|
55
55
|
SQL
|
56
|
-
@conn.execute
|
56
|
+
@conn.execute <<~SQL
|
57
57
|
ALTER TABLE TEST_POSTS
|
58
58
|
add CONSTRAINT pk_id_title PRIMARY KEY (id, title)
|
59
59
|
SQL
|
@@ -62,7 +62,7 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should dump foreign keys" do
|
65
|
-
@conn.execute
|
65
|
+
@conn.execute <<~SQL
|
66
66
|
ALTER TABLE TEST_POSTS
|
67
67
|
ADD CONSTRAINT fk_test_post_foo FOREIGN KEY (foo_id) REFERENCES foos(id)
|
68
68
|
SQL
|
@@ -74,14 +74,14 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
74
74
|
it "should dump foreign keys when reference column name is not 'id'" do
|
75
75
|
@conn.add_column :foos, :baz_id, :integer
|
76
76
|
|
77
|
-
@conn.execute
|
77
|
+
@conn.execute <<~SQL
|
78
78
|
ALTER TABLE FOOS
|
79
79
|
ADD CONSTRAINT UK_BAZ UNIQUE (BAZ_ID)
|
80
80
|
SQL
|
81
81
|
|
82
82
|
@conn.add_column :test_posts, :baz_id, :integer
|
83
83
|
|
84
|
-
@conn.execute
|
84
|
+
@conn.execute <<~SQL
|
85
85
|
ALTER TABLE TEST_POSTS
|
86
86
|
ADD CONSTRAINT fk_test_post_baz FOREIGN KEY (baz_id) REFERENCES foos(baz_id)
|
87
87
|
SQL
|
@@ -98,7 +98,7 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
it "should dump triggers" do
|
101
|
-
@conn.execute
|
101
|
+
@conn.execute <<~SQL
|
102
102
|
create or replace TRIGGER TEST_POST_TRIGGER
|
103
103
|
BEFORE INSERT
|
104
104
|
ON TEST_POSTS
|
@@ -112,7 +112,7 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
112
112
|
end
|
113
113
|
|
114
114
|
it "should dump types" do
|
115
|
-
@conn.execute
|
115
|
+
@conn.execute <<~SQL
|
116
116
|
create or replace TYPE TEST_TYPE AS TABLE OF VARCHAR2(10);
|
117
117
|
SQL
|
118
118
|
dump = ActiveRecord::Base.connection.structure_dump_db_stored_code.gsub(/\n|\s+/, " ")
|
@@ -128,7 +128,7 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
128
128
|
|
129
129
|
it "should dump virtual columns" do
|
130
130
|
skip "Not supported in this database version" unless @oracle11g_or_higher
|
131
|
-
@conn.execute
|
131
|
+
@conn.execute <<~SQL
|
132
132
|
CREATE TABLE bars (
|
133
133
|
id NUMBER(38,0) NOT NULL,
|
134
134
|
id_plus NUMBER GENERATED ALWAYS AS(id + 2) VIRTUAL,
|
@@ -141,7 +141,7 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
141
141
|
|
142
142
|
it "should dump RAW virtual columns" do
|
143
143
|
skip "Not supported in this database version" unless @oracle11g_or_higher
|
144
|
-
@conn.execute
|
144
|
+
@conn.execute <<~SQL
|
145
145
|
CREATE TABLE bars (
|
146
146
|
id NUMBER(38,0) NOT NULL,
|
147
147
|
super RAW(255) GENERATED ALWAYS AS \( HEXTORAW\(ID\) \) VIRTUAL,
|
@@ -153,7 +153,7 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
153
153
|
end
|
154
154
|
|
155
155
|
it "should dump NCLOB columns" do
|
156
|
-
@conn.execute
|
156
|
+
@conn.execute <<~SQL
|
157
157
|
CREATE TABLE bars (
|
158
158
|
id NUMBER(38,0) NOT NULL,
|
159
159
|
nclob_text NCLOB,
|
@@ -165,7 +165,7 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
165
165
|
end
|
166
166
|
|
167
167
|
it "should dump unique keys" do
|
168
|
-
@conn.execute
|
168
|
+
@conn.execute <<~SQL
|
169
169
|
ALTER TABLE test_posts
|
170
170
|
add CONSTRAINT uk_foo_foo_id UNIQUE (foo, foo_id)
|
171
171
|
SQL
|
@@ -180,7 +180,7 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
180
180
|
ActiveRecord::Base.connection.add_index(:test_posts, :foo, name: :ix_test_posts_foo)
|
181
181
|
ActiveRecord::Base.connection.add_index(:test_posts, :foo_id, name: :ix_test_posts_foo_id, unique: true)
|
182
182
|
|
183
|
-
@conn.execute
|
183
|
+
@conn.execute <<~SQL
|
184
184
|
ALTER TABLE test_posts
|
185
185
|
add CONSTRAINT uk_foo_foo_id UNIQUE (foo, foo_id)
|
186
186
|
SQL
|
@@ -194,7 +194,7 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
194
194
|
it "should dump multi-value and function value indexes" do
|
195
195
|
ActiveRecord::Base.connection.add_index(:test_posts, [:foo, :foo_id], name: :ix_test_posts_foo_foo_id)
|
196
196
|
|
197
|
-
@conn.execute
|
197
|
+
@conn.execute <<~SQL
|
198
198
|
CREATE INDEX "IX_TEST_POSTS_FUNCTION" ON "TEST_POSTS" (TO_CHAR(LENGTH("FOO"))||"FOO")
|
199
199
|
SQL
|
200
200
|
|
@@ -204,7 +204,7 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
204
204
|
end
|
205
205
|
|
206
206
|
it "should dump RAW columns" do
|
207
|
-
@conn.execute
|
207
|
+
@conn.execute <<~SQL
|
208
208
|
CREATE TABLE bars (
|
209
209
|
id NUMBER(38,0) NOT NULL,
|
210
210
|
super RAW(255),
|
@@ -290,7 +290,7 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
290
290
|
|
291
291
|
describe "database structure dump extensions" do
|
292
292
|
before(:all) do
|
293
|
-
@conn.execute
|
293
|
+
@conn.execute <<~SQL
|
294
294
|
CREATE TABLE nvarchartable (
|
295
295
|
unq_nvarchar NVARCHAR2(255) DEFAULT NULL
|
296
296
|
)
|
@@ -394,20 +394,20 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
394
394
|
t.string :foo
|
395
395
|
end
|
396
396
|
# view
|
397
|
-
@conn.execute
|
397
|
+
@conn.execute <<~SQL
|
398
398
|
create or replace view full_drop_test_view (foo) as select id as "foo" from full_drop_test
|
399
399
|
SQL
|
400
400
|
# materialized view
|
401
|
-
@conn.execute
|
401
|
+
@conn.execute <<~SQL
|
402
402
|
create materialized view full_drop_test_mview (foo) as select id as "foo" from full_drop_test
|
403
403
|
SQL
|
404
404
|
# package
|
405
|
-
@conn.execute
|
405
|
+
@conn.execute <<~SQL
|
406
406
|
create or replace package full_drop_test_package as
|
407
407
|
function test_func return varchar2;
|
408
408
|
end test_package;
|
409
409
|
SQL
|
410
|
-
@conn.execute
|
410
|
+
@conn.execute <<~SQL
|
411
411
|
create or replace package body full_drop_test_package as
|
412
412
|
function test_func return varchar2 is
|
413
413
|
begin
|
@@ -416,7 +416,7 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
416
416
|
end test_package;
|
417
417
|
SQL
|
418
418
|
# function
|
419
|
-
@conn.execute
|
419
|
+
@conn.execute <<~SQL
|
420
420
|
create or replace function full_drop_test_function
|
421
421
|
return varchar2
|
422
422
|
is
|
@@ -426,7 +426,7 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
426
426
|
end;
|
427
427
|
SQL
|
428
428
|
# procedure
|
429
|
-
@conn.execute
|
429
|
+
@conn.execute <<~SQL
|
430
430
|
create or replace procedure full_drop_test_procedure
|
431
431
|
begin
|
432
432
|
delete from full_drop_test where id=1231231231
|
@@ -436,11 +436,11 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
436
436
|
end;
|
437
437
|
SQL
|
438
438
|
# synonym
|
439
|
-
@conn.execute
|
439
|
+
@conn.execute <<~SQL
|
440
440
|
create or replace synonym full_drop_test_synonym for full_drop_test
|
441
441
|
SQL
|
442
442
|
# type
|
443
|
-
@conn.execute
|
443
|
+
@conn.execute <<~SQL
|
444
444
|
create or replace type full_drop_test_type as table of number
|
445
445
|
SQL
|
446
446
|
end
|