pgdexter 0.3.7 → 0.3.8

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
  SHA256:
3
- metadata.gz: a4245b0c02667e411a915ef4c19ef472925048180d5882bc7b63b90037cb9d45
4
- data.tar.gz: '0887ae99de87c186c1bfc52edbdbb59546df61de93bfbccd0974dff5c15b80f0'
3
+ metadata.gz: 3940bf892014f2337cc5cd95c85b66f245b3725ad7ce84397c4eb4f9e3751c3c
4
+ data.tar.gz: b8fc834cda0161c8ef0b44853c14f5f608c00f373e6a95481321e45611d2d5b4
5
5
  SHA512:
6
- metadata.gz: 45ec7b462d925c2e5aa313734d1109b59e65e743c28e3471ef604d430037949675c615ab9004b98f8b055b0a575cdc169470d89e64694ef39cdd2bee60674548
7
- data.tar.gz: 8d33afbd03ba250ae7dd4dfe6c1947e8860fece0925b58a098fb7a54f6f8fe76aaa3bc93f663b10282ef1a9b3bb2c059ac26014f9a3cff3798ece22dbb8d62be
6
+ metadata.gz: 463430e69b2a1f08ca411db0a4938c7243839e78f81db72455d508ff1e9de1a752889bff8a3e42486cf4859042065b0847f0b6c0216c80c9b9a36a10cf360753
7
+ data.tar.gz: d31949fc719e863aa56672fd807141dfbeb521d2ce2525ca551109e09840115c3091e7130cc47617a6b836ff31853dbf12a1bb9fb4dea492b17cbf7c9bfd5c8e
@@ -1,3 +1,8 @@
1
+ ## 0.3.8 (2020-08-17)
2
+
3
+ - Colorize output
4
+ - Fixed error when unable to parse view definitions
5
+
1
6
  ## 0.3.7 (2020-07-10)
2
7
 
3
8
  - Fixed help output
data/README.md CHANGED
@@ -146,10 +146,10 @@ dexter --interval 60 # seconds
146
146
 
147
147
  ## Examples
148
148
 
149
- Ubuntu with PostgreSQL 9.6
149
+ Ubuntu with PostgreSQL 12
150
150
 
151
151
  ```sh
152
- tail -F -n +1 /var/log/postgresql/postgresql-9.6-main.log | sudo -u postgres dexter dbname
152
+ tail -F -n +1 /var/log/postgresql/postgresql-12-main.log | sudo -u postgres dexter dbname
153
153
  ```
154
154
 
155
155
  Homebrew on Mac
@@ -1,13 +1,14 @@
1
1
  module Dexter
2
2
  class Client
3
+ extend Logging
3
4
  include Logging
4
5
 
5
6
  attr_reader :arguments, :options
6
7
 
7
8
  def self.start
8
9
  Dexter::Client.new(ARGV).perform
9
- rescue Dexter::Abort => e
10
- abort e.message
10
+ rescue Dexter::Abort, PG::UndefinedFile => e
11
+ abort colorize(e.message.strip, :red)
11
12
  end
12
13
 
13
14
  def initialize(args)
@@ -78,11 +79,11 @@ module Dexter
78
79
 
79
80
  # TODO don't use global var
80
81
  $log_level = options[:log_level].to_s.downcase
81
- abort "Unknown log level" unless ["error", "info", "debug", "debug2", "debug3"].include?($log_level)
82
+ raise Dexter::Abort, "Unknown log level" unless ["error", "info", "debug", "debug2", "debug3"].include?($log_level)
82
83
 
83
84
  [arguments, options]
84
85
  rescue Slop::Error => e
85
- abort e.message
86
+ raise Dexter::Abort, e.message
86
87
  end
87
88
  end
88
89
  end
@@ -16,7 +16,7 @@ module Dexter
16
16
  end
17
17
  end
18
18
  rescue CSV::MalformedCSVError => e
19
- abort "ERROR: #{e.message}"
19
+ raise Dexter::Abort, "ERROR: #{e.message}"
20
20
  end
21
21
  end
22
22
  end
@@ -123,9 +123,9 @@ module Dexter
123
123
  begin
124
124
  execute("CREATE EXTENSION IF NOT EXISTS hypopg")
125
125
  rescue PG::UndefinedFile
126
- abort "Install HypoPG first: https://github.com/ankane/dexter#installation"
126
+ raise Dexter::Abort, "Install HypoPG first: https://github.com/ankane/dexter#installation"
127
127
  rescue PG::InsufficientPrivilege
128
- abort "Use a superuser to run: CREATE EXTENSION hypopg"
128
+ raise Dexter::Abort, "Use a superuser to run: CREATE EXTENSION hypopg"
129
129
  end
130
130
  end
131
131
 
@@ -421,7 +421,7 @@ module Dexter
421
421
  # print summary
422
422
  if new_indexes.any?
423
423
  new_indexes.each do |index|
424
- log "Index found: #{index[:table]} (#{index[:columns].join(", ")})"
424
+ log colorize("Index found: #{index[:table]} (#{index[:columns].join(", ")})", :green)
425
425
  end
426
426
  else
427
427
  log "No new indexes found"
@@ -515,7 +515,7 @@ module Dexter
515
515
  PG::Connection.new(config)
516
516
  end
517
517
  rescue PG::ConnectionBad => e
518
- abort e.message
518
+ raise Dexter::Abort, e.message
519
519
  end
520
520
 
521
521
  def execute(query, pretty: true)
@@ -527,7 +527,7 @@ module Dexter
527
527
  # as an extra defense against SQL-injection attacks.
528
528
  # https://www.postgresql.org/docs/current/static/libpq-exec.html
529
529
  query = squish(query) if pretty
530
- log "SQL: #{query}" if @log_sql
530
+ log colorize("[sql] #{query}", :cyan) if @log_sql
531
531
 
532
532
  @mutex.synchronize do
533
533
  conn.exec_params(query, []).to_a
@@ -596,7 +596,13 @@ module Dexter
596
596
 
597
597
  view_tables = {}
598
598
  result.each do |row|
599
- view_tables[row["table_name"]] = PgQuery.parse(row["definition"]).tables
599
+ begin
600
+ view_tables[row["table_name"]] = PgQuery.parse(row["definition"]).tables
601
+ rescue PgQuery::ParseError
602
+ if @log_level.start_with?("debug")
603
+ log colorize("ERROR: Cannot parse view definition: #{row["table_name"]}", :red)
604
+ end
605
+ end
600
606
  end
601
607
 
602
608
  view_tables
@@ -1,11 +1,26 @@
1
1
  module Dexter
2
2
  module Logging
3
+ COLOR_CODES = {
4
+ red: 31,
5
+ green: 32,
6
+ yellow: 33,
7
+ cyan: 36
8
+ }
9
+
10
+ def output
11
+ $stdout
12
+ end
13
+
3
14
  def log(message = "")
4
- puts message unless $log_level == "error"
15
+ output.puts(message) unless $log_level == "error"
5
16
  end
6
17
 
7
- def abort(message)
8
- raise Dexter::Abort, message
18
+ def colorize(message, color)
19
+ if output.tty?
20
+ "\e[#{COLOR_CODES[color]}m#{message}\e[0m"
21
+ else
22
+ message
23
+ end
9
24
  end
10
25
  end
11
26
  end
@@ -37,7 +37,7 @@ module Dexter
37
37
  begin
38
38
  process_queries
39
39
  rescue PG::ServerError => e
40
- log "ERROR: #{e.class.name}: #{e.message}"
40
+ log colorize("ERROR: #{e.class.name}: #{e.message}", :red)
41
41
  end
42
42
  sleep(@interval)
43
43
  end
@@ -47,7 +47,7 @@ module Dexter
47
47
  begin
48
48
  @log_parser.perform
49
49
  rescue Errno::ENOENT => e
50
- abort "ERROR: #{e.message}"
50
+ raise Dexter::Abort, "ERROR: #{e.message}"
51
51
  end
52
52
 
53
53
  process_queries
@@ -1,3 +1,3 @@
1
1
  module Dexter
2
- VERSION = "0.3.7"
2
+ VERSION = "0.3.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgdexter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-10 00:00:00.000000000 Z
11
+ date: 2020-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slop