scenic-oracle_adapter 0.2.0 → 1.0.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: c25b74ca3becf8ed0e43f5f84893fcd737ace9544042555dc428cf8ffe51d0d6
4
+ data.tar.gz: aa53602569bc2a6e80562cbbaf97a33b989e5122a8bf0267fe80bac3e6f1cbd3
5
5
  SHA512:
6
- metadata.gz: c8486a41a221db67a984b06f5dfe9c754019f5c759bc540f47d5932991c97982fe9bb80fe20157a12854c51fa9f0e149a6956990ab2a13dd3b5a2b90b3106376
7
- data.tar.gz: 583843437bf27efafc5bf84e1cff91b5ca23b3e4f0b169fc53ceaef8ab8dd31d5214bb7ead2e1ca0103edcf5e1120a187a810961ec1250c3f18161e393653e92
6
+ metadata.gz: 825e47cfe103f1d19dc1595234b93a7354a21bff70b110ae24bd637d3823f4a70295b65790d53779a80cca90cf646586c40497a85c7ebf1675ed40d2429f7e2d
7
+ data.tar.gz: 3d7c362604f2ef9597abe25d9bc00e4c9cc052c3289c029cd339dedb9c384f4e407934bd3a348cad5c2a94b552304b3be05ebabb92b0ce42bd7f6c4157f9e8db
@@ -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
@@ -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.0.0"
6
6
  end
7
7
  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.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Dinger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-24 00:00:00.000000000 Z
11
+ date: 2018-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: scenic
@@ -135,6 +135,7 @@ files:
135
135
  - lib/scenic/adapters/oracle/index_reapplication.rb
136
136
  - lib/scenic/adapters/oracle/indexes.rb
137
137
  - lib/scenic/adapters/oracle/railtie.rb
138
+ - lib/scenic/adapters/oracle/refresh_dependencies.rb
138
139
  - lib/scenic/oracle_adapter.rb
139
140
  - lib/scenic/oracle_adapter/version.rb
140
141
  - scenic-oracle_adapter.gemspec