lib/dexter/indexer.rb in pgdexter-0.3.7 vs lib/dexter/indexer.rb in pgdexter-0.3.8
- old
+ new
@@ -121,13 +121,13 @@
def create_extension
execute("SET client_min_messages = warning")
begin
execute("CREATE EXTENSION IF NOT EXISTS hypopg")
rescue PG::UndefinedFile
- abort "Install HypoPG first: https://github.com/ankane/dexter#installation"
+ raise Dexter::Abort, "Install HypoPG first: https://github.com/ankane/dexter#installation"
rescue PG::InsufficientPrivilege
- abort "Use a superuser to run: CREATE EXTENSION hypopg"
+ raise Dexter::Abort, "Use a superuser to run: CREATE EXTENSION hypopg"
end
end
def extension_exists?
execute("SELECT * FROM pg_available_extensions WHERE name = 'hypopg' AND installed_version IS NOT NULL").any?
@@ -419,11 +419,11 @@
def show_and_create_indexes(new_indexes, queries)
# print summary
if new_indexes.any?
new_indexes.each do |index|
- log "Index found: #{index[:table]} (#{index[:columns].join(", ")})"
+ log colorize("Index found: #{index[:table]} (#{index[:columns].join(", ")})", :green)
end
else
log "No new indexes found"
end
@@ -513,11 +513,11 @@
config = config[:dbname] if config.keys == [:dbname] && config[:dbname].include?("=")
end
PG::Connection.new(config)
end
rescue PG::ConnectionBad => e
- abort e.message
+ raise Dexter::Abort, e.message
end
def execute(query, pretty: true)
# use exec_params instead of exec for security
#
@@ -525,11 +525,11 @@
# (There can be semicolons in it, but not more than one nonempty command.)
# This is a limitation of the underlying protocol, but has some usefulness
# as an extra defense against SQL-injection attacks.
# https://www.postgresql.org/docs/current/static/libpq-exec.html
query = squish(query) if pretty
- log "SQL: #{query}" if @log_sql
+ log colorize("[sql] #{query}", :cyan) if @log_sql
@mutex.synchronize do
conn.exec_params(query, []).to_a
end
end
@@ -594,10 +594,16 @@
schemaname NOT IN ('information_schema', 'pg_catalog')
SQL
view_tables = {}
result.each do |row|
- view_tables[row["table_name"]] = PgQuery.parse(row["definition"]).tables
+ begin
+ view_tables[row["table_name"]] = PgQuery.parse(row["definition"]).tables
+ rescue PgQuery::ParseError
+ if @log_level.start_with?("debug")
+ log colorize("ERROR: Cannot parse view definition: #{row["table_name"]}", :red)
+ end
+ end
end
view_tables
end