pg_migrate 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pg_migrate/util.rb +73 -0
- data/lib/pg_migrate/version.rb +1 -1
- metadata +2 -1
@@ -0,0 +1,73 @@
|
|
1
|
+
module PgMigrate
|
2
|
+
|
3
|
+
class Util
|
4
|
+
|
5
|
+
LOGGER = Logging.logger[self]
|
6
|
+
|
7
|
+
# recommended to create all connections via this method,
|
8
|
+
# so that we can put NOTICE/CONTEXT into logger instead of stderr
|
9
|
+
def self.create_conn(args)
|
10
|
+
conn = PG::Connection.open(args)
|
11
|
+
conn.set_notice_receiver do |result|
|
12
|
+
#result.res_status(result.result_status)
|
13
|
+
LOGGER.debug result.error_message
|
14
|
+
end
|
15
|
+
return conn
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.get_conn(connection_options)
|
19
|
+
if !connection_options[:pgconn].nil?
|
20
|
+
return connection_options[:pgconn]
|
21
|
+
elsif !connection_options[:connstring].nil?
|
22
|
+
create_conn(connection_options[:connstring])
|
23
|
+
elsif !connection_options[:connopts].nil?
|
24
|
+
return create_conn(connection_options[:connopts])
|
25
|
+
else
|
26
|
+
return create_conn(connection_options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# the 'out-of-band' conn is a connection to a database that you aren't
|
31
|
+
# interested in modifying; it's basically a landing pad so that you can do:
|
32
|
+
# DROP DATABSE BLAH; CREATE DATABASE BLAH -- for testing
|
33
|
+
def self.get_oob_conn(connection_options)
|
34
|
+
|
35
|
+
if !connection_options[:oob_pgconn].nil?
|
36
|
+
return connection_options[:oob_pgconn]
|
37
|
+
elsif !connection_options[:oob_connstring].nil?
|
38
|
+
return create_conn(connection_options[:oob_connstring])
|
39
|
+
elsif !connection_options[:oob_connopts].nil?
|
40
|
+
return create_conn(connection_options[:oob_connopts])
|
41
|
+
else
|
42
|
+
return create_conn(connection_options)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# finds dbname from connection_options
|
47
|
+
def self.get_db_name(connection_options)
|
48
|
+
dbname = nil
|
49
|
+
if !connection_options[:pgconn].nil?
|
50
|
+
dbname = connection_options[:pgconn].db
|
51
|
+
elsif !connection_options[:connstring].nil?
|
52
|
+
connstring = connection_options[:connstring]
|
53
|
+
bits = connstring.split(" ")
|
54
|
+
bits.each do |bit|
|
55
|
+
if bit.start_with? "dbname="
|
56
|
+
dbname = bit["dbname=".length..-1]
|
57
|
+
break
|
58
|
+
end
|
59
|
+
end
|
60
|
+
elsif !connection_options[:connopts].nil?
|
61
|
+
dbname = connection_options[:connopts]["dbname"]
|
62
|
+
else
|
63
|
+
dbname = connection_options["dbname"]
|
64
|
+
end
|
65
|
+
|
66
|
+
if dbname.nil?
|
67
|
+
raise "db name is null. tried finding dbname in #{connection_options.inspect}"
|
68
|
+
end
|
69
|
+
|
70
|
+
return dbname
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/pg_migrate/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_migrate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- lib/pg_migrate/package_templates/lib/gem/version.rb
|
91
91
|
- lib/pg_migrate/props.rb
|
92
92
|
- lib/pg_migrate/sql_reader.rb
|
93
|
+
- lib/pg_migrate/util.rb
|
93
94
|
- lib/pg_migrate/version.rb
|
94
95
|
- pg_migrate.gemspec
|
95
96
|
- spec/database.yml
|