postmodern 0.1.0 → 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/README.md +1 -0
- data/lib/postmodern/dummy.rb +1 -0
- data/lib/postmodern/vacuum/vacuum.rb +10 -1
- data/lib/postmodern/version.rb +1 -1
- data/spec/features/dummy_spec.rb +1 -0
- data/spec/features/freeze_spec.rb +1 -0
- data/spec/features/vacuum_spec.rb +1 -0
- data/spec/postmodern/vacuum/vacuum_spec.rb +26 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11654286ebdd50bde8e215c458a2a9faad3d5deb
|
4
|
+
data.tar.gz: afe4ed43d2137580448b21a480fa10193a64071e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31e5d5befd568bf174b76c644ffbef320a433f9ad287e68f47cf68e608af17f681d1533ac25b340a50d0145c6416e8656e80020c429883d210d2b7d6be44ac07
|
7
|
+
data.tar.gz: 0be73e7b01ecd064f19d778b5978976080b3abe358e536ed7a3c163220100d39cbf0fe90e870a439cea19f21a5f2544814b0f3a9eb0cca35fcb9fd8fd0aeb596
|
data/README.md
CHANGED
data/lib/postmodern/dummy.rb
CHANGED
@@ -71,6 +71,10 @@ module Postmodern
|
|
71
71
|
exit
|
72
72
|
end
|
73
73
|
|
74
|
+
opts.on_tail("-n", "--dry-run", "Perform dry-run, do not vacuum.") do
|
75
|
+
self.options[:dryrun] = true
|
76
|
+
end
|
77
|
+
|
74
78
|
opts.on_tail("--version", "Show version") do
|
75
79
|
require 'postmodern/version'
|
76
80
|
puts Postmodern::VERSION
|
@@ -99,12 +103,13 @@ module Postmodern
|
|
99
103
|
def vacuum
|
100
104
|
tables_to_vacuum.each do |table|
|
101
105
|
Postmodern.logger.info "Vacuuming #{table}"
|
102
|
-
adapter.execute(vacuum_statement(table))
|
106
|
+
adapter.execute(vacuum_statement(table)) unless dryrun?
|
103
107
|
if timedout?
|
104
108
|
Postmodern.logger.warn "Vacuuming timed out"
|
105
109
|
break
|
106
110
|
end
|
107
111
|
end
|
112
|
+
Postmodern.logger.info "Vacuuming finished"
|
108
113
|
end
|
109
114
|
|
110
115
|
def vacuum_statement table_name
|
@@ -115,6 +120,10 @@ module Postmodern
|
|
115
120
|
Time.now >= start_time + (options[:timeout].to_i * 60)
|
116
121
|
end
|
117
122
|
|
123
|
+
def dryrun?
|
124
|
+
!!options[:dryrun]
|
125
|
+
end
|
126
|
+
|
118
127
|
def tables_to_vacuum
|
119
128
|
table_res = adapter.execute(table_sql)
|
120
129
|
table_res.map{|f| f['full_table_name']}
|
data/lib/postmodern/version.rb
CHANGED
data/spec/features/dummy_spec.rb
CHANGED
@@ -141,6 +141,14 @@ ORDER BY dead_pct DESC, table_bytes DESC;
|
|
141
141
|
|
142
142
|
let(:tables_to_vacuum) { %w(table1 table2 table3) }
|
143
143
|
|
144
|
+
context 'dry run' do
|
145
|
+
let(:args) { %w(-d db --dry-run) }
|
146
|
+
it 'does not actually execute vacuum' do
|
147
|
+
command.vacuum
|
148
|
+
expect(adapter).not_to have_received(:execute)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
144
152
|
it "vacuums each table" do
|
145
153
|
command.vacuum
|
146
154
|
tables_to_vacuum.each do |table|
|
@@ -157,6 +165,24 @@ ORDER BY dead_pct DESC, table_bytes DESC;
|
|
157
165
|
end
|
158
166
|
end
|
159
167
|
|
168
|
+
describe '#dryrun?' do
|
169
|
+
context 'with --dry-run' do
|
170
|
+
let(:args) { %w(-d db --dry-run) }
|
171
|
+
|
172
|
+
it 'is true' do
|
173
|
+
expect(subject.dryrun?).to be true
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'without --dry-run' do
|
178
|
+
let(:args) { %w(-d db) }
|
179
|
+
|
180
|
+
it 'is false' do
|
181
|
+
expect(command.dryrun?).to be false
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
160
186
|
describe '#timedout?' do
|
161
187
|
let(:time) { Time.now }
|
162
188
|
let(:args) { %w(--d db -t 15) }
|