scenic-oracle_adapter 0.2.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9409f3d5fb8a10fc6fed5fcd1501d0034ad2fa4a383733b1ff9a6818660576ff
4
- data.tar.gz: 42256bb731d54eb934e7dd7cbc7abe4ef353f401e7c7b222cda5b30fd6a885b0
3
+ metadata.gz: 2a6654ada5f4a3b75d1a5539be516cbd673f9db9d19a267984d0262ad0909a4d
4
+ data.tar.gz: 306b5811810f316b451312e5a86428469fa2348fcf9ef3a13a1503519b9c4e2d
5
5
  SHA512:
6
- metadata.gz: c8486a41a221db67a984b06f5dfe9c754019f5c759bc540f47d5932991c97982fe9bb80fe20157a12854c51fa9f0e149a6956990ab2a13dd3b5a2b90b3106376
7
- data.tar.gz: 583843437bf27efafc5bf84e1cff91b5ca23b3e4f0b169fc53ceaef8ab8dd31d5214bb7ead2e1ca0103edcf5e1120a187a810961ec1250c3f18161e393653e92
6
+ metadata.gz: 918aa48ce7550cc4452c60bef6690661ddf09ad1a54f64ede2d523063b182fbe1ab807d300b9f31b212add47d87b952098ce362334f42a34b56c4a4dbb60f2af
7
+ data.tar.gz: 57c3671d477de89604300cf17462cf411f63b8b465cfd923d3bfefee44be82ff871cc967292b91f6ec1fcac2630ebcb5e6f81e4894541400e931ea6c6127ba2c
@@ -0,0 +1,19 @@
1
+ name: CI
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+
7
+ build:
8
+
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - name: Login to Docker Hub
14
+ uses: docker/login-action@v1
15
+ with:
16
+ username: ${{ secrets.DOCKER_HUB_USERNAME }}
17
+ password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
18
+ - name: Run tests
19
+ run: docker-compose run gem rspec
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: "2.3"
2
+ TargetRubyVersion: "2.5"
3
3
 
4
4
  # Use double quotes
5
5
  Style/StringLiterals:
data/Dockerfile ADDED
@@ -0,0 +1,18 @@
1
+ FROM ruby:latest
2
+
3
+ RUN curl -sLO 'https://download.oracle.com/otn_software/linux/instantclient/19600/instantclient-basic-linux.x64-19.6.0.0.0dbru.zip' && \
4
+ curl -sLO 'https://download.oracle.com/otn_software/linux/instantclient/19600/instantclient-sdk-linux.x64-19.6.0.0.0dbru.zip' && \
5
+ unzip instantclient-basic-linux.x64-19.6.0.0.0dbru.zip && \
6
+ unzip instantclient-sdk-linux.x64-19.6.0.0.0dbru.zip && \
7
+ rm instantclient-basic-linux.x64-19.6.0.0.0dbru.zip && \
8
+ rm instantclient-sdk-linux.x64-19.6.0.0.0dbru.zip
9
+
10
+ RUN apt update && \
11
+ apt-get install libaio1
12
+
13
+ ENV LD_LIBRARY_PATH /instantclient_19_6:$LD_LIBRARY_PATH
14
+
15
+ RUN mkdir /app
16
+ WORKDIR /app
17
+ COPY . /app
18
+ RUN bundle install
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # scenic-oracle_adapter [![Build Status](https://travis-ci.org/cdinger/scenic-oracle_adapter.svg?branch=master)](https://travis-ci.org/cdinger/scenic-oracle_adapter)
1
+ # scenic-oracle_adapter [![Build Status](https://github.com/cdinger/scenic-oracle_adapter/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/cdinger/scenic-oracle_adapter/actions/workflows/ci.yml?query=branch%3Amaster)
2
2
 
3
- An Oracle adapter for Thoughtbot's [scenic](https://github.com/thoughtbot/scenic) rubygem.
3
+ An Oracle adapter for the [scenic](https://github.com/scenic-views/scenic) rubygem.
4
4
 
5
5
  ## Installation
6
6
 
@@ -26,13 +26,19 @@ end
26
26
 
27
27
  ## Development
28
28
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/test` (or `rspec`) to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+ While you can use any Oracle instance for development, it's easiest to use Docker and docker-compose.
30
30
 
31
- By default, the test suite will attempt to connect to a local XE instance (see `spec/spec_helper.rb` for connection details).
32
- You can override the database URL by supplying a value to the `DATABASE_URL` environment variable.
31
+ Note that the Oracle container takes up to two minutes to start and become available. If you're doing active development you probably want to start the containers in detached mode: `docker-compose up -d`. This starts everything in the background and allows you to use `docker-compose exec` to run commands on the already running containers:
32
+
33
+ - Run specs: `docker-compose exec gem bin/test`
34
+ - Open a console: `docker-compose exec gem bin/console`
35
+
36
+ ## Tests
33
37
 
34
- If you don't have a test Oracle database available, you can use [oracle-dev-box](https://github.com/cdinger/oracle-dev-box) to
35
- run an XE instance in Vagrant.
38
+ If you just want to run the test suite you can use `docker-compose run --rm gem bin/test`. Again, because the Oracle container takes so long to start up, the first execution will take a while. The test suite will wait for the database container to become available. Subsequent executions will be faster.
39
+
40
+ By default, the test suite will attempt to connect to a local docker Oracle instance (see `spec/spec_helper.rb` for connection details).
41
+ You can override the database URL by supplying a value to the `DATABASE_URL` environment variable.
36
42
 
37
43
  ## Contributing
38
44
 
@@ -0,0 +1,20 @@
1
+ version: '3'
2
+ services:
3
+ db:
4
+ image: store/oracle/database-enterprise:12.2.0.1
5
+ volumes:
6
+ - db:/ORCL
7
+ ports:
8
+ - 1521:1521
9
+ gem:
10
+ build: .
11
+ volumes:
12
+ - .:/app
13
+ environment:
14
+ - TERM=dumb
15
+ stdin_open: true
16
+ tty: true
17
+ depends_on:
18
+ - db
19
+ volumes:
20
+ db:
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "oracle/index_reapplication"
4
4
  require_relative "oracle/indexes"
5
+ require_relative "oracle/refresh_dependencies"
5
6
 
6
7
  module Scenic
7
8
  module Adapters
@@ -31,8 +32,8 @@ module Scenic
31
32
  create_view(name, definition)
32
33
  end
33
34
 
34
- def create_materialized_view(name, definition)
35
- execute("create materialized view #{quote_table_name(name)} as #{definition}")
35
+ def create_materialized_view(name, definition, no_data: false)
36
+ execute("create materialized view #{quote_table_name(name)} #{'build deferred' if no_data} as #{definition}")
36
37
  end
37
38
 
38
39
  def update_materialized_view(name, definition)
@@ -46,7 +47,9 @@ module Scenic
46
47
  execute("drop materialized view #{quote_table_name(name)}")
47
48
  end
48
49
 
49
- def refresh_materialized_view(name, concurrently: false)
50
+ def refresh_materialized_view(name, concurrently: false, cascade: false)
51
+ refresh_dependencies_for(name) if cascade
52
+
50
53
  atomic_refresh = concurrently.to_s.upcase
51
54
  execute(<<~EOSQL)
52
55
  begin
@@ -71,6 +74,10 @@ module Scenic
71
74
  Scenic::View.new(name: view["name"], definition: view["definition"], materialized: true)
72
75
  end
73
76
  end
77
+
78
+ def refresh_dependencies_for(name)
79
+ Scenic::Adapters::Oracle::RefreshDependencies.call(name, self, connection)
80
+ end
74
81
  end
75
82
  end
76
83
  end
@@ -23,9 +23,8 @@ module Scenic
23
23
 
24
24
  def try_index_create(index)
25
25
  if valid_index?(index)
26
- if connection.execute(index.definition)
27
- say "index '#{index.index_name}' on '#{index.object_name}' has been recreated"
28
- end
26
+ connection.execute(index.definition) &&
27
+ say("index '#{index.index_name}' on '#{index.object_name}' has been recreated")
29
28
  else
30
29
  say "index '#{index.index_name}' on '#{index.object_name}' is no longer valid and has been dropped."
31
30
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tsort"
4
+
5
+ module Scenic
6
+ module Adapters
7
+ class Oracle
8
+ class RefreshDependencies
9
+ def self.call(name, adapter, connection)
10
+ new(name, adapter, connection).call
11
+ end
12
+
13
+ def initialize(name, adapter, connection)
14
+ @name = name
15
+ @adapter = adapter
16
+ @connection = connection
17
+ end
18
+
19
+ def call
20
+ dependencies.each do |dependency|
21
+ adapter.refresh_materialized_view(dependency)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :name, :adapter, :connection
28
+
29
+ def dependencies
30
+ d = dependency_tree_for(@name)
31
+ each_node = ->(&b) { d.each_key(&b) }
32
+ each_child = ->(n, &b) { d[n].each(&b) }
33
+ TSort.tsort(each_node, each_child) - [@name]
34
+ end
35
+
36
+ def dependency_tree_for(name, tree = {})
37
+ ds = connection.select_values(<<~EOSQL)
38
+ select referenced_name
39
+ from user_dependencies
40
+ where name = '#{name.upcase}'
41
+ and referenced_type = 'MATERIALIZED VIEW'
42
+ EOSQL
43
+
44
+ tree[name.downcase.to_sym] = Array(ds).map { |x| x.downcase.to_sym }
45
+ ds.each { |d| dependency_tree_for(d, tree) }
46
+ tree
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Scenic
4
4
  module OracleAdapter
5
- VERSION = "0.2.0"
5
+ VERSION = "1.1.0"
6
6
  end
7
7
  end
@@ -22,12 +22,12 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_dependency "scenic", "~> 1.4.1"
25
+ spec.add_dependency "scenic", "~> 1.5.4"
26
26
  spec.add_dependency "activerecord-oracle_enhanced-adapter", ">= 1.5.0"
27
- spec.add_dependency "ruby-oci8", "~> 2.2"
28
27
 
29
- spec.add_development_dependency "bundler", "~> 1.16"
30
- spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "bundler", "~> 2.0"
29
+ spec.add_development_dependency "rake", ">= 12.3.3"
31
30
  spec.add_development_dependency "rspec", "~> 3.0"
32
31
  spec.add_development_dependency "rubocop", ">= 0.49.0"
32
+ spec.add_development_dependency "ruby-oci8", "~> 2.2"
33
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scenic-oracle_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Dinger
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-24 00:00:00.000000000 Z
11
+ date: 2021-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: scenic
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.4.1
19
+ version: 1.5.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.4.1
26
+ version: 1.5.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord-oracle_enhanced-adapter
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,48 +38,34 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.5.0
41
- - !ruby/object:Gem::Dependency
42
- name: ruby-oci8
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '2.2'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '2.2'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: bundler
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '1.16'
47
+ version: '2.0'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '1.16'
54
+ version: '2.0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rake
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - "~>"
59
+ - - ">="
74
60
  - !ruby/object:Gem::Version
75
- version: '10.0'
61
+ version: 12.3.3
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - "~>"
66
+ - - ">="
81
67
  - !ruby/object:Gem::Version
82
- version: '10.0'
68
+ version: 12.3.3
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: rspec
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -108,21 +94,33 @@ dependencies:
108
94
  - - ">="
109
95
  - !ruby/object:Gem::Version
110
96
  version: 0.49.0
111
- description:
97
+ - !ruby/object:Gem::Dependency
98
+ name: ruby-oci8
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.2'
111
+ description:
112
112
  email:
113
113
  - chris@houseofding.com
114
114
  executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".github/workflows/ci.yml"
118
119
  - ".gitignore"
119
120
  - ".rspec"
120
121
  - ".rubocop.yml"
121
- - ".travis.yml"
122
- - ".travis/oracle/download.sh"
123
- - ".travis/oracle/install.sh"
124
- - ".travis/setup_accounts.sh"
125
122
  - CODE_OF_CONDUCT.md
123
+ - Dockerfile
126
124
  - Gemfile
127
125
  - LICENSE.txt
128
126
  - README.md
@@ -130,11 +128,13 @@ files:
130
128
  - bin/console
131
129
  - bin/setup
132
130
  - bin/test
131
+ - docker-compose.yml
133
132
  - lib/scenic/adapters/oracle.rb
134
133
  - lib/scenic/adapters/oracle/index.rb
135
134
  - lib/scenic/adapters/oracle/index_reapplication.rb
136
135
  - lib/scenic/adapters/oracle/indexes.rb
137
136
  - lib/scenic/adapters/oracle/railtie.rb
137
+ - lib/scenic/adapters/oracle/refresh_dependencies.rb
138
138
  - lib/scenic/oracle_adapter.rb
139
139
  - lib/scenic/oracle_adapter/version.rb
140
140
  - scenic-oracle_adapter.gemspec
@@ -142,7 +142,7 @@ homepage: https://github.com/cdinger/scenic-oracle_adapter
142
142
  licenses:
143
143
  - MIT
144
144
  metadata: {}
145
- post_install_message:
145
+ post_install_message:
146
146
  rdoc_options: []
147
147
  require_paths:
148
148
  - lib
@@ -157,9 +157,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  - !ruby/object:Gem::Version
158
158
  version: '0'
159
159
  requirements: []
160
- rubyforge_project:
161
- rubygems_version: 2.7.6
162
- signing_key:
160
+ rubygems_version: 3.1.2
161
+ signing_key:
163
162
  specification_version: 4
164
163
  summary: Oracle adapter for thoughtbot/scenic
165
164
  test_files: []
data/.travis.yml DELETED
@@ -1,41 +0,0 @@
1
- ---
2
- dist: trusty
3
- sudo: required
4
- language: ruby
5
- cache: bundler
6
- rvm:
7
- - 2.3
8
- - 2.4
9
- - 2.5
10
-
11
- env:
12
- global:
13
- - ORACLE_FILE=oracle11g/xe/oracle-xe-11.2.0-1.0.x86_64.rpm.zip
14
- - ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
15
- - TNS_ADMIN=$ORACLE_HOME/network/admin
16
- - NLS_LANG=AMERICAN_AMERICA.AL32UTF8
17
- - ORACLE_BASE=/u01/app/oracle
18
- - LD_LIBRARY_PATH=$ORACLE_HOME/lib
19
- - PATH=$PATH:$ORACLE_HOME/jdbc/lib
20
- - DATABASE_VERSION=11.2.0.1
21
- - ORACLE_SID=XE
22
- - DATABASE_NAME=XE
23
-
24
- before_install:
25
- - chmod +x .travis/oracle/download.sh
26
- - chmod +x .travis/oracle/install.sh
27
- - chmod +x .travis/setup_accounts.sh
28
- - gem install bundler -v 1.16.5
29
-
30
- install:
31
- - .travis/oracle/download.sh
32
- - .travis/oracle/install.sh
33
- - .travis/setup_accounts.sh
34
- - bundle install
35
-
36
- jobs:
37
- include:
38
- - stage: Static analysis
39
- script: bundle exec rubocop lib
40
- - stage: Test
41
- script: bundle exec rspec
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- cd "$(dirname "$(readlink -f "$0")")"
4
-
5
- deb_file=oracle-xe_11.2.0-1.0_amd64.deb
6
-
7
- git clone https://github.com/wnameless/docker-oracle-xe-11g.git
8
-
9
- cd docker-oracle-xe-11g/assets &&
10
- cat "${deb_file}aa" "${deb_file}ab" "${deb_file}ac" > "${deb_file}"
11
-
12
- pwd
13
-
14
- ls -lAh "${deb_file}"
@@ -1,33 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- [ -n "$ORACLE_FILE" ] || { echo "Missing ORACLE_FILE environment variable!"; exit 1; }
4
- [ -n "$ORACLE_HOME" ] || { echo "Missing ORACLE_HOME environment variable!"; exit 1; }
5
-
6
- cd "$(dirname "$(readlink -f "$0")")"
7
-
8
- ORACLE_DEB=docker-oracle-xe-11g/assets/oracle-xe_11.2.0-1.0_amd64.deb
9
-
10
- sudo apt-get -qq update
11
- sudo apt-get --no-install-recommends -qq install bc libaio1
12
-
13
- df -B1 /dev/shm | awk 'END { if ($1 != "shmfs" && $1 != "tmpfs" || $2 < 2147483648) exit 1 }' ||
14
- ( sudo rm -r /dev/shm && sudo mkdir /dev/shm && sudo mount -t tmpfs shmfs -o size=2G /dev/shm )
15
-
16
- test -f /sbin/chkconfig ||
17
- ( echo '#!/bin/sh' | sudo tee /sbin/chkconfig > /dev/null && sudo chmod u+x /sbin/chkconfig )
18
-
19
- test -d /var/lock/subsys || sudo mkdir /var/lock/subsys
20
-
21
- sudo dpkg -i "${ORACLE_DEB}"
22
-
23
- echo 'OS_AUTHENT_PREFIX=""' | sudo tee -a "$ORACLE_HOME/config/scripts/init.ora" > /dev/null
24
- echo 'disk_asynch_io=false' | sudo tee -a "$ORACLE_HOME/config/scripts/init.ora" > /dev/null
25
-
26
- sudo usermod -aG dba $USER
27
-
28
- ( echo ; echo ; echo travis ; echo travis ; echo n ) | sudo AWK='/usr/bin/awk' /etc/init.d/oracle-xe configure
29
-
30
- "$ORACLE_HOME/bin/sqlplus" -L -S / AS SYSDBA <<SQL
31
- CREATE USER $USER IDENTIFIED EXTERNALLY;
32
- GRANT CONNECT, RESOURCE TO $USER;
33
- SQL
@@ -1,14 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -ev
4
-
5
- "$ORACLE_HOME/bin/sqlplus" -L -S / AS SYSDBA <<SQL
6
- alter user sys identified by admin;
7
- alter user system identified by admin;
8
- alter database default tablespace USERS;
9
- CREATE USER scenic_oracle_adapter IDENTIFIED BY scenic_oracle_adapter;
10
- GRANT unlimited tablespace, create session, create table, create sequence,
11
- create procedure, create trigger, create view, create materialized view,
12
- create database link, create synonym, create type, ctxapp TO scenic_oracle_adapter;
13
- exit
14
- SQL