db_meta 0.1.8 → 0.2.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -1
- data/lib/db_meta/constant.rb +17 -16
- data/lib/db_meta/oracle/base.rb +4 -3
- data/lib/db_meta/oracle/objects.rb +20 -1
- data/lib/db_meta/oracle/oracle.rb +2 -0
- data/lib/db_meta/oracle/types/queue.rb +74 -0
- data/lib/db_meta/oracle/types/table.rb +0 -18
- data/lib/db_meta/oracle/types/table_data_collection.rb +7 -2
- data/lib/db_meta/oracle/types/trigger.rb +1 -1
- data/lib/db_meta/version.rb +1 -1
- data/todo.txt +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31580b0cbfa89d45501449eee785db39a868993b
|
4
|
+
data.tar.gz: 3082a06f0be1d0cee03ac6eeb4219736e02f4754
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a85de5825f541aa77cd2421326facfa25826a94f20f3d13555bd6b011f80409f7ac915409d80df126502dc35fa53817c8241d303ee3fb6ba187665ac2b5ab912
|
7
|
+
data.tar.gz: 2ab88e0af1bf31b3322b6209582ff173d7431e7959a7fa4a530371eff73c514716ae681500a916e36f1d55e25936f643a43eb06e6fcd2c177f0fd239f870ac85
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,7 @@ Database meta and core data extraction.
|
|
6
6
|
|
7
7
|
## Is it production ready?
|
8
8
|
|
9
|
-
Well, I would not say, but I am using it already for my database development work where the gem covers my needs. Be careful and check
|
9
|
+
Well, I would not say, but I am using it already for my database development work where the gem covers my needs. Be careful and check details. Please create an issue when you think that someting is wrong or missing.
|
10
10
|
|
11
11
|
## Installation
|
12
12
|
via Gemfile
|
@@ -40,6 +40,7 @@ meta.extract
|
|
40
40
|
- Type
|
41
41
|
- Synonym
|
42
42
|
- Database Link
|
43
|
+
- Queue
|
43
44
|
- more to come...
|
44
45
|
|
45
46
|
## Planned Features
|
data/lib/db_meta/constant.rb
CHANGED
@@ -10,22 +10,23 @@ module DbMeta
|
|
10
10
|
|
11
11
|
'DATABASE LINK' => 2,
|
12
12
|
'SEQUENCE' => 3,
|
13
|
-
'
|
14
|
-
'
|
15
|
-
'
|
16
|
-
'
|
17
|
-
'
|
18
|
-
'
|
19
|
-
'
|
20
|
-
'
|
21
|
-
'
|
22
|
-
'
|
23
|
-
'
|
24
|
-
'
|
25
|
-
'
|
26
|
-
'
|
27
|
-
'
|
28
|
-
'
|
13
|
+
'TYPE' => 4,
|
14
|
+
'TABLE' => 5,
|
15
|
+
'QUEUE' => 6,
|
16
|
+
'LOB' => 7,
|
17
|
+
'VIEW' => 8,
|
18
|
+
'MATERIALIZED VIEW' => 9,
|
19
|
+
'FUNCTION' => 10,
|
20
|
+
'PROCEDURE' => 11,
|
21
|
+
'PACKAGE' => 12,
|
22
|
+
'PACKAGE BODY' => 12.1,
|
23
|
+
'SYNONYM' => 13,
|
24
|
+
'TRIGGER' => 14,
|
25
|
+
'GRANT' => 15,
|
26
|
+
'GRANT EXTERNAL' => 16,
|
27
|
+
'INDEX' => 17,
|
28
|
+
'DATA' => 20,
|
29
|
+
'CONSTRAINT' => 30
|
29
30
|
}
|
30
31
|
|
31
32
|
EXTRACT_FORMATS = [:sql]
|
data/lib/db_meta/oracle/base.rb
CHANGED
@@ -5,7 +5,7 @@ module DbMeta
|
|
5
5
|
|
6
6
|
TYPES = {}
|
7
7
|
|
8
|
-
attr_accessor :type, :status, :name, :extract_type
|
8
|
+
attr_accessor :type, :status, :name, :extract_type, :system_object
|
9
9
|
|
10
10
|
def self.register_type(type)
|
11
11
|
TYPES[type] = self
|
@@ -30,6 +30,8 @@ module DbMeta
|
|
30
30
|
@status = args['STATUS'].downcase.to_sym if args['STATUS']
|
31
31
|
|
32
32
|
@extract_type = :default # :default, :embedded, :merged
|
33
|
+
|
34
|
+
@system_object = @name =~ /\$/i # true if there is a '$' in the object name
|
33
35
|
end
|
34
36
|
|
35
37
|
|
@@ -45,8 +47,7 @@ module DbMeta
|
|
45
47
|
end
|
46
48
|
|
47
49
|
def system_object?
|
48
|
-
|
49
|
-
return @name =~ /\$/i
|
50
|
+
@system_object
|
50
51
|
end
|
51
52
|
|
52
53
|
end
|
@@ -8,7 +8,7 @@ module DbMeta
|
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
@data = Hash.new{ |h, type| h[type] = {} }
|
11
|
-
@worker_queue = Queue.new
|
11
|
+
@worker_queue = ::Queue.new
|
12
12
|
@types_with_object_status_default = []
|
13
13
|
|
14
14
|
@summary = Hash.new{ |h, type| h[type] = 0 }
|
@@ -42,6 +42,23 @@ module DbMeta
|
|
42
42
|
worker.map(&:join) # wait until all are done
|
43
43
|
end
|
44
44
|
|
45
|
+
def detect_system_objects
|
46
|
+
Log.info("Detecting system objects...")
|
47
|
+
|
48
|
+
# detect materialized view tables
|
49
|
+
@data['MATERIALZIED VIEW'].values.each do |object|
|
50
|
+
table = @data['TABLE'][object.name]
|
51
|
+
next unless table
|
52
|
+
table.system_object = true
|
53
|
+
end
|
54
|
+
|
55
|
+
@data['QUEUE'].values.each do |object|
|
56
|
+
table = @data['TABLE'][object.queue_table]
|
57
|
+
next unless table
|
58
|
+
table.system_object = true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
45
62
|
def merge_synonyms
|
46
63
|
Log.info("Merging synonyms...")
|
47
64
|
synonym_collection = SynonymCollection.new(type: 'SYNONYM', name: 'ALL')
|
@@ -74,6 +91,7 @@ module DbMeta
|
|
74
91
|
Log.info("Embedding indexes...")
|
75
92
|
|
76
93
|
@data['INDEX'].values.each do |object|
|
94
|
+
next unless @data['TABLE'][object.table_name]
|
77
95
|
@data['TABLE'][object.table_name].add_object(object)
|
78
96
|
end
|
79
97
|
end
|
@@ -82,6 +100,7 @@ module DbMeta
|
|
82
100
|
Log.info("Embedding constraints...")
|
83
101
|
|
84
102
|
@data["CONSTRAINT"].values.each do |constraint|
|
103
|
+
next unless @data['TABLE'][constraint.table_name]
|
85
104
|
@data['TABLE'][constraint.table_name].add_object(constraint)
|
86
105
|
end
|
87
106
|
end
|
@@ -48,6 +48,7 @@ module DbMeta
|
|
48
48
|
remove_folder(@base_folder)
|
49
49
|
create_folder(@base_folder)
|
50
50
|
|
51
|
+
@objects.detect_system_objects
|
51
52
|
@objects.merge_synonyms
|
52
53
|
@objects.merge_grants
|
53
54
|
@objects.embed_indexes
|
@@ -79,6 +80,7 @@ module DbMeta
|
|
79
80
|
|
80
81
|
total = 0
|
81
82
|
@objects.summary_each do |type, count|
|
83
|
+
next if count == 0
|
82
84
|
total += count
|
83
85
|
buffer << "#{SUMMARY_COLUMN_FORMAT_NAME % type.upcase.to_s}#{"%5d" % count} #{"(#{@objects.summary_system_object[type]} system #{pluralize(@objects.summary_system_object[type], 'object')})" if @objects.summary_system_object[type] > 0}"
|
84
86
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module DbMeta
|
2
|
+
module Oracle
|
3
|
+
class Queue < Base
|
4
|
+
register_type('QUEUE')
|
5
|
+
|
6
|
+
attr_reader :queue_table, :queue_type, :max_retries, :retry_delay, :payload_type, :sort_order, :compatible
|
7
|
+
|
8
|
+
def fetch
|
9
|
+
connection = Connection.instance.get
|
10
|
+
cursor = connection.exec("select * from user_queues where name = '#{@name}'")
|
11
|
+
cursor.fetch_hash do |row|
|
12
|
+
@queue_table = row['QUEUE_TABLE']
|
13
|
+
@queue_type = row['QUEUE_TYPE']
|
14
|
+
@max_retries = row['MAX_RETRIES'].to_i
|
15
|
+
@retry_delay = row['RETRY_DELAY'].to_f
|
16
|
+
end
|
17
|
+
cursor.close
|
18
|
+
|
19
|
+
cursor = connection.exec("select * from user_queue_tables where queue_table = '#{@queue_table}'")
|
20
|
+
cursor.fetch_hash do |row|
|
21
|
+
@payload_type = row['OBJECT_TYPE']
|
22
|
+
@sort_order = row['SORT_ORDER']
|
23
|
+
@compatible = row['COMPATIBLE']
|
24
|
+
end
|
25
|
+
cursor.close
|
26
|
+
|
27
|
+
ensure
|
28
|
+
connection.logoff
|
29
|
+
end
|
30
|
+
|
31
|
+
def extract(args={})
|
32
|
+
buffer = [block(@name)]
|
33
|
+
|
34
|
+
buffer << 'begin'
|
35
|
+
buffer << ' dbms_aqadm.create_queue_table('
|
36
|
+
buffer << " queue_table => '#{@queue_table}',"
|
37
|
+
buffer << " queue_payload_type => '#{@payload_type}'"
|
38
|
+
buffer << " sort_list => '#{@sort_order}',"
|
39
|
+
buffer << " compatible => '#{@compatible}'"
|
40
|
+
buffer << ' );'
|
41
|
+
buffer << 'end;'
|
42
|
+
buffer << '/'
|
43
|
+
buffer << nil
|
44
|
+
|
45
|
+
buffer << 'begin'
|
46
|
+
buffer << ' dbms_aqadm.create_queue('
|
47
|
+
buffer << " queue_name => '#{@name}',"
|
48
|
+
buffer << " queue_table => '#{@queue_table}',"
|
49
|
+
buffer << " max_retires => #{@max_retries},"
|
50
|
+
buffer << " retry_delay => #{@retry_delay}"
|
51
|
+
buffer << ' );'
|
52
|
+
buffer << " dbms_aqadm.start_queue('#{@name}');"
|
53
|
+
buffer << " dbms_aqadm.start_queue('AQ$_#{@queue_table}_E', false, true);"
|
54
|
+
buffer << 'end;'
|
55
|
+
buffer << '/'
|
56
|
+
buffer << nil
|
57
|
+
buffer.join("\n")
|
58
|
+
end
|
59
|
+
|
60
|
+
def ddl_drop
|
61
|
+
buffer = []
|
62
|
+
buffer << 'begin'
|
63
|
+
buffer << " dbms_aqadm.stop_queue('#{@name}');"
|
64
|
+
buffer << " dbms_aqadm.stop_queue('AQ$_#{@queue_table}_E');"
|
65
|
+
buffer << " dbms_aqadm.drop_queue(queue_name => '#{@name}');"
|
66
|
+
buffer << " dbms_aqadm.drop_queue_table(queue_table => '#{@queue_table}');"
|
67
|
+
buffer << 'end;'
|
68
|
+
buffer << '/'
|
69
|
+
buffer.join("\n")
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -113,24 +113,6 @@ module DbMeta
|
|
113
113
|
"DROP #{@type} #{@name} CASCADE CONSTRAINTS PURGE;"
|
114
114
|
end
|
115
115
|
|
116
|
-
def system_object?
|
117
|
-
is_system_object = super
|
118
|
-
return is_system_object if is_system_object
|
119
|
-
|
120
|
-
# check for tables created based on materialized views
|
121
|
-
n = 0
|
122
|
-
connection = Connection.instance.get
|
123
|
-
cursor = connection.exec("select count(*) as n from user_mviews where mview_name = '#{@name}'")
|
124
|
-
cursor.fetch_hash do |item|
|
125
|
-
n = item['N']
|
126
|
-
end
|
127
|
-
cursor.close
|
128
|
-
|
129
|
-
return n == 1
|
130
|
-
ensure
|
131
|
-
connection.logoff if connection
|
132
|
-
end
|
133
|
-
|
134
116
|
def get_core_data_where_clause(id=1000000)
|
135
117
|
buffer = []
|
136
118
|
@constraints.each do |constraint|
|
@@ -15,11 +15,14 @@ module DbMeta
|
|
15
15
|
|
16
16
|
def extract(args={})
|
17
17
|
buffer = [block(@name)]
|
18
|
+
buffer << "set define off;"
|
18
19
|
buffer << nil
|
19
20
|
|
20
21
|
connection = Connection.instance.get
|
21
22
|
|
22
23
|
@tables.each do |table|
|
24
|
+
Log.info("Extracting data from #{table.name}...")
|
25
|
+
|
23
26
|
buffer << block(table.name, 40)
|
24
27
|
|
25
28
|
name_type_map = {}
|
@@ -66,11 +69,13 @@ module DbMeta
|
|
66
69
|
when /varchar|char/i
|
67
70
|
buffer << "'#{value.gsub("'","''")}'"
|
68
71
|
when /clob/i
|
69
|
-
buffer << "'#{
|
72
|
+
buffer << "'#{value.read}'"
|
70
73
|
when /date/i
|
71
74
|
buffer << "to_date('#{value.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS')"
|
72
75
|
when /timestamp/i
|
73
|
-
|
76
|
+
buffer << "to_timezone('#{value.strftime("%Y-%m-%d %H:%M:%S %Z")}','YYYY-MM-DD HH24:MI:SS.FF TZD')"
|
77
|
+
when /raw/i
|
78
|
+
buffer << "'#{value.to_s}'"
|
74
79
|
else
|
75
80
|
buffer << value.to_s
|
76
81
|
end
|
@@ -37,7 +37,7 @@ module DbMeta
|
|
37
37
|
buffer << "ON #{@table_name}"
|
38
38
|
buffer << "#{@referencing_names}"
|
39
39
|
buffer << "#{@for_each}" if @for_each
|
40
|
-
buffer << "#{@trigger_body.strip}"
|
40
|
+
buffer << "#{@trigger_body.strip}" if @trigger_body
|
41
41
|
buffer << '/'
|
42
42
|
buffer << nil
|
43
43
|
buffer.join("\n")
|
data/lib/db_meta/version.rb
CHANGED
data/todo.txt
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
-- -----------------------------------------------------------------------------
|
4
4
|
|
5
5
|
- storage clauses
|
6
|
-
- materialized view
|
7
6
|
|
8
7
|
-- -------------------------------------
|
9
8
|
-- DONE
|
@@ -24,7 +23,8 @@
|
|
24
23
|
- merge types (exp. table, index, constraints; synonyms)
|
25
24
|
- grants
|
26
25
|
- type
|
27
|
-
|
26
|
+
- queues
|
27
|
+
- materialized view
|
28
28
|
|
29
29
|
-- -------------------------------------
|
30
30
|
-- dbms_metadata
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db_meta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- lib/db_meta/oracle/types/package.rb
|
111
111
|
- lib/db_meta/oracle/types/package_body.rb
|
112
112
|
- lib/db_meta/oracle/types/procedure.rb
|
113
|
+
- lib/db_meta/oracle/types/queue.rb
|
113
114
|
- lib/db_meta/oracle/types/sequence.rb
|
114
115
|
- lib/db_meta/oracle/types/synonym.rb
|
115
116
|
- lib/db_meta/oracle/types/synonym_collection.rb
|