activerecord-oracle_enhanced-adapter 1.6.4 → 1.6.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3140aab4b8a424d37dbf40c830b1078da12c520a
4
- data.tar.gz: 5a4dda72b35ed5f9578ec10b21b2bf647ce3dd48
3
+ metadata.gz: 60a3ec980dcf98f634383b6ae254f5de37b549f7
4
+ data.tar.gz: d217ce9bc4b2ee4352746ca29eae5c639496b92f
5
5
  SHA512:
6
- metadata.gz: 8b966b3ee7215ae2b724667d0eb929fdd2c2e5d7d8b98f7bfdcd66490e3a7fa7907dfbc1c3ec23fe42c358b7509a7035f67ad9b1d0815738f8d6cde248d72e34
7
- data.tar.gz: 69feaef9c100e36ef781663aaaf98dafa72ee8f30d34b83611015da18311381bacec12c7ff97e846829076e4c9f9c411aeca1994478f3cb09bfd8fabb049889a
6
+ metadata.gz: 091010e46da037032c6714d2522c9097dbb3acd156a9ebecd240fc9154c73163f4e84e0e996ddbe27ae0ca64e2f13261370d61825aca3ab20fd997602362e3fc
7
+ data.tar.gz: 81622c33e2565fbe6292aa70214f865db3dd9d3cb623aac56ae65ebf7669e911e09a6c6251503654e5ce893c34b56e140d105def665be8fa6dc58e68e5fa215a
data/History.md CHANGED
@@ -1,6 +1,11 @@
1
+ ## 1.6.5 / 2015-12-01
2
+
3
+ * Enhancement
4
+ * Support `schema` option to use schema objects owned by another schema[#742]
5
+
1
6
  ## 1.6.4 / 2015-11-09
2
7
 
3
- * Changes and bug fixes since 1.6.2
8
+ * Changes and bug fixes since 1.6.3
4
9
  * Add table and column comments to structure dump and schema dump [#734]
5
10
  * Remove `serialized_attributes` which is removed in Rails 5 [#694]
6
11
  * fixing bundler dependency conflict with head of rails vs arel 6.0[#714]
data/README.md CHANGED
@@ -489,6 +489,23 @@ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces =
489
489
  {:clob => 'TS_LOB', :blob => 'TS_LOB', :index => 'TS_INDEX', :table => 'TS_DATA'}
490
490
  ```
491
491
 
492
+ ### Switching to another schema
493
+
494
+ There are some requirements to connect to Oracle database first and switch to another user.
495
+ Oracle enhanced adapter supports schema: option.
496
+
497
+ Note: Oracle enhanced adapter does not take care if the database user specified in username: parameter
498
+ has appropriate privilege to select, insert, update and delete database objects owned by the schema specified in schema: parameter.
499
+
500
+ ```yml
501
+ development:
502
+ adapter: oracle_enhanced
503
+ database: xe
504
+ username: user
505
+ password: secret
506
+ schema: tableowner
507
+ ```
508
+
492
509
  TROUBLESHOOTING
493
510
  ---------------
494
511
 
@@ -26,6 +26,9 @@ Running tests
26
26
  SQL> CREATE USER oracle_enhanced IDENTIFIED BY oracle_enhanced;
27
27
  SQL> GRANT unlimited tablespace, create session, create table, create sequence, create procedure, create trigger, create view, create materialized view, create database link, create synonym, create type, ctxapp TO oracle_enhanced;
28
28
 
29
+ SQL> CREATE USER oracle_enhanced_schema IDENTIFIED BY oracle_enhanced_schema;
30
+ SQL> GRANT unlimited tablespace, create session, create table, create sequence, create procedure, create trigger, create view, create materialized view, create database link, create synonym, create type, ctxapp TO oracle_enhanced_schema;
31
+
29
32
  * If you use RVM then switch to corresponding Ruby (1.8.7, 1.9.2 or JRuby) and it is recommended to create isolated gemset for test purposes (e.g. rvm create gemset oracle_enhanced)
30
33
 
31
34
  * Install bundler with
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.4
1
+ 1.6.5
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{activerecord-oracle_enhanced-adapter}
8
- s.version = "1.6.4"
8
+ s.version = "1.6.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.license = 'MIT'
12
12
  s.authors = [%q{Raimonds Simanovskis}]
13
- s.date = %q{2015-11-09}
13
+ s.date = %q{2015-12-01}
14
14
  s.description = %q{Oracle "enhanced" ActiveRecord adapter contains useful additional methods for working with new and legacy Oracle databases.
15
15
  This adapter is superset of original ActiveRecord Oracle adapter.
16
16
  }
@@ -159,8 +159,14 @@ module ActiveRecord
159
159
 
160
160
  self.autocommit = true
161
161
 
162
- # default schema owner
163
- @owner = username.upcase unless username.nil?
162
+ schema = config[:schema] && config[:schema].to_s
163
+ if schema.blank?
164
+ # default schema owner
165
+ @owner = username.upcase unless username.nil?
166
+ else
167
+ exec "alter session set current_schema = #{schema}"
168
+ @owner = schema
169
+ end
164
170
 
165
171
  @raw_connection
166
172
  end
@@ -25,7 +25,9 @@ module ActiveRecord
25
25
  def initialize(config)
26
26
  @raw_connection = OCI8EnhancedAutoRecover.new(config, OracleEnhancedOCIFactory)
27
27
  # default schema owner
28
- @owner = config[:username].to_s.upcase
28
+ @owner = config[:schema]
29
+ @owner ||= config[:username]
30
+ @owner = @owner.to_s.upcase
29
31
  end
30
32
 
31
33
  def raw_oci_connection
@@ -306,6 +308,7 @@ module ActiveRecord
306
308
  username = config[:username] && config[:username].to_s
307
309
  password = config[:password] && config[:password].to_s
308
310
  database = config[:database] && config[:database].to_s
311
+ schema = config[:schema] && config[:schema].to_s
309
312
  host, port = config[:host], config[:port]
310
313
  privilege = config[:privilege] && config[:privilege].to_sym
311
314
  async = config[:allow_concurrency]
@@ -333,6 +336,7 @@ module ActiveRecord
333
336
  conn.prefetch_rows = prefetch_rows
334
337
  conn.exec "alter session set cursor_sharing = #{cursor_sharing}" rescue nil
335
338
  conn.exec "alter session set time_zone = '#{time_zone}'" unless time_zone.blank?
339
+ conn.exec "alter session set current_schema = #{schema}" unless schema.blank?
336
340
 
337
341
  # Initialize NLS parameters
338
342
  OracleEnhancedAdapter::DEFAULT_NLS_PARAMETERS.each do |key, default_value|
@@ -10,7 +10,7 @@ module ActiveRecord #:nodoc:
10
10
  "CREATE SEQUENCE \"#{seq}\""
11
11
  end
12
12
  select_values("SELECT table_name FROM all_tables t
13
- WHERE owner = SYS_CONTEXT('userenv', 'session_user') AND secondary = 'N'
13
+ WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N'
14
14
  AND NOT EXISTS (SELECT mv.mview_name FROM all_mviews mv WHERE mv.owner = t.owner AND mv.mview_name = t.table_name)
15
15
  AND NOT EXISTS (SELECT mvl.log_table FROM all_mview_logs mvl WHERE mvl.log_owner = t.owner AND mvl.log_table = t.table_name)
16
16
  ORDER BY 1").each do |table_name|
@@ -79,7 +79,7 @@ module ActiveRecord #:nodoc:
79
79
  ON a.constraint_name = c.constraint_name
80
80
  WHERE c.table_name = '#{table.upcase}'
81
81
  AND c.constraint_type = 'P'
82
- AND c.owner = SYS_CONTEXT('userenv', 'session_user')
82
+ AND c.owner = SYS_CONTEXT('userenv', 'current_schema')
83
83
  SQL
84
84
  pks.each do |row|
85
85
  opts[:name] = row['constraint_name']
@@ -97,7 +97,7 @@ module ActiveRecord #:nodoc:
97
97
  ON a.constraint_name = c.constraint_name
98
98
  WHERE c.table_name = '#{table.upcase}'
99
99
  AND c.constraint_type = 'U'
100
- AND c.owner = SYS_CONTEXT('userenv', 'session_user')
100
+ AND c.owner = SYS_CONTEXT('userenv', 'current_schema')
101
101
  SQL
102
102
  uks.each do |uk|
103
103
  keys[uk['constraint_name']] ||= []
@@ -125,7 +125,7 @@ module ActiveRecord #:nodoc:
125
125
  end
126
126
 
127
127
  def structure_dump_fk_constraints #:nodoc:
128
- fks = select_all("SELECT table_name FROM all_tables WHERE owner = SYS_CONTEXT('userenv', 'session_user') ORDER BY 1").map do |table|
128
+ fks = select_all("SELECT table_name FROM all_tables WHERE owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1").map do |table|
129
129
  if respond_to?(:foreign_keys) && (foreign_keys = foreign_keys(table["table_name"])).any?
130
130
  foreign_keys.map do |fk|
131
131
  sql = "ALTER TABLE #{quote_table_name(fk.from_table)} ADD CONSTRAINT #{quote_column_name(fk.options[:name])} "
@@ -196,14 +196,14 @@ module ActiveRecord #:nodoc:
196
196
  FROM all_source
197
197
  WHERE type IN ('PROCEDURE', 'PACKAGE', 'PACKAGE BODY', 'FUNCTION', 'TRIGGER', 'TYPE')
198
198
  AND name NOT LIKE 'BIN$%'
199
- AND owner = SYS_CONTEXT('userenv', 'session_user') ORDER BY type").each do |source|
199
+ AND owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY type").each do |source|
200
200
  ddl = "CREATE OR REPLACE \n"
201
201
  select_all(%Q{
202
202
  SELECT text
203
203
  FROM all_source
204
204
  WHERE name = '#{source['name']}'
205
205
  AND type = '#{source['type']}'
206
- AND owner = SYS_CONTEXT('userenv', 'session_user')
206
+ AND owner = SYS_CONTEXT('userenv', 'current_schema')
207
207
  ORDER BY line
208
208
  }).each do |row|
209
209
  ddl << row['text']
@@ -220,7 +220,7 @@ module ActiveRecord #:nodoc:
220
220
  # export synonyms
221
221
  select_all("SELECT owner, synonym_name, table_name, table_owner
222
222
  FROM all_synonyms
223
- WHERE owner = SYS_CONTEXT('userenv', 'session_user') ").each do |synonym|
223
+ WHERE owner = SYS_CONTEXT('userenv', 'current_schema') ").each do |synonym|
224
224
  structure << "CREATE OR REPLACE #{synonym['owner'] == 'PUBLIC' ? 'PUBLIC' : '' } SYNONYM #{synonym['synonym_name']}
225
225
  FOR #{synonym['table_owner']}.#{synonym['table_name']}"
226
226
  end
@@ -233,7 +233,7 @@ module ActiveRecord #:nodoc:
233
233
  "DROP SEQUENCE \"#{seq}\""
234
234
  end
235
235
  select_values("SELECT table_name from all_tables t
236
- WHERE owner = SYS_CONTEXT('userenv', 'session_user') AND secondary = 'N'
236
+ WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N'
237
237
  AND NOT EXISTS (SELECT mv.mview_name FROM all_mviews mv WHERE mv.owner = t.owner AND mv.mview_name = t.table_name)
238
238
  AND NOT EXISTS (SELECT mvl.log_table FROM all_mview_logs mvl WHERE mvl.log_owner = t.owner AND mvl.log_table = t.table_name)
239
239
  ORDER BY 1").each do |table|
@@ -245,7 +245,7 @@ module ActiveRecord #:nodoc:
245
245
  def temp_table_drop #:nodoc:
246
246
  join_with_statement_token(select_values(
247
247
  "SELECT table_name FROM all_tables
248
- WHERE owner = SYS_CONTEXT('userenv', 'session_user') AND secondary = 'N' AND temporary = 'Y' ORDER BY 1").map do |table|
248
+ WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N' AND temporary = 'Y' ORDER BY 1").map do |table|
249
249
  "DROP TABLE \"#{table}\" CASCADE CONSTRAINTS"
250
250
  end)
251
251
  end
@@ -849,14 +849,19 @@ module ActiveRecord
849
849
  select_value("SELECT SYS_CONTEXT('userenv', 'session_user') FROM dual")
850
850
  end
851
851
 
852
+ # Current database session schema
853
+ def current_schema
854
+ select_value("SELECT SYS_CONTEXT('userenv', 'current_schema') FROM dual")
855
+ end
856
+
852
857
  # Default tablespace name of current user
853
858
  def default_tablespace
854
- select_value("SELECT LOWER(default_tablespace) FROM user_users WHERE username = SYS_CONTEXT('userenv', 'session_user')")
859
+ select_value("SELECT LOWER(default_tablespace) FROM user_users WHERE username = SYS_CONTEXT('userenv', 'current_schema')")
855
860
  end
856
861
 
857
862
  def tables(name = nil) #:nodoc:
858
863
  select_values(
859
- "SELECT DECODE(table_name, UPPER(table_name), LOWER(table_name), table_name) FROM all_tables WHERE owner = SYS_CONTEXT('userenv', 'session_user') AND secondary = 'N'",
864
+ "SELECT DECODE(table_name, UPPER(table_name), LOWER(table_name), table_name) FROM all_tables WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N'",
860
865
  name)
861
866
  end
862
867
 
@@ -869,7 +874,7 @@ module ActiveRecord
869
874
  end
870
875
 
871
876
  def materialized_views #:nodoc:
872
- select_values("SELECT LOWER(mview_name) FROM all_mviews WHERE owner = SYS_CONTEXT('userenv', 'session_user')")
877
+ select_values("SELECT LOWER(mview_name) FROM all_mviews WHERE owner = SYS_CONTEXT('userenv', 'current_schema')")
873
878
  end
874
879
 
875
880
  cattr_accessor :all_schema_indexes #:nodoc:
@@ -35,6 +35,30 @@ describe "OracleEnhancedConnection" do
35
35
 
36
36
  end
37
37
 
38
+ describe "create connection with schema option" do
39
+ before(:all) do
40
+ @conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_WITH_SCHEMA_PARAMS)
41
+ end
42
+
43
+ before(:each) do
44
+ @conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_WITH_SCHEMA_PARAMS) unless @conn.active?
45
+ end
46
+
47
+ it "should create new connection" do
48
+ @conn.should be_active
49
+ end
50
+
51
+ it "should swith to specified schema" do
52
+ @conn.select_value("select SYS_CONTEXT('userenv', 'current_schema') from dual").should == CONNECTION_WITH_SCHEMA_PARAMS[:schema].upcase
53
+ end
54
+
55
+ it "should swith to specified schema after reset" do
56
+ @conn.reset!
57
+ @conn.select_value("select SYS_CONTEXT('userenv', 'current_schema') from dual").should == CONNECTION_WITH_SCHEMA_PARAMS[:schema].upcase
58
+ end
59
+
60
+ end
61
+
38
62
  describe "create connection with NLS parameters" do
39
63
  after do
40
64
  ENV['NLS_DATE_FORMAT'] = nil
@@ -125,6 +125,7 @@ DATABASE_HOST = config["database"]["host"] || ENV['DATABASE_HOST
125
125
  DATABASE_PORT = config["database"]["port"] || ENV['DATABASE_PORT'] || 1521
126
126
  DATABASE_USER = config["database"]["user"] || ENV['DATABASE_USER'] || 'oracle_enhanced'
127
127
  DATABASE_PASSWORD = config["database"]["password"] || ENV['DATABASE_PASSWORD'] || 'oracle_enhanced'
128
+ DATABASE_SCHEMA = config["database"]["schema"] || ENV['DATABASE_SCHEMA'] || 'oracle_enhanced_schema'
128
129
  DATABASE_SYS_PASSWORD = config["database"]["sys_password"] || ENV['DATABASE_SYS_PASSWORD'] || 'admin'
129
130
 
130
131
  CONNECTION_PARAMS = {
@@ -136,6 +137,16 @@ CONNECTION_PARAMS = {
136
137
  :password => DATABASE_PASSWORD
137
138
  }
138
139
 
140
+ CONNECTION_WITH_SCHEMA_PARAMS = {
141
+ :adapter => "oracle_enhanced",
142
+ :database => DATABASE_NAME,
143
+ :host => DATABASE_HOST,
144
+ :port => DATABASE_PORT,
145
+ :username => DATABASE_USER,
146
+ :password => DATABASE_PASSWORD,
147
+ :schema => DATABASE_SCHEMA
148
+ }
149
+
139
150
  SYS_CONNECTION_PARAMS = {
140
151
  :adapter => "oracle_enhanced",
141
152
  :database => DATABASE_NAME,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-oracle_enhanced-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.4
4
+ version: 1.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raimonds Simanovskis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-09 00:00:00.000000000 Z
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jeweler