scenic_oracle_enhanced_adapter 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CHANGELOG +2 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/scenic/adapters/oracle_enhanced/views.rb +80 -0
- data/lib/scenic/adapters/oracle_enhanced.rb +69 -0
- data/lib/scenic_oracle_enhanced_adapter.rb +3 -0
- data/scenic_oracle_enhanced_adapter.gemspec +37 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5bcdb570493bef7acba3abf039b26ba4cabed959feb2f4a3a136511dd9a406ea
|
4
|
+
data.tar.gz: 2da1484c10b74d90bddc038ef5f119b564cc59713c51a08617dea94e27a3f96d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c9ff80955d26f8c73bfe6990283a8eb44835d358185cffd1831d9460bc0b511083a8079af16f57387764b4113a661b5d98d26b4b64b93813a6a03e0d8e3d5b41
|
7
|
+
data.tar.gz: 405cb5cbcfba01e3df57d37d609d86ae9742b2d02e479887dd396ccac19f2ee8b81493927b8b4a11312bbe3671a714e814a0aab5fd1d8052201adae0adc64ea3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Stephen Margheim
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# ScenicOracleEnhancedAdapter
|
2
|
+
|
3
|
+
This gem provides an adapter for the [Scenic gem](https://github.com/thoughtbot/scenic) for use with the [Oracle Enhanced Adapter](https://github.com/rsim/oracle-enhanced/).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'scenic_oracle_enhanced_adapter'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Then add a Scenic initializer (or modify your existing initializer) to make Scenic use this adapter:
|
18
|
+
|
19
|
+
```
|
20
|
+
# config/initializers/scenic.rb
|
21
|
+
|
22
|
+
Scenic.configure do |config|
|
23
|
+
config.database = Scenic::Adapters::OracleEnhanced.new
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
## Switching from rails_sql_views to Scenic
|
28
|
+
|
29
|
+
In Oracle 12, replacing a view has issues when the view refers to objects outside its own schema; use update_view, which will drop and create. The replace_view method can still be used for views referring to objects in their own schema.
|
30
|
+
|
31
|
+
1. Run `bundle exec rails g scenic:view <full_view_name>` (if you use a prefix for the view, include it).
|
32
|
+
1. Move the view's SQL definition from the original migration into the newly-created file in db/views.
|
33
|
+
1. In the original migration, delete any drop_view call.
|
34
|
+
1. Copy the create_view or update_view line from the scenic migration and substitute it for the old create_view method and block.
|
35
|
+
1. Delete the scenic migration file
|
36
|
+
1. For the down method, copy the update_view line into the down (replacing any drop_ and create_view methods) and make the version: argument to the same number as the revert_to_version: argument (e.g. `update_view :complex_data_view, version: 2, revert_to_version: 1` becomes `update_view :complex_data_view, version: 1, revert_to_version: 1`)
|
37
|
+
|
38
|
+
## Development
|
39
|
+
|
40
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
41
|
+
|
42
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/PMACS/scenic_oracle_enhanced_adapter.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'scenic_oracle_enhanced_adapter'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
module Scenic
|
2
|
+
module Adapters
|
3
|
+
class OracleEnhanced
|
4
|
+
class Views
|
5
|
+
def initialize(connection)
|
6
|
+
@connection = connection
|
7
|
+
@current_schema = fetch_current_schema
|
8
|
+
end
|
9
|
+
|
10
|
+
def all
|
11
|
+
views_from_oracle.map(&method(:to_scenic_view))
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
attr_reader :connection,
|
17
|
+
:current_schema
|
18
|
+
|
19
|
+
def fetch_current_schema
|
20
|
+
ActiveRecord::Base.connection
|
21
|
+
.execute("select sys_context('userenv', 'current_schema') from dual")
|
22
|
+
.fetch
|
23
|
+
.first
|
24
|
+
end
|
25
|
+
|
26
|
+
def views_from_oracle
|
27
|
+
# NOTE: Oracle cannot `UNION` on `LONG` fields,
|
28
|
+
# and the `all_mviews.query` field and `all_views.text` field
|
29
|
+
# are both `LONG` fields. Thus, we must use `UNION ALL`.
|
30
|
+
# Luckily, we are not here concerned about duplicates.
|
31
|
+
cursor = ActiveRecord::Base.connection.select_all(<<-SQL)
|
32
|
+
SELECT 'm' AS KIND,
|
33
|
+
mview_name AS VIEWNAME,
|
34
|
+
owner AS NAMESPACE,
|
35
|
+
query AS DEFINITION
|
36
|
+
FROM all_mviews
|
37
|
+
WHERE owner = '#{@current_schema}'
|
38
|
+
UNION ALL
|
39
|
+
SELECT 'v' AS KIND,
|
40
|
+
view_name AS VIEWNAME,
|
41
|
+
owner AS NAMESPACE,
|
42
|
+
text AS DEFINITION
|
43
|
+
FROM all_views
|
44
|
+
WHERE owner = '#{@current_schema}'
|
45
|
+
SQL
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_scenic_view(result)
|
49
|
+
namespace, viewname = result['namespace'], result['viewname']
|
50
|
+
|
51
|
+
if namespace != 'SYS'
|
52
|
+
namespaced_viewname = "#{oracle_identifier(namespace)}.#{oracle_identifier(viewname)}"
|
53
|
+
else
|
54
|
+
namespaced_viewname = oracle_identifier(viewname)
|
55
|
+
end
|
56
|
+
|
57
|
+
Scenic::View.new(
|
58
|
+
name: namespaced_viewname,
|
59
|
+
definition: result['definition'].strip,
|
60
|
+
materialized: result['kind'] == 'm'
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
def oracle_identifier(name)
|
65
|
+
# We've copied this method from the PostgreSQL Scenic adapter.
|
66
|
+
# If the name makes it past the guard clause, the quoted Oracle identifiers
|
67
|
+
# will end up causing the OEA's `describe` method to generate
|
68
|
+
# invalid, improperly quoted object names.
|
69
|
+
#
|
70
|
+
# We don't know where this return value is used so, until we have
|
71
|
+
# an actual use case for a name that makes it past this guard, we
|
72
|
+
# are going to leave this as it is.
|
73
|
+
return name if name =~ /^[a-zA-Z_][a-zA-Z0-9_]*$/
|
74
|
+
|
75
|
+
connection.quote_column_name_or_expression(name)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require_relative 'oracle_enhanced/views'
|
2
|
+
|
3
|
+
module Scenic
|
4
|
+
module Adapters
|
5
|
+
# An adapter for managing Oracle views.
|
6
|
+
class OracleEnhanced
|
7
|
+
def initialize(connectable = ActiveRecord::Base)
|
8
|
+
@connectable = connectable
|
9
|
+
end
|
10
|
+
|
11
|
+
def views
|
12
|
+
Views.new(connection).all
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_view(name, sql_definition)
|
16
|
+
execute "CREATE VIEW #{quote_table_name(name)} AS #{sql_definition}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def update_view(name, sql_definition)
|
20
|
+
drop_view(name)
|
21
|
+
create_view(name, sql_definition)
|
22
|
+
end
|
23
|
+
|
24
|
+
def replace_view(name, sql_definition)
|
25
|
+
execute "CREATE OR REPLACE VIEW #{quote_table_name(name)} AS #{sql_definition}"
|
26
|
+
end
|
27
|
+
|
28
|
+
# `_sql_definition` argument allows `create_view` to be reversed in a migration rollback
|
29
|
+
def drop_view(name, _sql_definition = nil)
|
30
|
+
execute "DROP VIEW #{quote_table_name(name)}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_materialized_view(name, sql_definition)
|
34
|
+
execute "CREATE MATERIALIZED VIEW #{quote_table_name(name)} AS #{sql_definition}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def update_materialized_view(name, sql_definition)
|
38
|
+
# IndexReapplication.new(connection: connection).on(name) do
|
39
|
+
drop_materialized_view(name)
|
40
|
+
create_materialized_view(name, sql_definition)
|
41
|
+
# end
|
42
|
+
end
|
43
|
+
|
44
|
+
# `_sql_definition` argument allows `create_materialized_view` to be reversed in a migration rollback
|
45
|
+
def drop_materialized_view(name, _sql_definition = nil)
|
46
|
+
execute "DROP MATERIALIZED VIEW #{quote_table_name(name)}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def refresh_materialized_view(name, concurrently: false, cascade: false)
|
50
|
+
# refresh_dependencies_for(name) if cascade
|
51
|
+
|
52
|
+
if concurrently
|
53
|
+
execute "REFRESH MATERIALIZED VIEW CONCURRENTLY #{quote_table_name(name)}"
|
54
|
+
else
|
55
|
+
execute "REFRESH MATERIALIZED VIEW #{quote_table_name(name)}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
attr_reader :connectable
|
62
|
+
delegate :execute, :quote_table_name, to: :connection
|
63
|
+
|
64
|
+
def connection
|
65
|
+
connectable.connection
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'scenic_oracle_enhanced_adapter'
|
7
|
+
spec.version = '0.0.2'
|
8
|
+
spec.authors = ['Stephen Margheim']
|
9
|
+
spec.email = ['margheim@mail.med.upenn.edu']
|
10
|
+
|
11
|
+
spec.summary = 'OracleEnhanced adapter for Scenic gem.'
|
12
|
+
spec.homepage = 'https://github.com/PMACS/scenic_oracle_enhanced_adapter'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
16
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
17
|
+
if spec.respond_to?(:metadata)
|
18
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
19
|
+
else
|
20
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
21
|
+
'public gem pushes.'
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
f.match(%r{^(test|spec|features)/})
|
26
|
+
end
|
27
|
+
spec.bindir = 'exe'
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ['lib']
|
30
|
+
|
31
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
32
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
33
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
34
|
+
|
35
|
+
spec.add_dependency 'activerecord', '>= 4.0.0'
|
36
|
+
spec.add_dependency 'scenic', '>= 1.4.0'
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scenic_oracle_enhanced_adapter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stephen Margheim
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-04-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 4.0.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 4.0.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: scenic
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.4.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.4.0
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- margheim@mail.med.upenn.edu
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- CHANGELOG
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- lib/scenic/adapters/oracle_enhanced.rb
|
101
|
+
- lib/scenic/adapters/oracle_enhanced/views.rb
|
102
|
+
- lib/scenic_oracle_enhanced_adapter.rb
|
103
|
+
- scenic_oracle_enhanced_adapter.gemspec
|
104
|
+
homepage: https://github.com/PMACS/scenic_oracle_enhanced_adapter
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata:
|
108
|
+
allowed_push_host: https://rubygems.org
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubygems_version: 3.0.3.1
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: OracleEnhanced adapter for Scenic gem.
|
128
|
+
test_files: []
|