plsql_deploy_util 0.0.0.pre
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.
- data/source/deployPackages.rb +51 -0
- data/source/pl_sql_package_deployer.rb +120 -0
- metadata +69 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require "pl_sql_package_deployer"
|
|
2
|
+
require "optparse"
|
|
3
|
+
require "ostruct"
|
|
4
|
+
|
|
5
|
+
class CommandLineParser
|
|
6
|
+
def self.parse(args)
|
|
7
|
+
# setup default argument values
|
|
8
|
+
options = OpenStruct.new
|
|
9
|
+
options.dbAlias = "gsb1"
|
|
10
|
+
options.sourceDir = Dir.getwd
|
|
11
|
+
|
|
12
|
+
opts = OptionParser.new do |opts|
|
|
13
|
+
opts.banner = "Usage: deployPackages.rb [options] packageFilePattern1 packageFilePattern2 ..."
|
|
14
|
+
opts.separator ""
|
|
15
|
+
opts.separator "Specific options:"
|
|
16
|
+
|
|
17
|
+
# Optional argument with keyword completion.
|
|
18
|
+
opts.on("--dbAlias [alias]", [:gsb1, :gsb2, :geor],
|
|
19
|
+
"Select target database alias name to deploy to (gsb1, gsb2, geor)") do |t|
|
|
20
|
+
options.dbAlias = t
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# No argument, shows at tail. This will print an options summary.
|
|
24
|
+
# Try it and see!
|
|
25
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
|
26
|
+
puts opts
|
|
27
|
+
exit
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
begin
|
|
31
|
+
opts.parse!(args)
|
|
32
|
+
rescue => e
|
|
33
|
+
puts e.message.capitalize + "nn"
|
|
34
|
+
puts opts
|
|
35
|
+
exit 1
|
|
36
|
+
end
|
|
37
|
+
options
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
# this will extract the command line argument options and leave
|
|
41
|
+
# the optional package name arguments intact
|
|
42
|
+
options = CommandLineParser.parse(ARGV)
|
|
43
|
+
remainingCommandLineArguments = ARGV
|
|
44
|
+
filenamePatterns = remainingCommandLineArguments unless remainingCommandLineArguments.empty?
|
|
45
|
+
d = PlSqlPackageDeployer.new(options.dbAlias)
|
|
46
|
+
if filenamePatterns
|
|
47
|
+
d.deployPackages(filenamePatterns)
|
|
48
|
+
else
|
|
49
|
+
d.deployPackages()
|
|
50
|
+
end
|
|
51
|
+
d.logoff
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
require "ruby-plsql"
|
|
2
|
+
require "yaml"
|
|
3
|
+
|
|
4
|
+
class PlSqlPackageDeployer
|
|
5
|
+
attr_reader :dbAlias
|
|
6
|
+
attr_reader :databaseConfigFilepath
|
|
7
|
+
attr_accessor :verbose
|
|
8
|
+
|
|
9
|
+
def databaseConfig
|
|
10
|
+
if !@database_config
|
|
11
|
+
@database_config = YAML.load(File.read(databaseConfigFilepath))
|
|
12
|
+
end
|
|
13
|
+
return @database_config
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def initialize(dbAlias='gsb1', verbose=false, databaseConfigFilepath=File.expand_path('../database.yml', __FILE__))
|
|
17
|
+
@dbAlias = dbAlias.to_sym
|
|
18
|
+
@verbose = verbose
|
|
19
|
+
@databaseConfigFilepath = databaseConfigFilepath
|
|
20
|
+
|
|
21
|
+
params = databaseConfig[dbAlias]
|
|
22
|
+
|
|
23
|
+
if params == nil
|
|
24
|
+
raise StandardError, "InvalidDbAlias, PL SQL Package deployer has no database configuration for " + dbAlias
|
|
25
|
+
end
|
|
26
|
+
symbol_params = Hash[*params.map{|k,v| [k.to_sym, v]}.flatten]
|
|
27
|
+
|
|
28
|
+
plsql(@dbAlias).connect! symbol_params
|
|
29
|
+
puts "Connected to DB " + symbol_params[:database] + " as " + symbol_params[:username]
|
|
30
|
+
# Set autocommit to false so that automatic commits after each statement are _not_ performed
|
|
31
|
+
plsql(@dbAlias).connection.autocommit = false
|
|
32
|
+
# reduce network traffic in case of large resultsets
|
|
33
|
+
plsql(@dbAlias).connection.prefetch_rows = 100
|
|
34
|
+
# log DBMS_OUTPUT to standard output
|
|
35
|
+
if ENV['PLSQL_DBMS_OUTPUT']
|
|
36
|
+
plsql(@dbAlias).dbms_output_stream = STDOUT
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
ObjectSpace.define_finalizer( self, self.class.finalize(@dbAlias) )
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.finalize(dbAlias)
|
|
43
|
+
proc {
|
|
44
|
+
puts self.inspect + " Finalizer proc called for :" + dbAlias
|
|
45
|
+
plsql(dbAlias).logoff()
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def self.findPackageFilepaths(filePattern)
|
|
50
|
+
packageFilenamePattern = filePattern.gsub(/\**\.pkg/i, "")
|
|
51
|
+
packageFilenamePattern += "*.pkg"
|
|
52
|
+
packageFilenames = Dir.glob(packageFilenamePattern)
|
|
53
|
+
if packageFilenames.empty?
|
|
54
|
+
raise "No package files found matching pattern " + packageFilenamePattern
|
|
55
|
+
end
|
|
56
|
+
packageFilenames
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def self.extractPackageNameFromFilepath(packageFilepath)
|
|
60
|
+
File.basename(packageFilepath, '.pkg')
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def deployPackages(filenamePatterns=Dir.pwd + '/')
|
|
64
|
+
filenamePatterns.each do |filenamePattern|
|
|
65
|
+
begin
|
|
66
|
+
PlSqlPackageDeployer.findPackageFilepaths(filenamePattern).each do |filepath|
|
|
67
|
+
deployPackage(filepath)
|
|
68
|
+
end
|
|
69
|
+
rescue Exception => e
|
|
70
|
+
puts e.message
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def deployPackage(packageFilepath)
|
|
76
|
+
packageName = PlSqlPackageDeployer.extractPackageNameFromFilepath(packageFilepath)
|
|
77
|
+
georgianPackageName = packageName + '_pkg'
|
|
78
|
+
packageFilepath = File.expand_path(packageFilepath)
|
|
79
|
+
packageBodyFilepath = packageFilepath.gsub(/.pkg$/, ".pkb")
|
|
80
|
+
puts "Deploying package " + georgianPackageName
|
|
81
|
+
puts " package source file " + packageFilepath
|
|
82
|
+
puts " package body source file " + packageBodyFilepath
|
|
83
|
+
|
|
84
|
+
# Execute SQL in package file <packageName>.pkg contents
|
|
85
|
+
executeSqlInFile(packageFilepath)
|
|
86
|
+
|
|
87
|
+
# Execute SQL in package body file <packageName>.pkb contents
|
|
88
|
+
executeSqlInFile(packageBodyFilepath)
|
|
89
|
+
|
|
90
|
+
executeSql('grant execute on ' + georgianPackageName + ' to ban_default_m')
|
|
91
|
+
begin
|
|
92
|
+
executeSql('drop public synonym ' + georgianPackageName)
|
|
93
|
+
rescue OCIError => e
|
|
94
|
+
if e.message.include? 'ORA-01432'
|
|
95
|
+
puts e.message
|
|
96
|
+
else
|
|
97
|
+
raise
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
executeSql('create public synonym ' + georgianPackageName + ' for georgian.pkg')
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def logoff
|
|
104
|
+
puts "logoff called"
|
|
105
|
+
plsql(@dbAlias).logoff
|
|
106
|
+
end
|
|
107
|
+
private
|
|
108
|
+
def executeSql(sql)
|
|
109
|
+
if @verbose
|
|
110
|
+
puts "executing sql:" + sql
|
|
111
|
+
end
|
|
112
|
+
plsql(@dbAlias).execute(sql)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def executeSqlInFile(filepath)
|
|
116
|
+
sql = IO.read(filepath)
|
|
117
|
+
executeSql(sql)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: plsql_deploy_util
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 961915972
|
|
5
|
+
prerelease: 6
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 0
|
|
10
|
+
- pre
|
|
11
|
+
version: 0.0.0.pre
|
|
12
|
+
platform: ruby
|
|
13
|
+
authors:
|
|
14
|
+
- Todd Hiles
|
|
15
|
+
autorequire:
|
|
16
|
+
bindir: bin
|
|
17
|
+
cert_chain: []
|
|
18
|
+
|
|
19
|
+
date: 2012-04-26 00:00:00 Z
|
|
20
|
+
dependencies: []
|
|
21
|
+
|
|
22
|
+
description: PL/SQL Deployment Utilities. PlSqlPackageDeployer uses the ruby-plsql gem to execute sql read from the specified file(s).
|
|
23
|
+
email: todd.hiles@georgiancollege.ca
|
|
24
|
+
executables: []
|
|
25
|
+
|
|
26
|
+
extensions: []
|
|
27
|
+
|
|
28
|
+
extra_rdoc_files: []
|
|
29
|
+
|
|
30
|
+
files:
|
|
31
|
+
- source/deployPackages.rb
|
|
32
|
+
- source/pl_sql_package_deployer.rb
|
|
33
|
+
homepage:
|
|
34
|
+
licenses: []
|
|
35
|
+
|
|
36
|
+
post_install_message:
|
|
37
|
+
rdoc_options: []
|
|
38
|
+
|
|
39
|
+
require_paths:
|
|
40
|
+
- lib
|
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
42
|
+
none: false
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
hash: 3
|
|
47
|
+
segments:
|
|
48
|
+
- 0
|
|
49
|
+
version: "0"
|
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
|
+
none: false
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">"
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
hash: 25
|
|
56
|
+
segments:
|
|
57
|
+
- 1
|
|
58
|
+
- 3
|
|
59
|
+
- 1
|
|
60
|
+
version: 1.3.1
|
|
61
|
+
requirements: []
|
|
62
|
+
|
|
63
|
+
rubyforge_project:
|
|
64
|
+
rubygems_version: 1.8.23
|
|
65
|
+
signing_key:
|
|
66
|
+
specification_version: 3
|
|
67
|
+
summary: PL/SQL Deployment Utilities
|
|
68
|
+
test_files: []
|
|
69
|
+
|