psql-cm 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.md +10 -0
- data/lib/psql-cm/database.rb +8 -5
- data/lib/psql-cm/dump.rb +1 -1
- data/lib/psql-cm/restore.rb +20 -3
- data/lib/psql-cm/version.rb +1 -1
- metadata +3 -3
data/History.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# 0.1.0 - 2012-04-24
|
2
|
+
|
3
|
+
Ensure pgpass file is created if it does not exist.
|
4
|
+
|
5
|
+
Ensure connections get closed.
|
6
|
+
|
7
|
+
Account for setting schema when restoring.
|
8
|
+
|
9
|
+
Specify schema in --table specifier within pg\_dump command.
|
10
|
+
|
1
11
|
# 0.0.9 - 2012-04-23
|
2
12
|
|
3
13
|
Dump now uses --no-privileges, privileges should be handled separately.
|
data/lib/psql-cm/database.rb
CHANGED
@@ -24,6 +24,8 @@ module PSQLCM
|
|
24
24
|
|
25
25
|
def connect!
|
26
26
|
@db = PG.connect(@config)
|
27
|
+
ObjectSpace.define_finalizer(self, proc { @db.close })
|
28
|
+
@db
|
27
29
|
end
|
28
30
|
|
29
31
|
def reconnect!(name = @config[:dbname])
|
@@ -36,19 +38,20 @@ module PSQLCM
|
|
36
38
|
end
|
37
39
|
|
38
40
|
def pgpass # Ensure a pgpass entry exists for this connection.
|
41
|
+
pgpass_file = File.join(ENV['HOME'], '.pgpass')
|
42
|
+
FileUtils.touch(pgpass_file) unless File.exists?(pgpass_file)
|
43
|
+
|
39
44
|
pgpass_line = [ @config[:host], @config[:port], @config[:dbname],
|
40
45
|
@config[:user], @config[:password] ].join(':')
|
41
46
|
|
42
|
-
content = File.
|
43
|
-
file.read
|
44
|
-
end.split("\n")
|
47
|
+
content = File.read(pgpass_file).split("\n")
|
45
48
|
|
46
49
|
unless content.detect{ |line| line == pgpass_line }
|
47
|
-
File.open(
|
50
|
+
File.open(pgpass_file, 'w') do |file|
|
48
51
|
content << pgpass_line
|
49
52
|
file.write(content.join("\n") + "\n")
|
50
53
|
end
|
51
|
-
File.chmod(0600,
|
54
|
+
File.chmod(0600, pgpass_file)
|
52
55
|
end
|
53
56
|
pgpass_line
|
54
57
|
end # def pgpass
|
data/lib/psql-cm/dump.rb
CHANGED
@@ -15,7 +15,7 @@ module PSQLCM
|
|
15
15
|
cm_file = File.join(sql_path,database,"#{schema}.sql")
|
16
16
|
|
17
17
|
sh %W[ pg_dump #{db(database).psql_args} --no-privileges --no-owner
|
18
|
-
--schema=#{schema} --file=#{cm_file} --table=#{config.cm_table}
|
18
|
+
--schema=#{schema} --file=#{cm_file} --table=#{schema}.#{config.cm_table}
|
19
19
|
#{database} ].join(' ')
|
20
20
|
end
|
21
21
|
end
|
data/lib/psql-cm/restore.rb
CHANGED
@@ -32,11 +32,28 @@ module PSQLCM
|
|
32
32
|
end
|
33
33
|
|
34
34
|
sql = "SELECT content from #{schema}.#{config.cm_table} where is_base IS false ORDER BY created_at ASC;"
|
35
|
+
debug "sql> #{sql}"
|
35
36
|
db(database).exec(sql).each do |row|
|
36
|
-
debug "
|
37
|
+
debug "change>\n#{row['content']}"
|
37
38
|
Tempfile.open('base.sql') do |temp_file|
|
38
|
-
temp_file.write(row)
|
39
|
-
|
39
|
+
temp_file.write(row['content'])
|
40
|
+
temp_file.close
|
41
|
+
|
42
|
+
psqlrc_file = File.join(ENV['HOME'],'.psqlrc')
|
43
|
+
FileUtils.touch(psqlrc_file) unless File.exists?(psqlrc_file)
|
44
|
+
psqlrc = File.read(psqlrc_file)
|
45
|
+
File.open(psqlrc_file,'w') do |file|
|
46
|
+
file.rewind
|
47
|
+
file.write "SET search_path TO #{schema}; "
|
48
|
+
end
|
49
|
+
begin
|
50
|
+
sh "psql #{db(database).psql_args} #{database} < #{temp_file.path}"
|
51
|
+
ensure
|
52
|
+
File.open(psqlrc_file,'w') do |file|
|
53
|
+
file.rewind
|
54
|
+
file.write psqlrc
|
55
|
+
end
|
56
|
+
end
|
40
57
|
end
|
41
58
|
end
|
42
59
|
end
|
data/lib/psql-cm/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: psql-cm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pg
|
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
version: 1.3.6
|
69
69
|
requirements: []
|
70
70
|
rubyforge_project:
|
71
|
-
rubygems_version: 1.8.
|
71
|
+
rubygems_version: 1.8.23
|
72
72
|
signing_key:
|
73
73
|
specification_version: 3
|
74
74
|
summary: PostgreSQL CM
|