db_meta 0.4.0 → 0.5.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 +5 -5
- data/.ruby-version +1 -0
- data/.travis.yml +33 -10
- data/.travis/oracle/download.sh +14 -0
- data/.travis/oracle/install.sh +32 -0
- data/.travis/setup_accounts.sh +8 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +45 -16
- data/README.md +1 -0
- data/Rakefile +2 -1
- data/db_meta.gemspec +15 -15
- data/docker/README.md +42 -0
- data/lib/db_meta.rb +10 -14
- data/lib/db_meta/abstract.rb +11 -21
- data/lib/db_meta/constant.rb +23 -25
- data/lib/db_meta/logger.rb +4 -7
- data/lib/db_meta/oracle/base.rb +9 -11
- data/lib/db_meta/oracle/connection.rb +3 -4
- data/lib/db_meta/oracle/helper.rb +7 -9
- data/lib/db_meta/oracle/objects.rb +45 -45
- data/lib/db_meta/oracle/oracle.rb +34 -30
- data/lib/db_meta/oracle/types/column.rb +15 -17
- data/lib/db_meta/oracle/types/comment.rb +2 -5
- data/lib/db_meta/oracle/types/constraint.rb +29 -32
- data/lib/db_meta/oracle/types/constraint_collection.rb +4 -6
- data/lib/db_meta/oracle/types/database_link.rb +4 -5
- data/lib/db_meta/oracle/types/function.rb +4 -5
- data/lib/db_meta/oracle/types/grant.rb +9 -10
- data/lib/db_meta/oracle/types/grant_collection.rb +4 -6
- data/lib/db_meta/oracle/types/index.rb +9 -11
- data/lib/db_meta/oracle/types/job.rb +2 -3
- data/lib/db_meta/oracle/types/lob.rb +2 -3
- data/lib/db_meta/oracle/types/materialized_view.rb +15 -18
- data/lib/db_meta/oracle/types/package.rb +7 -8
- data/lib/db_meta/oracle/types/package_body.rb +2 -3
- data/lib/db_meta/oracle/types/procedure.rb +4 -5
- data/lib/db_meta/oracle/types/queue.rb +24 -26
- data/lib/db_meta/oracle/types/sequence.rb +7 -8
- data/lib/db_meta/oracle/types/synonym.rb +6 -7
- data/lib/db_meta/oracle/types/synonym_collection.rb +4 -6
- data/lib/db_meta/oracle/types/table.rb +31 -34
- data/lib/db_meta/oracle/types/table_data_collection.rb +22 -18
- data/lib/db_meta/oracle/types/trigger.rb +12 -14
- data/lib/db_meta/oracle/types/type.rb +6 -7
- data/lib/db_meta/oracle/types/type_body.rb +2 -3
- data/lib/db_meta/oracle/types/view.rb +12 -14
- data/lib/db_meta/version.rb +1 -1
- metadata +27 -9
data/lib/db_meta/logger.rb
CHANGED
@@ -1,15 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require "logger"
|
2
2
|
|
3
3
|
class Logger
|
4
|
-
|
5
4
|
class Formatter
|
6
|
-
|
5
|
+
FORMAT2 = "%s\t%s\t%s\n"
|
7
6
|
|
8
7
|
def call(severity, time, progname, msg)
|
9
|
-
time_in_string = "#{time.strftime("%Y-%m-%d %H:%M:%S")}.#{"%03d" % (time.usec/1000)}"
|
10
|
-
|
8
|
+
time_in_string = "#{time.strftime("%Y-%m-%d %H:%M:%S")}.#{"%03d" % (time.usec / 1000)}"
|
9
|
+
FORMAT2 % [time_in_string, severity, msg]
|
11
10
|
end
|
12
|
-
|
13
11
|
end
|
14
|
-
|
15
12
|
end
|
data/lib/db_meta/oracle/base.rb
CHANGED
@@ -11,35 +11,34 @@ module DbMeta
|
|
11
11
|
TYPES[type] = self
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.from_type(args={})
|
15
|
-
type = args[
|
14
|
+
def self.from_type(args = {})
|
15
|
+
type = args["OBJECT_TYPE"]
|
16
16
|
|
17
17
|
# return instance of known type
|
18
|
-
return TYPES[type].new(args) if TYPES.
|
18
|
+
return TYPES[type].new(args) if TYPES.key?(type)
|
19
19
|
|
20
20
|
# There is no implementation for this type yet. Let's just use Base
|
21
21
|
Log.warn("Don't know how to handle oracle type [#{type}] yet")
|
22
22
|
Base.new(args)
|
23
23
|
end
|
24
24
|
|
25
|
-
def initialize(args={})
|
26
|
-
@type = args[
|
27
|
-
@name = args[
|
25
|
+
def initialize(args = {})
|
26
|
+
@type = args["OBJECT_TYPE"]
|
27
|
+
@name = args["OBJECT_NAME"]
|
28
28
|
|
29
29
|
@status = :unknown
|
30
|
-
@status = args[
|
30
|
+
@status = args["STATUS"].downcase.to_sym if args["STATUS"]
|
31
31
|
|
32
32
|
@extract_type = :default # :default, :embedded, :merged
|
33
33
|
|
34
34
|
@system_object = @name =~ /\$/i # true if there is a '$' in the object name
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
37
|
def fetch
|
39
38
|
end
|
40
39
|
|
41
|
-
def extract(args={})
|
42
|
-
|
40
|
+
def extract(args = {})
|
41
|
+
"-- class/method needs to be implemented"
|
43
42
|
end
|
44
43
|
|
45
44
|
def ddl_drop
|
@@ -49,7 +48,6 @@ module DbMeta
|
|
49
48
|
def system_object?
|
50
49
|
@system_object
|
51
50
|
end
|
52
|
-
|
53
51
|
end
|
54
52
|
end
|
55
53
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "singleton"
|
2
2
|
|
3
3
|
module DbMeta
|
4
4
|
module Oracle
|
@@ -19,12 +19,12 @@ module DbMeta
|
|
19
19
|
def get
|
20
20
|
unless @pool
|
21
21
|
# create connection pool
|
22
|
-
@pool = ::OCI8::ConnectionPool.new(
|
22
|
+
@pool = ::OCI8::ConnectionPool.new(1, @worker, 1, @username, @password, @database_instance)
|
23
23
|
Log.info("Connected to #{@username}@#{@database_instance}")
|
24
24
|
end
|
25
25
|
|
26
26
|
# create and return logical connection. It creates physical connection as needed.
|
27
|
-
|
27
|
+
::OCI8.new(@username, @password, @pool)
|
28
28
|
end
|
29
29
|
|
30
30
|
def disconnect
|
@@ -33,7 +33,6 @@ module DbMeta
|
|
33
33
|
Log.info("Logged off from #{@username}@#{@database_instance}")
|
34
34
|
@pool = nil
|
35
35
|
end
|
36
|
-
|
37
36
|
end
|
38
37
|
end
|
39
38
|
end
|
@@ -1,19 +1,18 @@
|
|
1
1
|
module DbMeta
|
2
2
|
module Oracle
|
3
3
|
module Helper
|
4
|
-
|
5
4
|
def block(title, size = 80)
|
6
|
-
line =
|
7
|
-
|
5
|
+
line = "-- " + ("-" * (size - 3))
|
6
|
+
[line, "-- #{title}", line].join("\n")
|
8
7
|
end
|
9
8
|
|
10
9
|
def type_sequence(type)
|
11
|
-
|
10
|
+
TYPE_SEQUENCE[type] || 99
|
12
11
|
end
|
13
12
|
|
14
13
|
def write_buffer_to_file(buffer, file)
|
15
14
|
buffer = buffer.join("\n") if buffer.is_a?(Array)
|
16
|
-
File.open(file.downcase.
|
15
|
+
File.open(file.downcase.tr(" ", "_"), "w") do |output|
|
17
16
|
output.write(buffer)
|
18
17
|
end
|
19
18
|
end
|
@@ -23,15 +22,14 @@ module DbMeta
|
|
23
22
|
end
|
24
23
|
|
25
24
|
def create_folder(folder)
|
26
|
-
Dir.mkdir(folder.downcase.
|
25
|
+
Dir.mkdir(folder.downcase.tr(" ", "_"))
|
27
26
|
rescue
|
28
27
|
end
|
29
28
|
|
30
|
-
def pluralize(n, singular, plural=nil)
|
29
|
+
def pluralize(n, singular, plural = nil)
|
31
30
|
return singular if n == 1
|
32
|
-
|
31
|
+
(plural || (singular + "s"))
|
33
32
|
end
|
34
|
-
|
35
33
|
end
|
36
34
|
end
|
37
35
|
end
|
@@ -7,13 +7,13 @@ module DbMeta
|
|
7
7
|
attr_reader :summary_system_object
|
8
8
|
|
9
9
|
def initialize
|
10
|
-
@data = Hash.new{ |h, type|
|
10
|
+
@data = Hash.new { |h, type| h[type] = {} }
|
11
11
|
@worker_queue = ::Queue.new
|
12
12
|
@types_with_object_status_default = []
|
13
13
|
|
14
|
-
@summary = Hash.new{ |h, type| h[type] = 0 }
|
15
|
-
@summary_system_object = Hash.new{ |h, type| h[type] = 0 }
|
16
|
-
@invalids = Hash.new{ |h, type| h[type] = [] }
|
14
|
+
@summary = Hash.new { |h, type| h[type] = 0 }
|
15
|
+
@summary_system_object = Hash.new { |h, type| h[type] = 0 }
|
16
|
+
@invalids = Hash.new { |h, type| h[type] = [] }
|
17
17
|
end
|
18
18
|
|
19
19
|
def <<(object)
|
@@ -25,20 +25,18 @@ module DbMeta
|
|
25
25
|
@invalids[object.type] << object if [:invalid, :disabled].include?(object.status)
|
26
26
|
end
|
27
27
|
|
28
|
-
def fetch(args={})
|
28
|
+
def fetch(args = {})
|
29
29
|
# fetch details in parallel
|
30
|
-
#
|
31
|
-
worker = (1..Connection.instance.worker).map
|
30
|
+
# number of threads = physical connections / 2 to prevent application locking
|
31
|
+
worker = (1..Connection.instance.worker / 2).map {
|
32
32
|
Thread.new do
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
object.fetch
|
37
|
-
end
|
38
|
-
rescue ThreadError
|
33
|
+
while (object = @worker_queue.pop(true))
|
34
|
+
Log.info(" - #{object.type} - #{object.name}")
|
35
|
+
object.fetch
|
39
36
|
end
|
37
|
+
rescue ThreadError
|
40
38
|
end
|
41
|
-
|
39
|
+
}
|
42
40
|
worker.map(&:join) # wait until all are done
|
43
41
|
end
|
44
42
|
|
@@ -46,14 +44,14 @@ module DbMeta
|
|
46
44
|
Log.info("Detecting system objects...")
|
47
45
|
|
48
46
|
# detect materialized view tables
|
49
|
-
@data[
|
50
|
-
table = @data[
|
47
|
+
@data["MATERIALZIED VIEW"].values.each do |object|
|
48
|
+
table = @data["TABLE"][object.name]
|
51
49
|
next unless table
|
52
50
|
table.system_object = true
|
53
51
|
end
|
54
52
|
|
55
|
-
@data[
|
56
|
-
table = @data[
|
53
|
+
@data["QUEUE"].values.each do |object|
|
54
|
+
table = @data["TABLE"][object.queue_table]
|
57
55
|
next unless table
|
58
56
|
table.system_object = true
|
59
57
|
end
|
@@ -61,38 +59,38 @@ module DbMeta
|
|
61
59
|
|
62
60
|
def merge_synonyms
|
63
61
|
Log.info("Merging synonyms...")
|
64
|
-
synonym_collection = SynonymCollection.new(type:
|
62
|
+
synonym_collection = SynonymCollection.new(type: "SYNONYM", name: "ALL")
|
65
63
|
|
66
|
-
@data[
|
64
|
+
@data["SYNONYM"].values.each do |object|
|
67
65
|
synonym_collection << object
|
68
66
|
end
|
69
67
|
|
70
68
|
return if synonym_collection.empty?
|
71
69
|
|
72
70
|
self << synonym_collection
|
73
|
-
@summary[
|
71
|
+
@summary["SYNONYM"] -= 1 # no need to count collection object
|
74
72
|
end
|
75
73
|
|
76
74
|
def merge_grants
|
77
75
|
Log.info("Merging grants...")
|
78
|
-
grant_collection = GrantCollection.new(type:
|
76
|
+
grant_collection = GrantCollection.new(type: "GRANT", name: "ALL")
|
79
77
|
|
80
|
-
@data[
|
78
|
+
@data["GRANT"].values.sort_by { |o| o.sort_value }.each do |object|
|
81
79
|
grant_collection << object
|
82
80
|
end
|
83
81
|
|
84
82
|
return if grant_collection.empty?
|
85
83
|
|
86
84
|
self << grant_collection
|
87
|
-
@summary[
|
85
|
+
@summary["GRANT"] -= 1 # no need to count collection object
|
88
86
|
end
|
89
87
|
|
90
88
|
def embed_indexes
|
91
89
|
Log.info("Embedding indexes...")
|
92
90
|
|
93
|
-
@data[
|
94
|
-
next unless @data[
|
95
|
-
@data[
|
91
|
+
@data["INDEX"].values.each do |object|
|
92
|
+
next unless @data["TABLE"][object.table_name]
|
93
|
+
@data["TABLE"][object.table_name].add_object(object)
|
96
94
|
end
|
97
95
|
end
|
98
96
|
|
@@ -100,8 +98,8 @@ module DbMeta
|
|
100
98
|
Log.info("Embedding constraints...")
|
101
99
|
|
102
100
|
@data["CONSTRAINT"].values.each do |constraint|
|
103
|
-
next unless @data[
|
104
|
-
@data[
|
101
|
+
next unless @data["TABLE"][constraint.table_name]
|
102
|
+
@data["TABLE"][constraint.table_name].add_object(constraint)
|
105
103
|
end
|
106
104
|
end
|
107
105
|
|
@@ -109,7 +107,7 @@ module DbMeta
|
|
109
107
|
Log.info("Embedding triggers...")
|
110
108
|
|
111
109
|
@data["TRIGGER"].values.each do |object|
|
112
|
-
table_object = @data[
|
110
|
+
table_object = @data["TABLE"][object.table_name]
|
113
111
|
|
114
112
|
if table_object
|
115
113
|
table_object.add_object(object)
|
@@ -122,9 +120,9 @@ module DbMeta
|
|
122
120
|
|
123
121
|
def merge_constraints
|
124
122
|
Log.info("Merging constraints...")
|
125
|
-
constraint_collection = ConstraintCollection.new(type:
|
123
|
+
constraint_collection = ConstraintCollection.new(type: "CONSTRAINT", name: "ALL FOREIGN KEYS")
|
126
124
|
|
127
|
-
@data[
|
125
|
+
@data["CONSTRAINT"].values.each do |object|
|
128
126
|
next unless object.extract_type == :merged
|
129
127
|
constraint_collection << object
|
130
128
|
end
|
@@ -132,7 +130,7 @@ module DbMeta
|
|
132
130
|
return if constraint_collection.empty?
|
133
131
|
|
134
132
|
self << constraint_collection
|
135
|
-
@summary[
|
133
|
+
@summary["CONSTRAINT"] -= 1 # no need to count collection object
|
136
134
|
end
|
137
135
|
|
138
136
|
def handle_table_data(args)
|
@@ -142,19 +140,23 @@ module DbMeta
|
|
142
140
|
@include_data = args[:include_data] if args[:include_data]
|
143
141
|
|
144
142
|
tables = []
|
145
|
-
@data[
|
143
|
+
@data["TABLE"].values.each do |table|
|
146
144
|
next if table.system_object?
|
147
|
-
|
148
|
-
|
145
|
+
if @exclude_data
|
146
|
+
next if table.name&.match?(@exclude_data)
|
147
|
+
end
|
148
|
+
if @include_data
|
149
|
+
next unless table.name&.match?(@include_data)
|
150
|
+
end
|
149
151
|
tables << table
|
150
152
|
end
|
151
153
|
|
152
|
-
self << TableDataCollection.new(name:
|
153
|
-
@summary[
|
154
|
+
self << TableDataCollection.new(name: "ALL CORE DATA", type: "DATA", tables: tables)
|
155
|
+
@summary["DATA"] -= 1 # no need to count DATA object
|
154
156
|
end
|
155
157
|
|
156
158
|
def default_each
|
157
|
-
@data.keys.sort_by{ |type| type_sequence(type) }.each do |type|
|
159
|
+
@data.keys.sort_by { |type| type_sequence(type) }.each do |type|
|
158
160
|
@data[type].keys.sort.each do |name|
|
159
161
|
object = @data[type][name]
|
160
162
|
next if object.system_object?
|
@@ -165,7 +167,7 @@ module DbMeta
|
|
165
167
|
end
|
166
168
|
|
167
169
|
def reverse_default_each
|
168
|
-
@data.keys.sort_by{ |type| type_sequence(type) }.reverse_each do |type|
|
170
|
+
@data.keys.sort_by { |type| type_sequence(type) }.reverse_each do |type|
|
169
171
|
@data[type].keys.sort.each do |name|
|
170
172
|
object = @data[type][name]
|
171
173
|
next if object.system_object?
|
@@ -191,7 +193,6 @@ module DbMeta
|
|
191
193
|
end
|
192
194
|
end
|
193
195
|
|
194
|
-
|
195
196
|
def self.all
|
196
197
|
objects = []
|
197
198
|
|
@@ -202,12 +203,12 @@ module DbMeta
|
|
202
203
|
cursor = connection.exec(OBJECT_QUERY)
|
203
204
|
cursor.fetch_hash do |item|
|
204
205
|
items << item
|
205
|
-
types << item[
|
206
|
+
types << item["OBJECT_TYPE"]
|
206
207
|
end
|
207
208
|
cursor.close
|
208
209
|
|
209
210
|
# sort items and make an object instance
|
210
|
-
items.sort_by{ |i| [
|
211
|
+
items.sort_by { |i| [type_sequence(i["OBJECT_TYPE"]), i["OBJECT_NAME"]] }.each do |item|
|
211
212
|
objects << Base.from_type(item)
|
212
213
|
end
|
213
214
|
|
@@ -215,9 +216,8 @@ module DbMeta
|
|
215
216
|
|
216
217
|
objects
|
217
218
|
ensure
|
218
|
-
connection
|
219
|
+
connection&.logoff # closes logical connection
|
219
220
|
end
|
220
|
-
|
221
221
|
end
|
222
222
|
end
|
223
223
|
end
|
@@ -1,12 +1,14 @@
|
|
1
|
-
|
2
|
-
require 'fileutils'
|
1
|
+
ENV["NLS_LANG"] = "American_America.UTF8"
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
require_relative 'base'
|
7
|
-
require_relative 'objects'
|
3
|
+
require "oci8"
|
4
|
+
require "fileutils"
|
8
5
|
|
9
|
-
|
6
|
+
require_relative "connection"
|
7
|
+
require_relative "helper"
|
8
|
+
require_relative "base"
|
9
|
+
require_relative "objects"
|
10
|
+
|
11
|
+
Dir[File.dirname(__FILE__) + "/types/*.rb"].sort.each { |file| require file }
|
10
12
|
|
11
13
|
module DbMeta
|
12
14
|
module Oracle
|
@@ -15,7 +17,7 @@ module DbMeta
|
|
15
17
|
|
16
18
|
register_type(:oracle)
|
17
19
|
|
18
|
-
def initialize(args={})
|
20
|
+
def initialize(args = {})
|
19
21
|
super(args)
|
20
22
|
|
21
23
|
Connection.instance.set(@username, @password, @instance, @worker)
|
@@ -23,13 +25,17 @@ module DbMeta
|
|
23
25
|
@objects = Objects.new
|
24
26
|
end
|
25
27
|
|
26
|
-
def fetch(args={})
|
28
|
+
def fetch(args = {})
|
27
29
|
@include_pattern = args[:include]
|
28
30
|
@exclude_pattern = args[:exclude]
|
29
31
|
|
30
32
|
Objects.all.each do |object|
|
31
|
-
|
32
|
-
|
33
|
+
if @exclude_pattern
|
34
|
+
next if @exclude_pattern&.match?(object.name)
|
35
|
+
end
|
36
|
+
if @include_pattern
|
37
|
+
next unless @include_pattern&.match?(object.name)
|
38
|
+
end
|
33
39
|
@objects << object
|
34
40
|
end
|
35
41
|
|
@@ -39,7 +45,7 @@ module DbMeta
|
|
39
45
|
Connection.instance.disconnect
|
40
46
|
end
|
41
47
|
|
42
|
-
def extract(args={})
|
48
|
+
def extract(args = {})
|
43
49
|
format = args[:format] || :sql
|
44
50
|
|
45
51
|
# validate args
|
@@ -66,7 +72,7 @@ module DbMeta
|
|
66
72
|
folder = File.join(@base_folder, "#{"%02d" % type_sequence(object.type)}_#{object.type}")
|
67
73
|
create_folder(folder)
|
68
74
|
|
69
|
-
filename = File.join(folder, "#{object.name}.#{format
|
75
|
+
filename = File.join(folder, "#{object.name}.#{format}")
|
70
76
|
write_buffer_to_file(object.extract(args), filename)
|
71
77
|
end
|
72
78
|
end
|
@@ -82,34 +88,34 @@ module DbMeta
|
|
82
88
|
@objects.summary_each do |type, count|
|
83
89
|
next if count == 0
|
84
90
|
total += count
|
85
|
-
buffer << "#{SUMMARY_COLUMN_FORMAT_NAME % type.upcase.to_s}#{"%5d" % count} #{"(#{@objects.summary_system_object[type]} system #{pluralize(@objects.summary_system_object[type],
|
91
|
+
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}"
|
86
92
|
end
|
87
93
|
buffer << nil
|
88
94
|
|
89
|
-
buffer << "#{SUMMARY_COLUMN_FORMAT_NAME %
|
95
|
+
buffer << "#{SUMMARY_COLUMN_FORMAT_NAME % "Total Objects"}#{"%5d" % total}"
|
90
96
|
buffer << nil
|
91
97
|
buffer << nil
|
92
98
|
|
93
99
|
# invalid objects
|
94
100
|
if @objects.invalids?
|
95
|
-
buffer <<
|
101
|
+
buffer << "Invalid/Disabled Objects"
|
96
102
|
@objects.invalid_each do |type, objects|
|
97
103
|
buffer << "#{SUMMARY_COLUMN_FORMAT_NAME % type.upcase.to_s}#{"%5d" % objects.size}"
|
98
104
|
objects.each do |object|
|
99
|
-
buffer <<
|
105
|
+
buffer << (SUMMARY_COLUMN_FORMAT_NAME_RIGHT % object.name).to_s
|
100
106
|
end
|
101
107
|
buffer << nil
|
102
108
|
end
|
103
109
|
else
|
104
|
-
buffer <<
|
110
|
+
buffer << "No invalid/disabled objects"
|
105
111
|
end
|
106
112
|
buffer << nil
|
107
113
|
|
108
|
-
filename = File.join(@base_folder, "#{"%02d" % type_sequence(
|
114
|
+
filename = File.join(@base_folder, "#{"%02d" % type_sequence("SUMMARY")}_summary.txt")
|
109
115
|
write_buffer_to_file(buffer, filename)
|
110
116
|
end
|
111
117
|
|
112
|
-
def extract_create_all(args={})
|
118
|
+
def extract_create_all(args = {})
|
113
119
|
Log.info("Extracting create all script...")
|
114
120
|
|
115
121
|
buffer = [block("#{@username} - CREATE ALL")]
|
@@ -117,33 +123,32 @@ module DbMeta
|
|
117
123
|
current_type = nil
|
118
124
|
@objects.default_each do |object|
|
119
125
|
if current_type != object.type
|
120
|
-
buffer << nil
|
126
|
+
buffer << nil
|
121
127
|
buffer << block(object.type, 40)
|
122
128
|
end
|
123
129
|
|
124
|
-
folder = "#{
|
130
|
+
folder = "#{"%02d" % type_sequence(object.type)}_#{object.type}"
|
125
131
|
file = "#{object.name}.sql"
|
126
|
-
buffer << "@#{File.join(folder,file).downcase.
|
132
|
+
buffer << "@#{File.join(folder, file).downcase.tr(" ", "_")}"
|
127
133
|
current_type = object.type
|
128
134
|
end
|
129
135
|
buffer << nil
|
130
136
|
buffer << compile_invalid_script
|
131
137
|
buffer << nil
|
132
138
|
|
133
|
-
filename = File.join(@base_folder,"#{
|
139
|
+
filename = File.join(@base_folder, "#{"%02d" % type_sequence("CREATE")}_create_all.sql")
|
134
140
|
write_buffer_to_file(buffer, filename)
|
135
141
|
end
|
136
142
|
|
137
|
-
def extract_drop_all(args={})
|
143
|
+
def extract_drop_all(args = {})
|
138
144
|
Log.info("Extracting drop all script...")
|
139
145
|
|
140
146
|
buffer = [block("#{@username} - DROP ALL")]
|
141
147
|
|
142
148
|
current_type = nil
|
143
149
|
@objects.reverse_default_each do |object|
|
144
|
-
|
145
150
|
if current_type != object.type
|
146
|
-
buffer << nil
|
151
|
+
buffer << nil
|
147
152
|
buffer << block(object.type, 40)
|
148
153
|
end
|
149
154
|
|
@@ -152,12 +157,12 @@ module DbMeta
|
|
152
157
|
end
|
153
158
|
buffer << nil
|
154
159
|
|
155
|
-
filename = File.join(@base_folder,"#{
|
160
|
+
filename = File.join(@base_folder, "#{"%02d" % type_sequence("DROP")}_drop_all.sql")
|
156
161
|
write_buffer_to_file(buffer, filename)
|
157
162
|
end
|
158
163
|
|
159
164
|
def compile_invalid_script
|
160
|
-
buffer = [block(
|
165
|
+
buffer = [block("Compile invalid objects if needed", 40)]
|
161
166
|
buffer << "declare"
|
162
167
|
buffer << "begin"
|
163
168
|
buffer << " for rec in (select object_name, object_type from user_objects where status = 'INVALID') loop"
|
@@ -172,7 +177,6 @@ module DbMeta
|
|
172
177
|
buffer << "/"
|
173
178
|
buffer.join("\n")
|
174
179
|
end
|
175
|
-
|
176
180
|
end
|
177
181
|
end
|
178
182
|
end
|