debloater 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33b62165f1a67989f3ba01274484d44adf38ec35
4
- data.tar.gz: 841d4684a2f920552621faf5a17bdc043756e30a
3
+ metadata.gz: d071b8c2e619cc724f84453444f600241088c6ac
4
+ data.tar.gz: 54f8a1a4b93b2ec4dee3ea3730c2874ff030e9d8
5
5
  SHA512:
6
- metadata.gz: 0cc3f9c0af2e80101fe7fb8aeb3571ac707f11332adbbcd91f0669a6da21c8f777f2364ad7465193a5782cfcef529a4869f3319aa78446c95e7d5a2eb781f917
7
- data.tar.gz: 3c6745026be290c0df30697fcc0c957fdbc616d285b92ac4d49837122e70a48718b2e1f32fca266daae0e233bf9a4971320b531f62c045b32e79b1fd7ac185fd
6
+ metadata.gz: 9de264341cffe510b287d4013448ba5fecf2b9cba86519aa05a224f14bf95c1757908102f5dee8f8c07f088833c1bf0b826be9917795d9be7db5bee56d33bcd2
7
+ data.tar.gz: 4b4e430e2d7978ce58ce627d83cbed6572a2546780a2320bdb55c4a3c2210102d4654b46a34403b735d533c5e7f4800929399154e0daea8bd38e663c5aecfcc3
@@ -56,21 +56,31 @@ module Debloater
56
56
 
57
57
 
58
58
  def debloat!
59
+ _log "Old index definition:"
60
+ _log @sql
61
+
59
62
  [
60
- "DROP INDEX IF EXISTS idx_debloat_new",
63
+ 'DROP INDEX IF EXISTS idx_debloat_new',
61
64
  @sql.
62
65
  sub(/CONCURRENTLY/i, '').
63
- sub(/CREATE (UNIQUE)? INDEX/i, 'CREATE \1 INDEX CONCURRENTLY').
66
+ sub(/CREATE\s+(UNIQUE\s+)?INDEX/i, 'CREATE \1INDEX CONCURRENTLY').
64
67
  sub(@name, 'idx_debloat_new'),
65
- 'BEGIN',
66
- "ALTER INDEX #{@name} RENAME TO idx_debloat_old",
67
- "ALTER INDEX idx_debloat_new RENAME TO #{@name}",
68
- 'DROP INDEX idx_debloat_old',
69
- 'COMMIT',
68
+ %{
69
+ BEGIN;
70
+ ALTER INDEX #{@name} RENAME TO idx_debloat_old;
71
+ ALTER INDEX idx_debloat_new RENAME TO #{@name};
72
+ DROP INDEX idx_debloat_old;
73
+ COMMIT;
74
+ },
70
75
  ].each do |sql|
71
- _log "\t#{sql}"
72
76
  begin
77
+ _log "\t#{sql}"
73
78
  @conn.exec sql
79
+ rescue PG::TRDeadlockDetected => e
80
+ _log "Deadlock encountered. Press enter to retry, ^C to abort."
81
+ IO.console.gets
82
+ @conn.exec 'ROLLBACK;'
83
+ retry
74
84
  rescue PG::DependentObjectsStillExist => e
75
85
  _log "Could not debloat '#{@name}', skipping. Details:"
76
86
  _log e.message
@@ -1,3 +1,3 @@
1
1
  module Debloater
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debloater
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Letessier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-21 00:00:00.000000000 Z
11
+ date: 2017-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler