avmtrf1-tools 0.24.0 → 0.25.0

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
  SHA256:
3
- metadata.gz: f55a52f271f4f056252876fd6510a0cb8915bd5e7708b07e31d63f34608d3361
4
- data.tar.gz: 014a3956f990bb0e41dba46f3b0571df84df11ffc65fbe278beb98e501c885f0
3
+ metadata.gz: 9001516b0fcc9bba4885ce017e6b7685350f5dccdad07a0acd9e0b0ca168119e
4
+ data.tar.gz: cd859f74feef86df8eae9a06d14f04e5859978358b810fa7c7ae143065beaed8
5
5
  SHA512:
6
- metadata.gz: b24fe1aa6c44427005a0b503667dff97f1b265841bd4ae2847b7600cb08c7657b7ff9e5f912a52d8409c656f16bf3de14b429f7c96043016bb49c267091745ce
7
- data.tar.gz: d52df68d7df12c5c3d33f74ccc637b47675020671c71bd0b3ae8c7ef6909d1bc3544a282c79490e6e551df3972a9100a8de4cffb374f55b6cb610d5ab4493787
6
+ metadata.gz: 15abe704a6fb9d054cb529c7a55033ac8c1203498517d87ddda7b083773046a959a67e680bb81d6a426d77447d4be74be89fc2646d4e6be618ca7fb717e6a709
7
+ data.tar.gz: 9ddf1149f6da8efb1748a36b4d0d11654b0dad6d2d53939c2544a5d9fffaa71e8ba9b1841be151b1571c47a033acf5440ce08bf758f73f6b6e0c7f103f8f198f
@@ -93,7 +93,7 @@ module Avmtrf1
93
93
  end
94
94
 
95
95
  def issue_uncached
96
- ::AvmTrf1::IssueFactory.find(issue_id)
96
+ ::Avmtrf1::IssueFactory.find(issue_id)
97
97
  end
98
98
  end
99
99
  end
@@ -3,7 +3,7 @@
3
3
  require 'avmtrf1/default_jira'
4
4
  require 'avmtrf1/default_redmine'
5
5
 
6
- module AvmTrf1
6
+ module Avmtrf1
7
7
  class IssueFactory
8
8
  class << self
9
9
  def find(issue_id)
@@ -4,7 +4,7 @@ Dir["#{File.dirname(__FILE__)}/#{::File.basename(__FILE__, '.*')}/*.rb"].sort.ea
4
4
  require path
5
5
  end
6
6
 
7
- module AvmTrf1
7
+ module Avmtrf1
8
8
  module Oracle
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ Dir["#{File.dirname(__FILE__)}/#{::File.basename(__FILE__, '.*')}/*.rb"].sort.ea
4
4
  require path
5
5
  end
6
6
 
7
- module AvmTrf1
7
+ module Avmtrf1
8
8
  module Oracle
9
9
  module Connection
10
10
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avmtrf1/oracle/objects'
3
4
  require 'avmtrf1/oracle/oci8'
4
5
 
5
6
  module Avmtrf1
@@ -8,14 +9,24 @@ module Avmtrf1
8
9
  class Base
9
10
  DEFAULT_PORT = 1521
10
11
 
12
+ delegate :exec, to: :connection
13
+
11
14
  def initialize(connection_string)
12
15
  @connection = OCI8.new(connection_string)
13
16
  end
14
17
 
18
+ def first_row(sql)
19
+ connection.exec(sql) { |row| return row }
20
+ nil
21
+ end
22
+
23
+ def first_row_hash(sql)
24
+ connection.exec(sql).fetch_hash { |row| return row }
25
+ nil
26
+ end
27
+
15
28
  def unique_value(sql)
16
- connection.exec(sql) do |row|
17
- return row.first
18
- end
29
+ first_row(sql).if_present(&:first)
19
30
  end
20
31
 
21
32
  def query(sql, &block)
@@ -26,6 +37,10 @@ module Avmtrf1
26
37
  end
27
38
  end
28
39
 
40
+ def objects
41
+ @objects ||= ::Avmtrf1::Oracle::Objects.new(self)
42
+ end
43
+
29
44
  private
30
45
 
31
46
  attr_reader :connection
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avmtrf1
6
+ module Oracle
7
+ class Object
8
+ require_sub __FILE__
9
+
10
+ class << self
11
+ def factory_get(connection, attributes)
12
+ return nil if attributes.blank?
13
+
14
+ type_class(attributes.fetch(:type)).new(connection, attributes)
15
+ end
16
+
17
+ def type_class(type)
18
+ const_get(type.to_s.humanize.camelize)
19
+ rescue NameError
20
+ ::Avmtrf1::Oracle::Object::Base
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/listable'
5
+
6
+ module Avmtrf1
7
+ module Oracle
8
+ class Object
9
+ class Base
10
+ include ::EacRubyUtils::Listable
11
+
12
+ lists.add_string :attributes, :id, :name, :owner, :type
13
+ common_constructor :connection, :attributes
14
+
15
+ lists.attributes.values.each do |attribute| # rubocop:disable Style/HashEachMethods
16
+ define_method(attribute) do
17
+ attributes.fetch(attribute.to_sym)
18
+ end
19
+ end
20
+
21
+ def drop
22
+ connection.exec(drop_ddl)
23
+ end
24
+
25
+ def fullname
26
+ (owner.present? ? "#{owner}." : '') + name
27
+ end
28
+
29
+ def to_s
30
+ "#{type}/#{fullname}"
31
+ end
32
+
33
+ def drop_ddl
34
+ "drop #{type} #{fullname}"
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avmtrf1/oracle/object/base'
4
+
5
+ module Avmtrf1
6
+ module Oracle
7
+ class Object
8
+ class Table < ::Avmtrf1::Oracle::Object::Base
9
+ def drop_ddl
10
+ "#{super} cascade constraints"
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avmtrf1/oracle/object/base'
4
+
5
+ module Avmtrf1
6
+ module Oracle
7
+ class Object
8
+ class User < ::Avmtrf1::Oracle::Object::Base
9
+ def objects(search_attributes = {})
10
+ connection.objects.list(search_attributes.merge(owner: name))
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avmtrf1/oracle/object/base'
4
+
5
+ module Avmtrf1
6
+ module Oracle
7
+ class Object
8
+ class View < ::Avmtrf1::Oracle::Object::Base
9
+ def drop_ddl
10
+ "#{super} cascade constraints"
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avmtrf1
6
+ module Oracle
7
+ class Objects
8
+ require_sub __FILE__
9
+
10
+ COLUMNS_TO_ATTRIBUTES = {
11
+ object_id: :id,
12
+ object_name: :name,
13
+ object_type: :type,
14
+ owner: :owner
15
+ }.freeze
16
+ TABLE_NAME = 'all_objects'
17
+
18
+ class << self
19
+ def row_to_object(connection, row)
20
+ ::Avmtrf1::Oracle::Object.factory_get(
21
+ connection,
22
+ row_to_attributes(row)
23
+ )
24
+ end
25
+
26
+ def row_to_attributes(row)
27
+ return nil if row.blank?
28
+
29
+ COLUMNS_TO_ATTRIBUTES.map do |column, attribute|
30
+ [attribute, row.fetch(column.to_s.upcase)]
31
+ end.to_h
32
+ end
33
+ end
34
+
35
+ common_constructor :connection
36
+
37
+ def list(options = {})
38
+ ::Avmtrf1::Oracle::Objects::Relation.new(connection, sql(options))
39
+ end
40
+
41
+ def first(options = {})
42
+ self.class.row_to_object(
43
+ connection,
44
+ connection.first_row_hash(sql(options))
45
+ )
46
+ end
47
+
48
+ def sql(options)
49
+ ::Avmtrf1::Oracle::Objects::SqlBuilder.new(options).sql
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avmtrf1
6
+ module Oracle
7
+ class Objects
8
+ class Relation
9
+ common_constructor :connection, :sql
10
+
11
+ def each
12
+ connection.query(sql).fetch_hash do |row|
13
+ yield(::Avmtrf1::Oracle::Objects.row_to_object(connection, row))
14
+ end
15
+ end
16
+
17
+ def count
18
+ connection.unique_value("select * from (#{sql})").to_i
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avmtrf1
6
+ module Oracle
7
+ class Objects
8
+ class SqlBuilder
9
+ COLUMNS = {
10
+ type: :type_name, name: :name, owner: :owner_name, table: :table_name
11
+ }.freeze
12
+
13
+ enable_simple_cache
14
+ common_constructor :options
15
+
16
+ def sql
17
+ "SELECT * FROM (\n" +
18
+ [all_objects_sql, all_users_sql].map { |sub_sql| "\t(#{with_where_sql(sub_sql)})\n" }
19
+ .join("\tUNION ALL\n") +
20
+ ") order by object_type, owner, object_name\n"
21
+ end
22
+
23
+ def all_objects_sql
24
+ "SELECT #{COLUMNS_TO_ATTRIBUTES.keys.join(', ')} FROM #{TABLE_NAME}"
25
+ end
26
+
27
+ def all_users_sql
28
+ 'SELECT user_id as object_id, username as object_name, \'USER\' as object_type' \
29
+ ', null as owner FROM all_users'
30
+ end
31
+
32
+ def with_where_sql(sql)
33
+ r = "select * from (#{sql}) WHERE 1=1"
34
+ COLUMNS_TO_ATTRIBUTES.each_value do |search_key|
35
+ search_option_condition(search_key).if_present do |v|
36
+ r += " and (#{v})"
37
+ end
38
+ end
39
+ r
40
+ end
41
+
42
+ def column_by_search_key(search_key)
43
+ COLUMNS_TO_ATTRIBUTES.key(search_key) || raise("Search key not found: #{search_key}")
44
+ end
45
+
46
+ def search_option_condition(search_key)
47
+ values = search_option(search_key)
48
+ return nil unless values.any?
49
+
50
+ column = column_by_search_key(search_key)
51
+ values.map { |v| "(LOWER(#{column}) LIKE LOWER('#{v}'))" }.join(' or ')
52
+ end
53
+
54
+ def search_option(search_key)
55
+ [search_key.to_s, search_key.to_sym].each do |k|
56
+ v = options[k]
57
+ return Array(v) if v.present?
58
+ end
59
+ []
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/default_runner'
4
+ require 'eac_ruby_utils/console/docopt_runner'
5
+ require 'eac_ruby_utils/console/speaker'
6
+
7
+ module Avmtrf1
8
+ module Tools
9
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
10
+ class Oracle < ::EacRubyUtils::Console::DocoptRunner
11
+ class UserClear < ::EacRubyUtils::Console::DocoptRunner
12
+ include ::EacCli::DefaultRunner
13
+
14
+ SELECTED_TYPES = %w[FUNCTION PACKAGE PROCEDURE SEQUENCE TABLE VIEW].freeze
15
+
16
+ runner_definition do
17
+ desc 'Remove todos os objetos (Tabelas, views, etc) de um usuário Oracle.'
18
+ bool_opt '-y', '--yes', 'Remove sem perguntar.'
19
+ bool_opt '-d', '--drop', 'Remove os objetos.'
20
+ pos_arg 'owner-name'
21
+ end
22
+
23
+ def run
24
+ objects_banner
25
+ drop_objects
26
+ end
27
+
28
+ private
29
+
30
+ def objects_banner
31
+ infov 'Owner', owner
32
+ infov 'Objects'
33
+ count = 0
34
+ objects.each do |object|
35
+ infov " * #{object.type}", object.fullname
36
+ count += 1
37
+ end
38
+ infov 'Total', count
39
+ end
40
+
41
+ def drop_objects
42
+ return unless options.fetch('--drop')
43
+ return unless confirm?
44
+
45
+ infom 'Removendo objetos...'
46
+ objects.each do |object|
47
+ infom "Removendo \"#{object}\"..."
48
+ object.drop
49
+ end
50
+ end
51
+
52
+ def confirm?
53
+ options.fetch('--yes') || request_input('Confirma a remoção?', bool: true)
54
+ end
55
+
56
+ def owner_uncached
57
+ context(:connection).objects.first(name: options.fetch('<owner-name>'), type: :user)
58
+ end
59
+
60
+ def objects_uncached
61
+ owner.objects(type: SELECTED_TYPES)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avmtrf1
4
4
  module Tools
5
- VERSION = '0.24.0'
5
+ VERSION = '0.25.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avmtrf1-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.0
4
+ version: 0.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-14 00:00:00.000000000 Z
11
+ date: 2020-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -290,6 +290,14 @@ files:
290
290
  - lib/avmtrf1/oracle/connection.rb
291
291
  - lib/avmtrf1/oracle/connection/base.rb
292
292
  - lib/avmtrf1/oracle/connection/string_builder.rb
293
+ - lib/avmtrf1/oracle/object.rb
294
+ - lib/avmtrf1/oracle/object/base.rb
295
+ - lib/avmtrf1/oracle/object/table.rb
296
+ - lib/avmtrf1/oracle/object/user.rb
297
+ - lib/avmtrf1/oracle/object/view.rb
298
+ - lib/avmtrf1/oracle/objects.rb
299
+ - lib/avmtrf1/oracle/objects/relation.rb
300
+ - lib/avmtrf1/oracle/objects/sql_builder.rb
293
301
  - lib/avmtrf1/oracle/oci8.rb
294
302
  - lib/avmtrf1/patches.rb
295
303
  - lib/avmtrf1/patches/avm/git/issue/complete.rb
@@ -330,6 +338,7 @@ files:
330
338
  - lib/avmtrf1/tools/runner/oracle.rb
331
339
  - lib/avmtrf1/tools/runner/oracle/query.rb
332
340
  - lib/avmtrf1/tools/runner/oracle/source_get.rb
341
+ - lib/avmtrf1/tools/runner/oracle/user_clear.rb
333
342
  - lib/avmtrf1/tools/runner/php.rb
334
343
  - lib/avmtrf1/tools/runner/php/docker.rb
335
344
  - lib/avmtrf1/tools/runner/red.rb